Skip to content

Commit 31975da

Browse files
Quick pass at some YARP improvements (#35119)
* Quick pass at some YARP improvements * Update aspnetcore/fundamentals/servers/yarp/dests-health-checks.md --------- Co-authored-by: Rick Anderson <[email protected]>
1 parent f10530a commit 31975da

File tree

11 files changed

+31
-26
lines changed

11 files changed

+31
-26
lines changed

aspnetcore/fundamentals/servers/yarp/config-providers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ The configuration objects and collections supplied to the proxy should be read-o
6868
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.
6969

7070
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.
7272
- Route and cluster objects are immutable, so new instances have to be created for any new data.
7373
- 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.
7575

7676
There are important differences when reloading configuration vs the first configuration load.
7777
- 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.

aspnetcore/fundamentals/servers/yarp/dests-health-checks.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ Active health check settings can also be defined in code via the corresponding t
8484

8585
`Cluster/HealthCheck/Active` section and [ActiveHealthCheckConfig](xref:Yarp.ReverseProxy.Configuration.ActiveHealthCheckConfig):
8686

87-
- `Enabled` - flag indicating whether active health check is enabled for a cluster. Default `false`
88-
- `Interval` - period of sending health probing requests. Default `00:00:15`
89-
- `Timeout` - probing request timeout. Default `00:00:10`
90-
- `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`.
87+
- `Enabled`: Flag indicating whether active health check is enabled for a cluster. Default `false`
88+
- `Interval`: Period of sending health probing requests. Default `00:00:15`
89+
- `Timeout`: Probing request timeout. Default `00:00:10`
90+
- `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`.
9393

9494
`Destination` section and [DestinationConfig](xref:Yarp.ReverseProxy.Configuration.DestinationConfig).
9595

@@ -346,10 +346,10 @@ public class FirstUnsuccessfulResponseHealthPolicy : IPassiveHealthCheckPolicy
346346
## Available destination collection
347347
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.
348348

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.
350350
- Active health checks are disabled on the cluster OR `DestinationHealthState.Active != DestinationHealth.Unhealthy`
351351
- 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.
353353

354354
**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`.
355355

aspnetcore/fundamentals/servers/yarp/diagnosing-yarp-issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,5 @@ It can be attractive to use network tracing tools like [Fiddler](https://www.tel
247247
- Fiddler registers itself as a proxy and relies on applications using the default proxy to be able to monitor traffic. This works for inbound traffic from a browser to YARP, but will not capture the outbound requests as YARP is configured to not use the proxy settings for outbound traffic.
248248
- On windows Wireshark uses Npcap to capture packet data for network traffic, so it will capture both inbound and outbound traffic, and can be used to monitor HTTP traffic. Wireshark works out of the box for HTTP traffic.
249249
- HTTPS traffic is encrypted, and so is not automatically decryptable by network monitoring tools. Each tool has workarounds that may enable traffic to be monitored, but they require hacking around with certificates and trust relationships. Because YARP is making outbound requests, techniques for tricking browsers do not apply to the YARP process.
250-
250+
251251
The protocol choice for outbound traffic is made based on the destination URL in the cluster configuration. If traffic monitoring is being used for diagnostics then, if possible, changing the outbound URLs to "http://" may be simplest approach to enable the monitoring tools to work, provided the issues being diagnosed are not transport protocol related.

aspnetcore/fundamentals/servers/yarp/grpc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ai-usage: ai-assisted
2020

2121
gRPC requires HTTP/2 for most scenarios. HTTP/1.1 and HTTP/2 are enabled by default on ASP.NET Core servers (YARP's front end) but they require https (TLS) for HTTP/2 so YARP needs to be listening on a `https://` URL.
2222

23-
HTTP/2 over http (non-TLS) is only supported on Kestrel and requires specific settings. For details see [here](/aspnet/core/grpc/aspnetcore#server-options).
23+
HTTP/2 over http (non-TLS) is only supported on Kestrel and requires specific settings. For details see [here](/aspnet/core/grpc/aspnetcore#server-options).
2424

2525
This shows configuring Kestrel to use HTTP/2 over http (non-TLS):
2626
```json

aspnetcore/fundamentals/servers/yarp/http-client-config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ These types are focused on defining serializable configuration. The code based c
2626
### HttpClient
2727
HTTP client configuration is based on [HttpClientConfig](xref:Yarp.ReverseProxy.Configuration.HttpClientConfig) and represented by the following configuration schema. If you need a more granular approach, use a <!--check link--> [custom implementation](xref:fundamentals/servers/yarp/http-client-config#custom-iforwarderhttpclientfactory) of `IForwarderHttpClientFactory`.
2828

29-
<!-- original linke [custom implementation](https://microsoft.github.io/reverse-proxy/articles/http-client-config.html#custom-iforwarderhttpclientfactory) -->
29+
<!-- original linke [custom implementation](https://microsoft.github.io/reverse-proxy/articles/http-client-config.html#custom-iforwarderhttpclientfactory) -->
3030
```JSON
3131
"HttpClient": {
3232
"SslProtocols": [ "<protocol-names>" ],

aspnetcore/fundamentals/servers/yarp/load-balancing.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,27 @@ var clusters = new[]
7272
## Built-in policies
7373

7474
YARP ships with the following built-in policies:
75+
7576
- `FirstAlphabetical`
7677

77-
Select the alphabetically first available destination without considering load. This is useful for dual destination fail-over systems.
78+
Select the alphabetically first available destination without considering load. This is useful for dual destination fail-over systems.
79+
7880
- `Random`
7981

80-
Select a destination randomly.
82+
Select a destination randomly.
83+
8184
- `PowerOfTwoChoices` (default)
8285

83-
Select two random destinations and then select the one with the least assigned requests.
84-
This avoids the overhead of `LeastRequests` and the worst case for `Random` where it selects a busy destination.
86+
Select two random destinations and then select the one with the least assigned requests.
87+
This avoids the overhead of `LeastRequests` and the worst case for `Random` where it selects a busy destination.
88+
8589
- `RoundRobin`
8690

87-
Select a destination by cycling through them in order.
91+
Select a destination by cycling through them in order.
92+
8893
- `LeastRequests`
8994

90-
Select the destination with the least assigned requests. This requires examining all destinations.
95+
Select the destination with the least assigned requests. This requires examining all destinations.
9196

9297
## Extensibility
9398

aspnetcore/fundamentals/servers/yarp/middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Middleware like session affinity and load balancing examine the `IReverseProxyFe
112112

113113
`AvailableDestinations` lists the destinations currently considered eligible to handle the request. It is initialized to `AllDestinations`, excluding unhealthy ones if health checks are enabled. `AvailableDestinations` should be reduced to a single destination by the end of the pipeline or else one will be selected randomly from the remainder.
114114

115-
`ProxiedDestination` is set by the proxy logic at the end of the pipeline to indicate which destination was ultimately used. If there are no available destinations remaining then a 503 error response is sent.
115+
`ProxiedDestination` is set by the proxy logic at the end of the pipeline to indicate which destination was ultimately used. If there are no available destinations remaining then a 503 error response is sent.
116116

117117
```C#
118118
proxyPipeline.Use(async (context, next) =>

aspnetcore/fundamentals/servers/yarp/session-affinity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The `Cookie` and `CustomHeader` policies encrypt the key using Data Protection.
118118
## Affinity failure policy
119119
If the affinity key cannot be decoded or no healthy destination found it's considered as a failure and an affinity failure policy is called to handle it. The policy has the full access to `HttpContext` and can send response to the client by itself. It returns a boolean value indicating whether the request processing can proceed down the pipeline or must be terminated.
120120

121-
There are two built-in failure policies. The default is `Redistribute`.
121+
There are two built-in failure policies. The default is `Redistribute`.
122122
1. `Redistribute` - tries to establish a new affinity to one of available healthy destinations by skipping the affinity lookup step and passing all healthy destination to the load balancer the same way it is done for a request without any affinity. Request processing continues. This is implemented by `RedistributeAffinityFailurePolicy`.
123123

124124
2. `Return503Error` - sends a `503` response back to the client and request processing is terminated. This is implemented by `Return503ErrorAffinityFailurePolicy`

aspnetcore/fundamentals/servers/yarp/transforms-response.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
uid: fundamentals/servers/yarp/transforms-response
33
title: YARP Response and Response Trailer Transforms
4-
description: YARP Response and Response Trailer Transforms
4+
description: YARP Response and Response Trailer Transforms
55
author: samsp-msft
66
ms.author: samsp
77
ms.date: 2/6/2025

aspnetcore/fundamentals/servers/yarp/transforms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ X-Forwarded-Host: IncomingHost:5000
4545

4646
## Transform Categories
4747

48-
Transforms fall into a few categories: [Request](./transforms-request.md), [Response](./transforms-response.md), and [Response Trailers](./transforms-response.md#responsetrailer). Request trailers are not supported because they are not supported by the underlying HttpClient.
48+
Transforms fall into a few categories: [Request](./transforms-request.md), [Response](./transforms-response.md), and [Response Trailers](./transforms-response.md#responsetrailer). Request trailers are not supported because they are not supported by the underlying HttpClient.
4949

5050
If the built-in set of transforms is insufficient, then custom transforms can be added via [extensibility](./extensibility-transforms.md).
5151

0 commit comments

Comments
 (0)