Skip to content

API that allows to remove all resilience handlers from the HTTP client #5801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 21, 2025

Conversation

rainsxng
Copy link
Contributor

@rainsxng rainsxng commented Jan 17, 2025

Background and motivation

.NET provides the ConfigureHttpClientDefaults method that allows you to configure the default behavior of the HttpClient. With the help of this method you can register the StandardResiliencePipeline as part of the default configuration of the HttpClient:

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());

This is convenient, since you don't need to configure the resilience pipeline for each HttpClient. But with the API we currently provide users face a few issues/challenges when they need to change the default configuration. This change focuses on the following issue:

Removing the existing default resilience pipeline and adding a custom one

For example, a user registers the StandardResilienceHandler as default configuration, but at the same time he/she wants to use the StandardHedgingHandler for a particular named HttpClient:

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());

// For a named HttpClient "custom" we want to remove the StandardResilienceHandler and add instead the StandardHedgingHandler.
services.AddHttpClient("custom")./*Remove StandardResilienceHandler*/.AddStandardHedgingHandler();

API description

This API provides functionality to remove all assigned handlers from the HttpClient.

API Usage

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());
// For a named HttpClient "custom" we want to remove the StandardResilienceHandler and add instead the StandardHedgingHandler.
services.AddHttpClient("custom")
    .RemoveAllResilienceHandlers()
    .AddStandardHedgingHandler();

This PR partially resolves #5695

Microsoft Reviewers: Open in CodeFlow

@rainsxng rainsxng added area-resilience api-approved API was approved in API review, it can be implemented labels Jan 17, 2025
@rainsxng rainsxng self-assigned this Jan 17, 2025
@rainsxng rainsxng requested a review from a team as a code owner January 17, 2025 15:12
@rainsxng rainsxng marked this pull request as draft January 17, 2025 15:13
@dotnet-comment-bot
Copy link
Collaborator

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI 88 89
Microsoft.Extensions.AI.OpenAI 77 78

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=923055&view=codecoverage-tab

@rainsxng rainsxng marked this pull request as ready for review January 20, 2025 16:30
@dotnet-comment-bot
Copy link
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Caching.Hybrid Line 86 77.82 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.OpenAI 77 78
Microsoft.Extensions.AI 88 89

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=923176&view=codecoverage-tab

Copy link
Contributor

@iliar-turdushev iliar-turdushev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rainsxng The PR looks good. Thank you for the contribution.

@dotnet-comment-bot
Copy link
Collaborator

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.OpenAI 77 78
Microsoft.Extensions.AI 88 89

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=923862&view=codecoverage-tab

@rainsxng rainsxng changed the title API that allows to remove all assigned handlers from the HTTP client API that allows to remove all resilience handlers from the HTTP client Jan 21, 2025
@dotnet-comment-bot
Copy link
Collaborator

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI 88 89
Microsoft.Extensions.AI.OpenAI 77 78

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=923985&view=codecoverage-tab

@dotnet-comment-bot
Copy link
Collaborator

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.AI.OpenAI 77 78
Microsoft.Extensions.AI 88 89

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=924034&view=codecoverage-tab

@rainsxng rainsxng merged commit d586dc4 into main Jan 21, 2025
6 checks passed
@rainsxng rainsxng deleted the dbohdanov/resilience_handler_api branch January 21, 2025 15:58
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-resilience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal, Microsoft.Extensions.Http.Resilience]: API for removing and replacing the standard resilience/hedging handlers
4 participants