Skip to content
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

#1875 Use Polly v8 syntax #1914

Merged
merged 59 commits into from Mar 15, 2024
Merged

#1875 Use Polly v8 syntax #1914

merged 59 commits into from Mar 15, 2024

Conversation

RaynaldM
Copy link
Collaborator

@RaynaldM RaynaldM commented Jan 9, 2024

Closes #1875

Proposed Changes

Use Polly 8's specific syntax to define resiliencePipelines (vs. PollyPolicies)

"Polly v8 introduces the concept of resilience pipelines, a powerful tool that blends one or more resilience strategies. This new API foundation echoes the Policy Wrap of previous versions but is now integrated seamlessly into the core API. All strategies start with a pipeline."

in v7, we written

// Create and use the IAsyncPolicy
IAsyncPolicy asyncPolicy = Policy
    .Handle<Exception>()
    .WaitAndRetryAsync(3, _ => TimeSpan.FromSeconds(1));

in v8, it becomes

// Use the ResiliencePipelineBuilder to start building the resilience pipeline
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        ShouldHandle = new PredicateBuilder().Handle<Exception>(),
        Delay = TimeSpan.FromSeconds(1),
        MaxRetryAttempts = 3,
        BackoffType = DelayBackoffType.Constant
    })
    .Build(); // After all necessary strategies are added, call Build() to create the pipeline.

Ray and others added 9 commits December 7, 2023 15:02
created tests for  PollyResiliencePipelineDelegatingHandler
created tests for PollyQoSResiliencePipelineProvider
…ensions` and `PollyQoSResiliencePipelineProvider` classes, as well as modifications to the `PollyQoSTests` class.

In the `OcelotBuilderExtensions` class, the `GetDelegatingHandler` method is now used instead of `GetDelegatingHandlerV7` in the `AddPolly` methods. The `AddPolly` method without parameters has been simplified using a lambda expression. The `GetDelegatingHandler` method now returns a new instance of `PollyResiliencePipelineDelegatingHandler` instead of `PollyPoliciesDelegatingHandler`.

In the `PollyQoSResiliencePipelineProvider` class, a comment has been added suggesting the use of `ResiliencePipelineRegistry<TKey>.GetOrAddPipeline` due to its thread-safe nature. The `MinimumThroughput` property in `circuitBreakerStrategyOptions` now uses the value from `route.QosOptions.ExceptionsAllowedBeforeBreaking`.

In the `PollyQoSTests` class, the `QoSOptions` used in the test configurations have been updated. Two tests, `Should_open_circuit_breaker_then_close` and `Open_circuit_should_not_effect_different_route`, have been modified to repeat the same request as the minimum `ExceptionsAllowedBeforeBreaking` is now 2. The `GivenThereIsAPossiblyBrokenServiceRunningOn` method now delays for 2.1 seconds when the request count is 2, to ensure the circuit is open.

Changes:

1. `OcelotBuilderExtensions` class updated to use `GetDelegatingHandler` method.
2. `AddPolly` methods in `OcelotBuilderExtensions` class simplified.
3. `GetDelegatingHandler` method in `OcelotBuilderExtensions` class now returns a new instance of `PollyResiliencePipelineDelegatingHandler`.
4. Comment added in `PollyQoSResiliencePipelineProvider` class suggesting the use of `ResiliencePipelineRegistry<TKey>.GetOrAddPipeline`.
5. `MinimumThroughput` property in `circuitBreakerStrategyOptions` updated to use value from `route.QosOptions.ExceptionsAllowedBeforeBreaking`.
6. `QoSOptions` in `PollyQoSTests` class updated.
7. `Should_open_circuit_breaker_then_close` and `Open_circuit_should_not_effect_different_route` tests in `PollyQoSTests` class updated.
8. `GivenThereIsAPossiblyBrokenServiceRunningOn` method in `PollyQoSTests` class updated to delay for 2.1 seconds when request count is 2.
@RaynaldM RaynaldM linked an issue Jan 9, 2024 that may be closed by this pull request
@raman-m raman-m changed the title 1875 use polly v8 syntax #1875 Use Polly v8 syntax Jan 9, 2024
@raman-m
Copy link
Member

raman-m commented Jan 9, 2024

This branch is 9 commits ahead of, 3 commits behind develop.

@raman-m raman-m added feature A new feature Jan'24 January 2024 release labels Jan 10, 2024
@raman-m raman-m added this to the January'24 milestone Jan 10, 2024
@raman-m
Copy link
Member

raman-m commented Jan 10, 2024

Ray, build 3064 has failed!
Commit 8375908 looks like a bad merge 😉 Please fix the build!

RaynaldM and others added 4 commits January 10, 2024 15:27
…er`. This new implementation replaces the previous dictionary-based approach for managing cache for resilience pipelines.
Use `ResiliencePipelineRegistry` in `PollyQoSResiliencePipelineProvider`
@raman-m
Copy link
Member

raman-m commented Jan 15, 2024

I love when Raynald develops features! 😍

@RaynaldM RaynaldM requested a review from raman-m January 16, 2024 09:46
@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

@RaynaldM I'm very sorry... But we have merge conflicts ❗ Please resolve them, and I'll review.

@raman-m raman-m self-requested a review March 8, 2024 15:10
Update docs according to the Polly v8 implementations and QoS design upgrade
@raman-m
Copy link
Member

raman-m commented Mar 8, 2024

@ggnaegi Please review and approve! I believe the PR is ready for delivery.
I've got necessary explanations by Ray, and I have a good clarity now.
Seems, nothing to improve.

@ggnaegi
Copy link
Member

ggnaegi commented Mar 8, 2024

@ggnaegi Please review and approve! I believe the PR is ready for delivery.
I've got necessary explanations by Ray, and I have a good clarity now.
Seems, nothing to improve.

@raman-m Ok, but it's going to be late, around 11 your time.

Copy link
Member

@ggnaegi ggnaegi left a comment

Choose a reason for hiding this comment

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

some minor changes, thanks!

@raman-m
Copy link
Member

raman-m commented Mar 9, 2024

What I'm worrying now is increased duration of running unit tests by ~30s !
Locally it takes 27 seconds to run new 20 unit tests:
image
So, our CircleCI builds will take not 12m but 12m 30s ❗ Last build took 12m 45s!
Seems nothing to do with that. But in future we could move all package tests to separate testing project and release the package independently from Ocelot.nupkg

But acceptance tests cannot be moved unfortunately, and they will stay in the current testing project.

@ggnaegi
Copy link
Member

ggnaegi commented Mar 9, 2024

@raman-m commented on Mar 9:

Seems nothing to do with that. But in future we could move all package tests to separate testing project and release the package independently from Ocelot.nupkg

Yes you're right!

@ggnaegi
Copy link
Member

ggnaegi commented Mar 9, 2024

@raman-m commented on Mar 6

I don't know, probably some design issues since I agree with you about the HttpContextAccessor. Probably the way the object is instantiated.

@raman-m
Copy link
Member

raman-m commented Mar 11, 2024

@ggnaegi commented on Mar 9

The problem is that your design of the delegate was reused in the new delegate class by Raynald.
So, seems it is a little bit late to fix design issue doing some refactoring. But we can skip it for now, and let's keep in mind that this design issue can be fixed in future PR...

@ggnaegi
Copy link
Member

ggnaegi commented Mar 11, 2024

@ggnaegi commented on Mar 9

The problem is that your design of the delegate was reused in the new delegate class by Raynald.
So, seems it is a little bit late to fix design issue doing some refactoring. But we can skip it for now, and let's keep in mind that this design issue can be fixed in future PR...

@raman-m yes but I think it's quite deeply rooted in the Ocelot's design somewhere. You know, the kind of of classes that are not injected with DI.

@raman-m
Copy link
Member

raman-m commented Mar 12, 2024

@ggnaegi commented on Mar 9

Great! We have the consensus! So, at least after the release I will create a TODO task to start brainstorming how to separate Polly Provider package to a separate Visual Studio solution with its own testing project. Possibly we could brainstorm how to adjust release process also.

TODO

  • Move Ocelot.Provider.Polly package to a separate solution

@ggnaegi
Copy link
Member

ggnaegi commented Mar 12, 2024

@ggnaegi commented on Mar 9

Great! We have the consensus! So, at least after the release I will create a TODO task to start brainstorming how to separate Polly Provider package to a separate Visual Studio solution with its own testing project. Possibly we could brainstorm how to adjust release process also.

TODO

  • Move Ocelot.Provider.Polly package to a separate solution

@raman-m, I don't think that's the problem. The problem is more related with the fact that the QoS classes don't know the polly provider, since it's provided in a project that is not referenced in ocelot base. That's why I finally used this ugly hack.

@raman-m
Copy link
Member

raman-m commented Mar 12, 2024

@ggnaegi Cherry pick 0ca4b18 once again?

@raman-m
Copy link
Member

raman-m commented Mar 13, 2024

@ggnaegi I expect your fixing code review issues and approving finally till Friday to allow Raynald to merge the PR on Friday, March 15. 🆗 ❔

@raman-m
Copy link
Member

raman-m commented Mar 14, 2024

@RaynaldM Ready for delivery! ✅

  • Code review ✔️✔️
  • Team approvals ✔️
  • Unit testing ✔️
  • Acceptance tests ❔ updated
  • Updated docs ✔️

@RaynaldM RaynaldM merged commit d6eefc8 into develop Mar 15, 2024
2 checks passed
@raman-m raman-m deleted the 1875-use-polly-v8-syntax branch March 15, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature Feb'24 February 2024 release highest Highest priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Polly v8 syntax
3 participants