8000 #2078 V7 polly syntax not longer supported by RaynaldM · Pull Request #2079 · ThreeMammals/Ocelot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#2078 V7 polly syntax not longer supported #2079

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 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions docs/features/qualityofservice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,12 @@ You can set the **TimeoutValue** in isolation of the **ExceptionsAllowedBeforeBr

There is no point setting the other two in isolation as they affect each other!

Defaults
--------
Notes
-----

If you do not add a QoS section, QoS will not be used, however Ocelot will default to a **90** seconds timeout on all downstream requests.
If someone needs this to be configurable, open an issue. [#f2]_
1. If you do not add a QoS section, QoS will not be used, however Ocelot will default to a **90** seconds timeout on all downstream requests. If someone needs this to be configurable, open an issue. [#f2]_

.. _qos-polly-v7-vs-v8:

`Polly`_ v7 vs v8
-----------------

Important changes in version `23.2`_: [#f3]_

- With `Polly`_ version 8+, the ``ExceptionsAllowedBeforeBreaking`` value must be equal to or greater than **2**!
Comment on lines -57 to -59
Copy link
Member

Choose a reason for hiding this comment

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

I believe these lines can be retained and relocated to an earlier position.

- The ``AddPolly`` method has been migrated from v7 policy wrappers to v8 resilience pipelines. Consequently, it now exhibits different behavior based on v8 pipelines.

If you prefer not to modify your settings, you can continue using `Polly`_ v7 as follows:

.. code-block:: csharp

services.AddOcelot()
.AddPollyV7();

**Note**: Support for `Polly`_ v7 will be removed in a future version. We recommend avoiding this method (which is tagged as ``Obsolete``) unless absolutely necessary.
2. `Polly`_ V7 syntax no longer supported. In version `23.2`_ [#f3]_ with `Polly`_ version 8+, the ``ExceptionsAllowedBeforeBreaking`` value must be equal to or greater than **2**!

.. _qos-extensibility:

Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Polly" Version="8.3.1" />
<PackageReference Include="Polly" Version="8.4.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Right! Good to bump the version!

</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0" />
Expand Down
97 changes: 2 additions & 95 deletions src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Ocelot.Errors.QoS;
using Ocelot.Logging;
using Ocelot.Provider.Polly.Interfaces;
using Ocelot.Provider.Polly.v7;
using Ocelot.Requester;
using Polly.CircuitBreaker;
using Polly.Registry;
Expand All @@ -32,7 +31,7 @@ public static class OcelotBuilderExtensions
/// <summary>
/// Adds Polly QoS provider to Ocelot by custom delegate and with custom error mapping.
/// </summary>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSProvider"/>).</typeparam>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSResiliencePipelineProvider"/>).</typeparam>
/// <param name="builder">Ocelot builder to extend.</param>
/// <param name="delegatingHandler">Your customized delegating handler (to manage QoS behavior by yourself).</param>
/// <param name="errorMapping">Your customized error mapping.</param>
Expand Down Expand Up @@ -94,7 +93,7 @@ public static IOcelotBuilder AddPolly<TProvider>(this IOcelotBuilder builder)
/// Defaults:
/// <list type="bullet">
/// <item><see cref="PollyQoSResiliencePipelineProvider"/></item>
/// <item><see cref="GetDelegatingHandlerV7"/></item>
/// <item><see cref="GetDelegatingHandler"/></item>
/// <item><see cref="DefaultErrorMapping"/></item>
/// </list>
/// </remarks>
Expand All @@ -112,96 +111,4 @@ public static IOcelotBuilder AddPolly(this IOcelotBuilder builder)
/// <returns>A <see cref="DelegatingHandler"/> object, but concrete type is the <see cref="PollyResiliencePipelineDelegatingHandler"/> class.</returns>
private static DelegatingHandler GetDelegatingHandler(DownstreamRoute route, IHttpContextAccessor contextAccessor, IOcelotLoggerFactory loggerFactory)
=> new PollyResiliencePipelineDelegatingHandler(route, contextAccessor, loggerFactory);

#region Obsolete extensions will be removed in future version
Copy link
Member

Choose a reason for hiding this comment

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

I love when regions are removed 😃


/// <summary>
/// Adds Polly QoS provider to Ocelot by custom delegate and with custom error mapping.
/// </summary>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSProvider"/>).</typeparam>
/// <param name="builder">Ocelot builder to extend.</param>
/// <param name="delegatingHandler">Your customized delegating handler (to manage QoS behavior by yourself).</param>
/// <param name="errorMapping">Your customized error mapping.</param>
/// <returns>The reference to the same extended <see cref="IOcelotBuilder"/> object.</returns>
[Obsolete("Use AddPolly instead, it will be remove in future version")]
public static IOcelotBuilder AddPollyV7<TProvider>(this IOcelotBuilder builder, QosDelegatingHandlerDelegate delegatingHandler, IDictionary<Type, Func<Exception, Error>> errorMapping)
where TProvider : class, IPollyQoSProvider<HttpResponseMessage>
{
builder.Services
.AddSingleton(errorMapping)
.AddSingleton<IPollyQoSProvider<HttpResponseMessage>, TProvider>()
.AddSingleton(delegatingHandler);
return builder;
}

/// <summary>
/// Adds Polly QoS provider to Ocelot with custom error mapping, but default <see cref="DelegatingHandler"/> is used.
/// </summary>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSProvider"/>).</typeparam>
/// <param name="builder">Ocelot builder to extend.</param>
/// <param name="errorMapping">Your customized error mapping.</param>
/// <returns>The reference to the same extended <see cref="IOcelotBuilder"/> object.</returns>
[Obsolete("Use AddPolly instead, it will be remove in future version")]
public static IOcelotBuilder AddPollyV7<TProvider>(this IOcelotBuilder builder, IDictionary<Type, Func<Exception, Error>> errorMapping)
where TProvider : class, IPollyQoSProvider<HttpResponseMessage>
=> AddPollyV7<TProvider>(builder, GetDelegatingHandlerV7, errorMapping);

/// <summary>
/// Adds Polly QoS provider to Ocelot with custom <see cref="DelegatingHandler"/> delegate, but default error mapping is used.
/// </summary>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSProvider"/>).</typeparam>
/// <param name="builder">Ocelot builder to extend.</param>
/// <param name="delegatingHandler">Your customized delegating handler (to manage QoS behavior by yourself).</param>
/// <returns>The reference to the same extended <see cref="IOcelotBuilder"/> object.</returns>
[Obsolete("Use AddPolly instead, it will be remove in future version")]
public static IOcelotBuilder AddPollyV7<TProvider>(this IOcelotBuilder builder, QosDelegatingHandlerDelegate delegatingHandler)
where TProvider : class, IPollyQoSProvider<HttpResponseMessage>
=> AddPollyV7<TProvider>(builder, delegatingHandler, DefaultErrorMapping);

/// <summary>
/// Adds Polly QoS provider to Ocelot by defaults.
/// </summary>
/// <remarks>
/// Defaults:
/// <list type="bullet">
/// <item><see cref="GetDelegatingHandlerV7"/></item>
/// <item><see cref="DefaultErrorMapping"/></item>
/// </list>
/// </remarks>
/// <typeparam name="TProvider">QoS provider to use (by default use <see cref="PollyQoSProvider"/>).</typeparam>
/// <param name="builder">Ocelot builder to extend.</param>
/// <returns>The reference to the same extended <see cref="IOcelotBuilder"/> object.</returns>
[Obsolete("Use AddPolly instead, it will be remove in future version")]
public static IOcelotBuilder AddPollyV7<TProvider>(this IOcelotBuilder builder)
where TProvider : class, IPollyQoSProvider<HttpResponseMessage>
=> AddPollyV7<TProvider>(builder, GetDelegatingHandlerV7, DefaultErrorMapping);

/// <summary>
/// Adds Polly QoS provider to Ocelot by defaults with default QoS provider.
/// </summary>
/// <remarks>
/// Defaults:
/// <list type="bullet">
/// <item><see cref="PollyQoSProvider"/></item>
/// <item><see cref="GetDelegatingHandlerV7"/></item>
/// <item><see cref="DefaultErrorMapping"/></item>
/// </list>
/// </remarks>
/// <param name="builder">Ocelot builder to extend.</param>
/// <returns>The reference to the same extended <see cref="IOcelotBuilder"/> object.</returns>
[Obsolete("Use AddPolly instead, it will be remove in future version")]
public static IOcelotBuilder AddPollyV7(this IOcelotBuilder builder)
=> AddPollyV7<PollyQoSProvider>(builder, GetDelegatingHandlerV7, DefaultErrorMapping);

/// <summary>< 9E88 /td>
/// Creates default delegating handler based on the <see cref="PollyPoliciesDelegatingHandler"/> type.
/// </summary>
/// <param name="route">The downstream route to apply the handler for.</param>
/// <param name="contextAccessor">The context accessor of the route.</param>
/// <param name="loggerFactory">The factory of logger.</param>
/// <returns>A <see cref="DelegatingHandler"/> object, but concrete type is the <see cref="PollyPoliciesDelegatingHandler"/> class.</returns>
private static DelegatingHandler GetDelegatingHandlerV7(DownstreamRoute route, IHttpContextAccessor contextAccessor, IOcelotLoggerFactory loggerFactory)
=> new PollyPoliciesDelegatingHandler(route, contextAccessor, loggerFactory);

#endregion
}
6 changes: 2 additions & 4 deletions src/Ocelot.Provider.Polly/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Default Microsoft.NET.Sdk namespaces
// Project extra global namespaces
global using Polly;
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;

// Project extra global namespaces
global using Polly;
10 changes: 0 additions & 10 deletions src/Ocelot.Provider.Polly/v7/IPollyQoSProvider.cs

This file was deleted.

120 changes: 0 additions & 120 deletions src/Ocelot.Provider.Polly/v7/OcelotBuilderExtensions.cs 89E0

This file was deleted.

54 changes: 0 additions & 54 deletions src/Ocelot.Provider.Polly/v7/PollyPoliciesDelegatingHandler.cs

This file was deleted.

Loading
0