Skip to content

Commit

Permalink
Merge pull request #1641 from Cratis/feature/configureable-polly
Browse files Browse the repository at this point in the history
Deal with annoying polly logging
  • Loading branch information
woksin authored Jan 10, 2025
2 parents 7229cc3 + d5a66fb commit bbdfa5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/Kernel/Setup/ResilientStorageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel.DataAnnotations;
using Polly.Retry;
using Polly.Telemetry;
using Polly.Timeout;
namespace Cratis.Chronicle.Setup;

Expand All @@ -22,4 +23,14 @@ public class ResilientStorageOptions
/// </summary>
[Required]
public TimeoutStrategyOptions Timeout { get; set; } = new();

/// <summary>
/// Gets or sets the value indicating whether to enable Polly recording telemetry for each "OnRetry" event.
/// </summary>
#pragma warning disable MA0016
public Dictionary<string, ResilienceEventSeverity> ResilienceEventSeverities { get; set; } = new(StringComparer.InvariantCulture)
#pragma warning restore MA0016
{
{ "OnRetry", ResilienceEventSeverity.Debug }
};
}
15 changes: 15 additions & 0 deletions Source/Kernel/Setup/StorageProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Orleans.Storage;
using Polly;
using Polly.Registry;
using Polly.Telemetry;

namespace Orleans.Hosting;

Expand All @@ -33,6 +34,20 @@ public static ISiloBuilder AddStorageProviders(this ISiloBuilder builder)
var options = context.GetOptions<ResilientStorageOptions>();
builder.AddRetry(options.Retry);
builder.AddTimeout(options.Timeout);

var telemetryOptions = new TelemetryOptions(context.GetOptions<TelemetryOptions>())
{
SeverityProvider = ev =>
{
if (options.ResilienceEventSeverities.TryGetValue(ev.Event.EventName, out var severity))
{
return severity;
}

return ev.Event.Severity;
}
};
builder.ConfigureTelemetry(telemetryOptions);
});

builder.ConfigureServices(services =>
Expand Down

0 comments on commit bbdfa5e

Please sign in to comment.