[API Proposal]: Resilience extensions - Introduce a Total timeout -> Retry -> Timeout resilience pipeline
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 894
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 23
Description
### Background and motivation
### Motivation
The current resilience logic in Standard Resilience Pipeline is _Rate limiter -> Total Timeout -> Retry -> CB -> Timeout_. However, we do observe that in many real services, the more common and wanted logic is a _Total Timeout -> Retry -> Timeout_ pipeline, as they may not want circuit breaker either because there is not that much huge traffic, or because they don't want to block the single endpoint from CB which will leading to nowhere to go. Similar other reasons to rate limiter policy.
Now, there is no property in `HttpStandardResilienceOptions` to allow users to disable certain policies. For circuit breaker, a possible workaround is to override its `ShouldHandle` to always return `false`, but this will still leading to non-necessary resource wasting in runtime since the policy is still there consuming calculation resource. For rate limiter, I don't find a good way to disable it.
So, we propose to add a `StreamlinedStandardResiliencePipeline`, with resilience logic similar to Standard Resilience Pipeline, but remove the rate limiter and circuit breaker policy. (_Total Timeout -> Retry -> Attempt Timeout_)
### API Proposal
```csharp
public static IStreamlinedStandardResiliencePipelineBuilder AddStreamlinedStandardResilienceHandler(this IHttpClientBuilder builder)
```
```csharp
public static IStreamlinedStandardResiliencePipelineBuilder Configure(this IStreamlinedStandardResiliencePipelineBuilder builder, Action configuration)
```
```csharp
public class StreamlinedStandardResiliencePipelineOptions
{
internal static class StandardPipelineNames
{
public const string Retry = "StreamlinedStandard-Retry";
public const string TotalRequestTimeout = "StreamlinedStandard-TotalRequestTimeout";
public const string AttemptTimeout = "StreamlinedStandard-AttemptTimeout";
}
[Required]
[ValidateObjectMembers]
public HttpTimeoutStrategyOptions TotalRequestTimeout { get; set; } = new HttpTimeoutStrategyOptions
{
Name = StandardPipelineNames.TotalRequestTimeout
};
[Required]
[ValidateObjectMembers]
public HttpRetryStrategyOptions Retry { get; set; } = new HttpRetryStrategyOptions
{
Name = StandardPipelineNames.Retry
};
[Required]
[ValidateObjectMembers]
public HttpTimeoutStrategyOptions AttemptTimeout { get; set; } = new()
{
Name = StandardPipelineNames.AttemptTimeout
};
}
```
### API Usage
```csharp
services.AddHttpClient("test-client")
.AddStreamlinedStandardResilienceHandler()
.Configure(options =>
{
options.TotalTimeout =...
});
```
### Alternative Designs
If there is good way to enable/disable rate limiter and circuit breaker in standard resilience pipeline, that will also be acceptable.
### Risks
Don't see risks regarding introduce a new resilience pipeline.
Contributor guide
Assessment
This issue has not been assessed yet.