-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add example for chaos engineering #1956
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1956 +/- ##
=======================================
Coverage 85.91% 85.91%
=======================================
Files 312 312
Lines 6654 6654
Branches 1057 1057
=======================================
Hits 5717 5717
Misses 540 540
Partials 397 397
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
samples/Chaos/Program.cs
Outdated
var builder = WebApplication.CreateBuilder(args); | ||
var services = builder.Services; | ||
services.TryAddSingleton<IChaosManager, ChaosManager>(); | ||
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just use the AddHttpContextAccessor()
method?
samples/Chaos/README.md
Outdated
# Chaos Example | ||
|
||
This example demonstrates how to use new [chaos engineering](https://www.pollydocs.org/chaos) tools in Polly to inject chaos into HTTP client communication. | ||
The HTTP client communicates with `https://jsonplaceholder.typicode.com/todos` endpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HTTP client communicates with `https://jsonplaceholder.typicode.com/todos` endpoint. | |
The HTTP client communicates with the `https://jsonplaceholder.typicode.com/todos` endpoint. |
samples/Chaos/README.md
Outdated
|
||
To test the application: | ||
|
||
- Run the app using `dotnet run` command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Run the app using `dotnet run` command. | |
- Run the app using the `dotnet run` command. |
samples/Chaos/TodosClient.cs
Outdated
public async Task<IEnumerable<TodoModel>?> GetTodosAsync(CancellationToken cancellationToken) | ||
{ | ||
using var request = new HttpRequestMessage(HttpMethod.Get, "/todos"); | ||
using var response = await client.SendAsync(request, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simplify this down to just use GetFromJsonAsync<T>()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to include handling of invalid status codes which is not possible with that method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that method implicitly called EnsureStatusCode()
for you, so it's basically the same? I meant the one that's an overload of HttpClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my understanding it does not do status code checking. (it would prevent deserializing error bodies for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, if that's the case I've been using it wrong a lot then. I assumed it checked the status code, as otherwise you'd get a weird result if you tried to deserialise the response as a model for an OK and instead the body was an ErrorDetails or an HTML error page or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be weird to do a get knowing in advance you were just going to get an error details because it would fail. Not checking the status would make more sense if it was a discriminated union.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it checks the status code as well. Simplified.
Pull Request
The issue or feature being addressed
Contributes to #1954
Details on the issue fix or feature implementation
An example of how to use chaos strategies alongside the resilience. This sample will be referenced in the upcoming blog post about chaos engineering with Polly.
Confirm the following