You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/config-files.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,9 +90,9 @@ Example:
90
90
### Routes
91
91
92
92
The routes section is an unordered collection of route matches and their associated configuration. A route requires at least the following fields:
93
-
- RouteId - a unique name
94
-
- ClusterId - refers to the name of an entry in the clusters section.
95
-
- Match - contains either a Hosts array or a Path pattern string. Path is an ASP.NET Core route template that can be defined as [explained here](/aspnet/core/fundamentals/routing#route-templates).
93
+
* RouteId - a unique name
94
+
* ClusterId - refers to the name of an entry in the clusters section.
95
+
* Match - contains either a Hosts array or a Path pattern string. Path is an ASP.NET Core route template that can be defined as [explained here](/aspnet/core/fundamentals/routing#route-templates).
96
96
Route matching is based on the most specific routes having highest precedence as described [here](/aspnet/core/fundamentals/routing#url-matching). Explicit ordering can be achieved using the `order` field, with lower values taking higher priority.
97
97
98
98
[Headers](xref:fundamentals/servers/yarp/header-routing), [Authorization](xref:fundamentals/servers/yarp/authn-authz), [CORS](xref:fundamentals/servers/yarp/cors), and other route based policies can be configured on each route entry. For additional fields see [RouteConfig](xref:Yarp.ReverseProxy.Configuration.RouteConfig).
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/config-filters.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,11 @@ ai-usage: ai-assisted
16
16
YARP configuration for routes, clusters, and destinations can be loaded from [configuration files](xref:fundamentals/servers/yarp/config-files) or from [configuration providers](xref:fundamentals/servers/yarp/config-providers). Configuration filters can be used to modify that raw input before it's validated and applied.
17
17
18
18
Filters can be used for a variety of purposes such as:
19
-
- Supplementing config fields with data from other sources like the deployment environment
20
-
- Applying system defaults
21
-
- Applying common settings and enforce policies
22
-
- Substituting placeholder values
23
-
- Normalization and error correction
19
+
* Supplementing config fields with data from other sources like the deployment environment
20
+
* Applying system defaults
21
+
* Applying common settings and enforce policies
22
+
* Substituting placeholder values
23
+
* Normalization and error correction
24
24
25
25
## AddConfigFilter
26
26
Configuration filters are registered in the Dependency Injection system using the [AddConfigFilter](xref:Microsoft.Extensions.DependencyInjection.ReverseProxyServiceCollectionExtensions) API. Any number of unique filters can be added and will be applied in the order added.
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/config-providers.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,9 @@ Configuration can be modified during the load sequence using [Configuration Filt
24
24
25
25
### Routes
26
26
The routes section is an unordered collection of named routes. A route contains matches and their associated configuration. A route requires at least the following fields:
27
-
- RouteId - a unique name
28
-
- ClusterId - refers to the name of an entry in the clusters section.
29
-
- Match - contains either a Hosts array or a Path pattern string. Path is an ASP.NET Core route template that can be defined as [explained here](/aspnet/core/fundamentals/routing#route-templates).
27
+
* RouteId - a unique name
28
+
* ClusterId - refers to the name of an entry in the clusters section.
29
+
* Match - contains either a Hosts array or a Path pattern string. Path is an ASP.NET Core route template that can be defined as [explained here](/aspnet/core/fundamentals/routing#route-templates).
30
30
31
31
[Headers](xref:fundamentals/servers/yarp/header-routing), [Authorization](xref:fundamentals/servers/yarp/authn-authz), [CORS](xref:fundamentals/servers/yarp/cors), and other route based policies can be configured on each route entry. For additional fields see [RouteConfig](xref:Yarp.ReverseProxy.Configuration.RouteConfig).
The `IProxyConfigProvider` should be registered in the DI container as a singleton. At startup, the proxy will resolve this instance and call `GetConfig()`. On this first call the provider may choose to:
58
-
- Throw an exception if the provider cannot produce a valid proxy configuration for any reason. This will prevent the application from starting.
59
-
- Synchronously block while it loads the configuration. This will block the application from starting until valid route data is available.
60
-
- Or, it may choose to return an empty `IProxyConfig` instance while it loads the configuration in the background. The provider will need to trigger the `IChangeToken` when the configuration is available.
58
+
* Throw an exception if the provider cannot produce a valid proxy configuration for any reason. This will prevent the application from starting.
59
+
* Synchronously block while it loads the configuration. This will block the application from starting until valid route data is available.
60
+
* Or, it may choose to return an empty `IProxyConfig` instance while it loads the configuration in the background. The provider will need to trigger the `IChangeToken` when the configuration is available.
61
61
62
62
The proxy will validate the given configuration and if it's invalid, an exception will be thrown that prevents the application from starting. The provider can avoid this by using the [IConfigValidator](xref:Yarp.ReverseProxy.Configuration.IConfigValidator) to pre-validate routes and clusters and take whatever action it deems appropriate such as excluding invalid entries.
63
63
@@ -68,15 +68,15 @@ The configuration objects and collections supplied to the proxy should be read-o
68
68
If the `IChangeToken` supports `ActiveChangeCallbacks`, once the proxy has processed the initial set of configurations it will register a callback with this token. If the provider does not support callbacks then `HasChanged` will be polled every 5 minutes.
69
69
70
70
When the provider wants to provide a new configuration to the proxy it should:
71
-
- Load that configuration in the background.
71
+
* Load that configuration in the background.
72
72
- Route and cluster objects are immutable, so new instances have to be created for any new data.
73
73
- Objects for unchanged routes and clusters can be re-used, or new instances can be created - changes will be detected by diffing them.
74
-
- Optionally validate the configuration using the [IConfigValidator](xref:Yarp.ReverseProxy.Configuration.IConfigValidator), and only then signal the `IChangeToken` from the prior `IProxyConfig` instance that new data is available. The proxy will call `GetConfig()` again to retrieve the new data.
74
+
* Optionally validate the configuration using the [IConfigValidator](xref:Yarp.ReverseProxy.Configuration.IConfigValidator), and only then signal the `IChangeToken` from the prior `IProxyConfig` instance that new data is available. The proxy will call `GetConfig()` again to retrieve the new data.
75
75
76
76
There are important differences when reloading configuration vs the first configuration load.
77
-
- The new configuration will be diffed against the current one and only modified routes or clusters will be updated. The update will be applied atomically and will only affect new requests, not requests currently in progress.
78
-
- Any errors in the reload process will be logged and suppressed. The application will continue using the last known good configuration.
79
-
- If `GetConfig()` throws the proxy will be unable to listen for future changes because `IChangeToken`s are single-use.
77
+
* The new configuration will be diffed against the current one and only modified routes or clusters will be updated. The update will be applied atomically and will only affect new requests, not requests currently in progress.
78
+
* Any errors in the reload process will be logged and suppressed. The application will continue using the last known good configuration.
79
+
* If `GetConfig()` throws the proxy will be unable to listen for future changes because `IChangeToken`s are single-use.
80
80
81
81
Once the new configuration has been validated and applied, the proxy will register a callback with the new `IChangeToken`. Note if there are multiple reloads signaled in close succession, the proxy may skip some and load the next available configuration as soon as it's ready. Each `IProxyConfig` contains the full configuration state so nothing will be lost.
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/destination-resolvers.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,9 +26,9 @@ YARP uses a destination resolver to expand the set of configured destination add
26
26
27
27
### Startup
28
28
The `IDestinationResolver` should be registered in the DI container as a singleton. At startup, the proxy will resolve this instance and call `ResolveDestinationsAsync(...)` with the configured destinations retrieved from the resolved `IProxyConfigProviders`. On this first call the provider may choose to:
29
-
- Throw an exception if the provider cannot produce a valid proxy configuration for any reason. This will prevent the application from starting.
30
-
- Asynchronously resolve the destinations. This will stop the application from starting until resolved destinations are available.
31
-
- Or, it may choose to return an empty `ResolvedDestinationCollection` instance while it resolves destinations in the background. The provider will need to trigger the `IChangeToken` when the configuration is available.
29
+
* Throw an exception if the provider cannot produce a valid proxy configuration for any reason. This will prevent the application from starting.
30
+
* Asynchronously resolve the destinations. This will stop the application from starting until resolved destinations are available.
31
+
* Or, it may choose to return an empty `ResolvedDestinationCollection` instance while it resolves destinations in the background. The provider will need to trigger the `IChangeToken` when the configuration is available.
32
32
33
33
### Atomicity
34
34
The destinations objects and collections supplied to the proxy should be read-only and not modified once they have been handed to the proxy via `GetConfig()`.
@@ -37,10 +37,10 @@ The destinations objects and collections supplied to the proxy should be read-on
37
37
If the `IChangeToken` supports `ActiveChangeCallbacks`, once the proxy has processed the initial set of destinations it will register a callback with this token. If the provider does not support callbacks then `HasChanged` will be polled alongside `IProxyConfig` change tokens, every 5 minutes.
38
38
39
39
When the provider wants to provide a new set of destinations to the proxy it should:
40
-
- Resolve those destinations in the background.
40
+
* Resolve those destinations in the background.
41
41
-`ResolvedDestinationCollection` is immutable, so new instances have to be created for any new data.
42
42
- Objects for unchanged destinations can be re-used, or new instances can be created.
43
-
- Invalidate the `IChangeToken` returned from the previous `ResolveDestinationsAsync` invocation.
43
+
* Invalidate the `IChangeToken` returned from the previous `ResolveDestinationsAsync` invocation.
44
44
45
45
Once the new destinations have been applied, the proxy will register a callback with the new `IChangeToken`. Note if there are multiple reloads signaled in close succession, the proxy may skip some and resolve destinations as soon as it's ready.
*`Policy`: Name of a policy evaluating destinations' active health states. Mandatory parameter
91
+
*`Path`: Health check path on all cluster's destinations. Default `null`.
92
+
*`Query`: Health check query on all cluster's destinations. Default `null`.
93
93
94
94
`Destination` section and [DestinationConfig](xref:Yarp.ReverseProxy.Configuration.DestinationConfig).
95
95
96
-
-`Health` - A dedicated health probing endpoint such as `http://destination:12345/`. Defaults `null` and falls back to `Destination/Address`.
96
+
*`Health` - A dedicated health probing endpoint such as `http://destination:12345/`. Defaults `null` and falls back to `Destination/Address`.
97
97
98
98
### Built-in policies
99
99
There is currently one built-in active health check policy - `ConsecutiveFailuresHealthPolicy`. It counts consecutive health probe failures and marks a destination as unhealthy once the given threshold is reached. On the first successful response, a destination is marked as healthy and the counter is reset.
`Cluster/HealthCheck/Passive` section and [PassiveHealthCheckConfig](xref:Yarp.ReverseProxy.Configuration.PassiveHealthCheckConfig):
266
266
267
-
-`Enabled` - flag indicating whether passive health check is enabled for a cluster. Default `false`
268
-
-`Policy` - name of a policy evaluating destinations' passive health states. Mandatory parameter
269
-
-`ReactivationPeriod` - period after which an unhealthy destination's passive health state is reset to `Unknown` and it starts receiving traffic again. Default value is `null` which means the period will be set by a `IPassiveHealthCheckPolicy`
267
+
*`Enabled` - flag indicating whether passive health check is enabled for a cluster. Default `false`
268
+
*`Policy` - name of a policy evaluating destinations' passive health states. Mandatory parameter
269
+
*`ReactivationPeriod` - period after which an unhealthy destination's passive health state is reset to `Unknown` and it starts receiving traffic again. Default value is `null` which means the period will be set by a `IPassiveHealthCheckPolicy`
270
270
271
271
### Built-in policies
272
272
There is currently one built-in passive health check policy - [`TransportFailureRateHealthPolicy`](xref:Yarp.ReverseProxy.Health.TransportFailureRateHealthPolicyOptions). It calculates the proxied requests failure rate for each destination and marks it as unhealthy if the specified limit is exceeded. Rate is calculated as a percentage of failed requests to the total number of request proxied to a destination in the given period of time. Failed and total counters are tracked in a sliding time window which means that only the recent readings fitting in the window are taken into account.
273
273
There are two sets of policy parameters defined globally and on per cluster level.
274
274
275
275
Global parameters are set via the options mechanism using `TransportFailureRateHealthPolicyOptions` type with the following properties:
276
276
277
-
-`DetectionWindowSize` - period of time while detected failures are kept and taken into account in the rate calculation. Default is `00:01:00`.
278
-
-`MinimalTotalCountThreshold` - minimal total number of requests which must be proxied to a destination within the detection window before this policy starts evaluating the destination's health and enforcing the failure rate limit. Default is `10`.
279
-
-`DefaultFailureRateLimit` - default failure rate limit for a destination to be marked as unhealthy that is applied if it's not set on a cluster's metadata. The value is in range `(0,1)`. Default is `0.3` (30%).
277
+
*`DetectionWindowSize` - period of time while detected failures are kept and taken into account in the rate calculation. Default is `00:01:00`.
278
+
*`MinimalTotalCountThreshold` - minimal total number of requests which must be proxied to a destination within the detection window before this policy starts evaluating the destination's health and enforcing the failure rate limit. Default is `10`.
279
+
*`DefaultFailureRateLimit` - default failure rate limit for a destination to be marked as unhealthy that is applied if it's not set on a cluster's metadata. The value is in range `(0,1)`. Default is `0.3` (30%).
280
280
281
281
Global policy options can be set in code as follows:
282
282
```csharp
@@ -346,10 +346,10 @@ public class FirstUnsuccessfulResponseHealthPolicy : IPassiveHealthCheckPolicy
346
346
## Available destination collection
347
347
Destinations health state is used to determine which of them are eligible for receiving proxied requests. Each cluster maintains its own list of available destinations on `AvailableDestinations` property of the [ClusterDestinationState](xref:Yarp.ReverseProxy.Model.ClusterDestinationsState) type. That list gets rebuilt when any destination's health state changes. The [IClusterDestinationsUpdater](xref:Yarp.ReverseProxy.Health.IClusterDestinationsUpdater) controls that process and calls an [IAvailableDestinationsPolicy](xref:Yarp.ReverseProxy.Health.IAvailableDestinationsPolicy) configured on the cluster to actually choose the available destinations from the all cluster's destinations. There are the following built-in policies provided and custom ones can be implemented if necessary.
348
348
349
-
-`HealthyAndUnknown` - Inspects each `DestinationState` and adds it on the available destination list if all of the following statements are TRUE. If no destinations are available then requests will get a 503 error.
349
+
*`HealthyAndUnknown` - Inspects each `DestinationState` and adds it on the available destination list if all of the following statements are TRUE. If no destinations are available then requests will get a 503 error.
350
350
- Active health checks are disabled on the cluster OR `DestinationHealthState.Active != DestinationHealth.Unhealthy`
351
351
- Passive health checks are disabled on the cluster OR `DestinationHealthState.Passive != DestinationHealth.Unhealthy`
352
-
-`HealthyOrPanic` - Calls `HealthyAndUnknown` policy at first to get the available destinations. If none of them are returned from this call, it marks all cluster's destinations as available. This is the default policy.
352
+
*`HealthyOrPanic` - Calls `HealthyAndUnknown` policy at first to get the available destinations. If none of them are returned from this call, it marks all cluster's destinations as available. This is the default policy.
353
353
354
354
**NOTE**: An available destination policy configured on a cluster will be always called regardless of if any health check is enabled on the given cluster. The health state of a disabled health check is set to `Unknown`.
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/direct-forwarding.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,17 +19,17 @@ Some applications only need the ability to take a specific request and forward i
19
19
[IHttpForwarder](xref:Yarp.ReverseProxy.Forwarder.IHttpForwarder) serves as the core proxy adapter between incoming AspNetCore and outgoing System.Net.Http requests. It handles the mechanics of creating a HttpRequestMessage from a HttpContext, sending it, and relaying the response.
20
20
21
21
IHttpForwarder supports:
22
-
- Dynamic destination selection, you specify the destination for each request
23
-
- Http client customization, you provide the HttpMessageInvoker
24
-
- Request and response customization (except bodies)
25
-
- Streaming protocols like gRPC and WebSockets
26
-
- Error handling
22
+
* Dynamic destination selection, you specify the destination for each request
23
+
* Http client customization, you provide the HttpMessageInvoker
24
+
* Request and response customization (except bodies)
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/servers/yarp/distributed-tracing.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,8 @@ As an ASP.NET Core component, YARP can easily integrate into different tracing s
21
21
YARP supports distributed tracing using Open Telemetry (OTEL). When a request comes in, and there is a listener for Activities, then ASP.NET Core will propagate the [Trace Context](https://www.w3.org/TR/trace-context) trace-id, or create one if necessary, and create new spans/activities for the work performed.
22
22
In addition YARP can create activities for:
23
23
24
-
- Forwarding Requests
25
-
- Active health checks for clusters
24
+
* Forwarding Requests
25
+
* Active health checks for clusters
26
26
27
27
These will only be created if there is a listener for the [`ActivitySource`](/dotnet/core/diagnostics/distributed-tracing-instrumentation-walkthroughs#activitysource) named `Yarp.ReverseProxy`.
0 commit comments