From 2f1ef04f6afc5b81c592a544bf117107f8a6b4c9 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Thu, 25 Aug 2022 11:27:57 +0200 Subject: [PATCH] add retry policy for grpc clients --- .../MareSynchronosServer/Startup.cs | 22 +++++++++++++++++++ .../Discord/DiscordBot.cs | 1 + .../Startup.cs | 19 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/MareSynchronosServer/MareSynchronosServer/Startup.cs b/MareSynchronosServer/MareSynchronosServer/Startup.cs index 3149e8a..9a31b15 100644 --- a/MareSynchronosServer/MareSynchronosServer/Startup.cs +++ b/MareSynchronosServer/MareSynchronosServer/Startup.cs @@ -15,6 +15,7 @@ using AspNetCoreRateLimit; using MareSynchronosShared.Authentication; using MareSynchronosShared.Data; using MareSynchronosShared.Protos; +using Grpc.Net.Client.Configuration; namespace MareSynchronosServer { @@ -46,17 +47,38 @@ namespace MareSynchronosServer var mareConfig = Configuration.GetRequiredSection("MareSynchronos"); + var defaultMethodConfig = new MethodConfig + { + Names = { MethodName.Default }, + RetryPolicy = new RetryPolicy + { + MaxAttempts = 100, + InitialBackoff = TimeSpan.FromSeconds(1), + MaxBackoff = TimeSpan.FromSeconds(5), + BackoffMultiplier = 1.5, + } + }; + services.AddGrpcClient(c => { c.Address = new Uri(mareConfig.GetValue("ServiceAddress")); + }).ConfigureChannel(c => + { + c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } }; }); services.AddGrpcClient(c => { c.Address = new Uri(mareConfig.GetValue("ServiceAddress")); + }).ConfigureChannel(c => + { + c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } }; }); services.AddGrpcClient(c => { c.Address = new Uri(mareConfig.GetValue("StaticFileServiceAddress")); + }).ConfigureChannel(c => + { + c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } }; }); services.AddDbContextPool(options => diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs index 59eaa68..7f27550 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBot.cs @@ -484,6 +484,7 @@ public class DiscordBot : IHostedService vanityUpdateCts = new(); while (!vanityUpdateCts.IsCancellationRequested) { + logger.LogInformation($"Cleaning up Vanity UIDs"); var guild = discordClient.Guilds.FirstOrDefault(); if (guild == null) { diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs index da879ea..44684fe 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Startup.cs @@ -1,3 +1,4 @@ +using Grpc.Net.Client.Configuration; using MareSynchronosShared.Authentication; using MareSynchronosShared.Data; using MareSynchronosShared.Protos; @@ -30,13 +31,31 @@ public class Startup var mareSettings = Configuration.GetRequiredSection("MareSynchronos"); + var defaultMethodConfig = new MethodConfig + { + Names = { MethodName.Default }, + RetryPolicy = new RetryPolicy + { + MaxAttempts = 100, + InitialBackoff = TimeSpan.FromSeconds(1), + MaxBackoff = TimeSpan.FromSeconds(5), + BackoffMultiplier = 1.5, + } + }; + services.AddGrpcClient(c => { c.Address = new Uri(mareSettings.GetValue("ServiceAddress")); + }).ConfigureChannel(c => + { + c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } }; }); services.AddGrpcClient(c => { c.Address = new Uri(mareSettings.GetValue("ServiceAddress")); + }).ConfigureChannel(c => + { + c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } }; }); services.AddDbContextPool(options =>