From 97a1c5557c0cd249869b7b2a1fa9a563b12b6eb5 Mon Sep 17 00:00:00 2001 From: martintmk <103487740+martintmk@users.noreply.github.com> Date: Wed, 3 May 2023 10:29:15 +0200 Subject: [PATCH 1/5] ResilienceStrategyRegistry now also uses BuilderName (#1175) --- .../ResilienceStrategyRegistryOptionsTests.cs | 10 ++++-- .../ResilienceStrategyRegistryTests.cs | 35 +++++++++++-------- .../Registry/ResilienceStrategyRegistry.cs | 9 +++-- .../ResilienceStrategyRegistryOptions.cs | 26 ++++++++++++-- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryOptionsTests.cs b/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryOptionsTests.cs index aeec877c49c..61673025b97 100644 --- a/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryOptionsTests.cs +++ b/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryOptionsTests.cs @@ -8,8 +8,12 @@ public void Ctor_EnsureDefaults() { ResilienceStrategyRegistryOptions options = new(); - options.KeyFormatter.Should().NotBeNull(); - options.KeyFormatter(null!).Should().Be(""); - options.KeyFormatter("ABC").Should().Be("ABC"); + options.StrategyKeyFormatter.Should().NotBeNull(); + options.StrategyKeyFormatter(null!).Should().Be(""); + options.StrategyKeyFormatter("ABC").Should().Be("ABC"); + + options.BuilderNameFormatter.Should().NotBeNull(); + options.BuilderNameFormatter(null!).Should().Be(""); + options.BuilderNameFormatter("ABC").Should().Be("ABC"); } } diff --git a/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs b/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs index e8f463ff2b5..1ade2d37721 100644 --- a/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs +++ b/src/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs @@ -7,8 +7,22 @@ namespace Polly.Core.Tests.Registry; public class ResilienceStrategyRegistryTests { + private readonly ResilienceStrategyRegistryOptions _options; + private Action _callback = _ => { }; + public ResilienceStrategyRegistryTests() => _options = new() + { + BuilderFactory = () => + { + var builder = new ResilienceStrategyBuilder(); + _callback(builder); + return builder; + }, + StrategyComparer = StrategyId.Comparer, + BuilderComparer = StrategyId.BuilderComparer + }; + [Fact] public void Ctor_Default_Ok() { @@ -121,18 +135,21 @@ public void AddBuilder_GetStrategy_EnsureCalled() [Fact] public void AddBuilder_EnsureStrategyKey() { + _options.BuilderNameFormatter = k => k.BuilderName; + _options.StrategyKeyFormatter = k => k.InstanceName; + var called = false; var registry = CreateRegistry(); - registry.TryAddBuilder(StrategyId.Create("A"), (key, builder) => + registry.TryAddBuilder(StrategyId.Create("A"), (_, builder) => { builder.AddStrategy(new TestResilienceStrategy()); + builder.BuilderName.Should().Be("A"); builder.Properties.TryGetValue(TelemetryUtil.StrategyKey, out var val).Should().BeTrue(); - val.Should().Be(key.ToString()); + val.Should().Be("Instance1"); called = true; }); registry.Get(StrategyId.Create("A", "Instance1")); - called.Should().BeTrue(); } @@ -175,16 +192,6 @@ public void TryAdd_Twice_SecondNotAdded() private ResilienceStrategyRegistry CreateRegistry() { - return new ResilienceStrategyRegistry(new ResilienceStrategyRegistryOptions - { - BuilderFactory = () => - { - var builder = new ResilienceStrategyBuilder(); - _callback(builder); - return builder; - }, - StrategyComparer = StrategyId.Comparer, - BuilderComparer = StrategyId.BuilderComparer - }); + return new ResilienceStrategyRegistry(_options); } } diff --git a/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs b/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs index 75a52594a5d..c16fc61bbaa 100644 --- a/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs +++ b/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs @@ -21,7 +21,8 @@ public sealed class ResilienceStrategyRegistry : ResilienceStrategyProvide private readonly Func _activator; private readonly ConcurrentDictionary> _builders; private readonly ConcurrentDictionary _strategies; - private readonly Func _keyFormatter; + private readonly Func _strategyKeyFormatter; + private readonly Func _builderNameFormatter; /// /// Initializes a new instance of the class with the default comparer. @@ -44,7 +45,8 @@ public ResilienceStrategyRegistry(ResilienceStrategyRegistryOptions option _activator = options.BuilderFactory; _builders = new ConcurrentDictionary>(options.BuilderComparer); _strategies = new ConcurrentDictionary(options.StrategyComparer); - _keyFormatter = options.KeyFormatter; + _strategyKeyFormatter = options.StrategyKeyFormatter; + _builderNameFormatter = options.BuilderNameFormatter; } /// @@ -89,7 +91,8 @@ public override bool TryGet(TKey key, [NotNullWhen(true)] out ResilienceStrategy strategy = _strategies.GetOrAdd(key, key => { var builder = _activator(); - builder.Properties.Set(TelemetryUtil.StrategyKey, _keyFormatter(key)); + builder.BuilderName = _builderNameFormatter(key); + builder.Properties.Set(TelemetryUtil.StrategyKey, _strategyKeyFormatter(key)); configure(key, builder); return builder.Build(); }); diff --git a/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs b/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs index f4622488df4..05cd3ac68b9 100644 --- a/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs +++ b/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs @@ -36,8 +36,30 @@ public class ResilienceStrategyRegistryOptions public IEqualityComparer BuilderComparer { get; set; } = EqualityComparer.Default; /// - /// Gets or sets the formatter that is used by the registry to format the keys as a string. + /// Gets or sets the formatter that is used by the registry to format the to a string that + /// represents the strategy key. /// + /// + /// By default, the formatter uses the method. + /// + /// Use custom formatter for composite keys in case you want to have different metric values for a builder and strategy key. + /// In general, strategies can have the same builder name and different strategy keys. + /// + /// + [Required] + public Func StrategyKeyFormatter { get; set; } = (key) => key?.ToString() ?? string.Empty; + + /// + /// Gets or sets the formatter that is used by the registry to format the to a string that + /// represents the builder name. + /// + /// + /// By default, the formatter uses the method. + /// + /// Use custom formatter for composite keys in case you want to have different metric values for a builder and strategy key. + /// In general, strategies can have the same builder name and different strategy keys. + /// + /// [Required] - public Func KeyFormatter { get; set; } = (key) => key?.ToString() ?? string.Empty; + public Func BuilderNameFormatter { get; set; } = (key) => key?.ToString() ?? string.Empty; } From 04c0249e207e964a0e88b9627ea98cb2e7300925 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 May 2023 17:30:06 +0000 Subject: [PATCH 2/5] Bump martincostello/update-dotnet-sdk from 2.1.4 to 2.2.0 (#1179) --- .github/workflows/update-dotnet-sdk.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-dotnet-sdk.yml b/.github/workflows/update-dotnet-sdk.yml index 06853e9a084..32ca01b727f 100644 --- a/.github/workflows/update-dotnet-sdk.yml +++ b/.github/workflows/update-dotnet-sdk.yml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - name: Update .NET SDK - uses: martincostello/update-dotnet-sdk@bba9c5d796cf9e84046ae0cb42f7dd33bde568f3 # v2.1.4 + uses: martincostello/update-dotnet-sdk@6cfd047b0c2ce72ea0e22708bc1918a3d912c050 # v2.2.0 with: labels: "dependencies,.NET" repo-token: ${{ secrets.GITHUB_TOKEN }} From ffa8756747616a5d0bc54c7ae6b7a44b970ba5be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 May 2023 17:55:27 +0000 Subject: [PATCH 3/5] Bump ReportGenerator from 5.1.19 to 5.1.20 (#1178) --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 927083f66a6..c848d8e3351 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -12,7 +12,7 @@ - + From 26bd13fd83ef6682e194e8cf1a324def2aa175e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 May 2023 17:34:58 +0000 Subject: [PATCH 4/5] Bump github/codeql-action from 2.3.2 to 2.3.3 (#1180) --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/ossf-scorecard.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0ca9240a480..88a7a5ced07 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -41,14 +41,14 @@ jobs: restore-keys: ${{ runner.os }}-nuget- - name: Initialize CodeQL - uses: github/codeql-action/init@f3feb00acb00f31a6f60280e6ace9ca31d91c76a # v2.3.2 + uses: github/codeql-action/init@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3 with: languages: ${{ matrix.language }} - name: Autobuild - uses: github/codeql-action/autobuild@f3feb00acb00f31a6f60280e6ace9ca31d91c76a # v2.3.2 + uses: github/codeql-action/autobuild@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@f3feb00acb00f31a6f60280e6ace9ca31d91c76a # v2.3.2 + uses: github/codeql-action/analyze@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3 with: category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/ossf-scorecard.yml b/.github/workflows/ossf-scorecard.yml index 819f61d9553..eb6bcdb092c 100644 --- a/.github/workflows/ossf-scorecard.yml +++ b/.github/workflows/ossf-scorecard.yml @@ -39,6 +39,6 @@ jobs: retention-days: 5 - name: Upload to code-scanning - uses: github/codeql-action/upload-sarif@f3feb00acb00f31a6f60280e6ace9ca31d91c76a # v2.3.2 + uses: github/codeql-action/upload-sarif@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3 with: sarif_file: results.sarif From 24da1720cee4bc23eab224a9394490c62c6fb6f6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 May 2023 17:41:32 +0000 Subject: [PATCH 5/5] Bump GitHubActionsTestLogger from 2.0.2 to 2.1.0 (#1181) --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index c848d8e3351..a9fb1bbb195 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -3,7 +3,7 @@ - +