harp_apps.proxy.settings

Inheritance diagram of harp_apps.proxy.settings

class Endpoint[source]

Bases: Stateful[EndpointSettings]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

remote: Remote
class EndpointSettings[source]

Bases: BaseEndpointSettings

Configuration parser for proxy.endpoints[] settings.

name: my-endpoint
port: 8080
description: My endpoint
remote:
  # see HttpRemote
  ...
controller : optional controller Service definition, default to HttpProxyController

A shorthand syntax is also available for cases where you only need to proxy to a single URL and do not require fine-tuning the endpoint settings:

name: my-endpoint
port: 8080
description: My endpoint
url: http://my-endpoint:8080

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

controller: Service | str | None

custom controller

max_request_body_size: ByteSize | None

largest request body this endpoint accepts, instead of proxy.max_request_body_size

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

remote: RemoteSettings | None

remote definition, with url pools, probes, etc.

class Proxy[source]

Bases: Stateful[ProxySettings]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

property endpoints: list[Endpoint][source]
model_config: ClassVar[ConfigDict] = {'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class ProxySettings[source]

Bases: ApplicationSettingsMixin, BaseProxySettings

Configuration parser for proxy settings.

endpoints:
  # see ProxyEndpoint
  - ...

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

client_read_timeout: float

Seconds a client may stay silent in the middle of a request body before it is answered 408, disconnected, and its request is never forwarded upstream. Each silence is timed on its own: a client sending a byte at shorter intervals is not cut (see min_request_body_rate). Does not apply to a response being sent.

endpoints: list[EndpointSettings]
max_recorded_body_size: ByteSize

How much of a request or response body is recorded, at most: a byte count or a size with its unit ("1MiB"). A longer body is still sent whole, recorded truncated and marked truncated-request-body or truncated-response-body; a response is also not stored in the http cache.

max_request_body_size: ByteSize | None

Largest request body accepted, unset (no limit) by default: a byte count or a size with its unit ("10MiB"). A declared Content-Length above it is answered 413 before the body is read, a chunked body is answered 413 as soon as it crosses it, and the request is never forwarded upstream. Each endpoint may set its own.

min_request_body_rate: ByteSize

Bytes per second (or a size with its unit: "1KiB") a request body must average once request_body_grace_period is over. A slower client is answered 408 and disconnected, and its request is never forwarded upstream. 0 disables the check.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

request_body_grace_period: float

Seconds during which a request body is not held to min_request_body_rate.

tags: TagsSettings

Bounds on the tags clients set with x-harp-* request headers.

trusted_proxies: list[IPvAnyNetwork]

CIDR ranges ("10.0.0.0/8", "fd00::/8", or a single address) of the proxies in front of HARP. The X-Forwarded-For, Forwarded and X-Real-IP headers of a peer outside these ranges are stripped, a trusted peer’s are kept. The peer address is appended to X-Forwarded-For and Forwarded in both cases.

class Remote[source]

Bases: Stateful[RemoteSettings]

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

async check()[source]

Uses the probe (luke), to check the health of each urls. It is also done on fallback and inactive urls, to ensure that they are ready in case we need them.

async check_forever()[source]
get_url()[source]

Get next candidate url from the current pool, then rotate.

Return type:

str

model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

Parameters:
  • self (BaseModel)

  • context (Any)

Return type:

None

notify_url_status(url, status)[source]

Take into account a http status code to update the status of the url. Behaviour differs depending on the instance configuration (some considers 5xx as down, some ignores non-network errors).

refresh()[source]

Recompute the current pool of endpoints.

set_checking(url)[source]
set_down(url)[source]
set_up(url)[source]
DEFAULT_LIVENESS: ClassVar[BaseLiveness] = IgnoreLiveness()

Default liveness object to use when the remote is set to inherit the liveness object.

property current_pool: List[str]
current_pool_name: str

Name of the currently used pool. This does not mean that all urls come from this pool, as the fallback pool may be active although some urls from default pool are still available.

property endpoints: List[RemoteEndpoint]
liveness: IgnoreLiveness | InheritLiveness | LeakyBucketLiveness | NaiveLiveness

Liveness

model_config: ClassVar[ConfigDict] = {'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

probe: RemoteProbe | None

Probe reference

class RemoteEndpoint[source]

Bases: Stateful[RemoteEndpointSettings]

Stateful version of a remote endpoint definition.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

failure(reason=None)[source]

Returns a boolean indicating if a state change happened.

Parameters:

reason (str)

success()[source]

Returns a boolean indicating if a state change happened.

Return type:

bool

failure_reasons: set | None
liveness: IgnoreLiveness | InheritLiveness | LeakyBucketLiveness | NaiveLiveness
model_config: ClassVar[ConfigDict] = {'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

status: int
class RemoteEndpointSettings[source]

Bases: Configurable

A HttpEndpoint is an instrumented target URL that a proxy will use to route requests. It is used as the configuration parser for proxy.endpoints[].remote.endpoints[] settings.

url: "http://my-endpoint:8080"
pools: [fallback]  # omit for default pool
failure_threshold: 3
success_threshold: 1

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

classmethod serialize_in_order(value)[source]
Parameters:

value (List[str])

classmethod validate_pools(pools)[source]
Parameters:

pools (List[str])

Return type:

List[str]

liveness: Annotated[IgnoreLivenessSettings | InheritLivenessSettings | LeakyBucketLivenessSettings | NaiveLivenessSettings, Discriminator(discriminator=type, custom_error_type=None, custom_error_message=None, custom_error_context=None)]
model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pools: List[str]
url: HttpUrl
class RemoteProbe[source]

Bases: Stateful[RemoteProbeSettings]

Stateful version of a probe definition.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

async_client()[source]
async check(client, endpoint)[source]
Parameters:
model_config: ClassVar[ConfigDict] = {'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class RemoteProbeSettings[source]

Bases: Configurable

A HttpProbe is a health check that can be used to check the health of a remote’s endpoints. It is used as the configuration parser for proxy.endpoints[].remote.probe settings.

type: http
method: GET
path: /health
headers:
  x-purpose: "health probe"
timeout: 5.0

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

headers: dict[str, Annotated[SecretStr, PlainSerializer(func=_serialize_secret, return_type=str, when_used=always)]]
interval: float
method: str
model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

path: str
timeout: float
verify: bool
class RemoteSettings[source]

Bases: BaseRemoteSettings

A HttpRemote is a collection of endpoints that a proxy will use to route requests. It is used as the configuration parser for proxy.endpoints[].remote settings.

min_pool_size: 1
endpoints:
  # see HttpEndpoint
  - ...
probe:
  # see HttpProbe
  ...

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

endpoints: list[RemoteEndpointSettings]
liveness: Annotated[IgnoreLivenessSettings | InheritLivenessSettings | LeakyBucketLivenessSettings | NaiveLivenessSettings, Discriminator(discriminator=type, custom_error_type=None, custom_error_message=None, custom_error_context=None)]
model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

probe: RemoteProbeSettings | None
class TagsSettings[source]

Bases: Configurable

Bounds on the tags a client sets with x-harp-* request headers. A tag over a bound is dropped, never the request.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

max_count: int

Tags kept per transaction: the first ones in request header order.

max_name_length: int

Longest tag name kept, in characters.

max_value_length: int

Longest tag value kept, in characters.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'hide_input_in_errors': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Submodules