From 48d4009c695394fd6c68a4686d3de17e97c37a6c Mon Sep 17 00:00:00 2001 From: spiral Date: Tue, 9 Nov 2021 02:19:31 -0500 Subject: [PATCH] fix: fix reporting Discord response metrics to influxdb --- Myriad/Rest/BaseRestClient.cs | 11 +++++------ Myriad/Rest/DiscordApiClient.cs | 2 +- PluralKit.Bot/Modules.cs | 4 +++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Myriad/Rest/BaseRestClient.cs b/Myriad/Rest/BaseRestClient.cs index 68ecc9d6..f9f04000 100644 --- a/Myriad/Rest/BaseRestClient.cs +++ b/Myriad/Rest/BaseRestClient.cs @@ -209,12 +209,11 @@ namespace Myriad.Rest await HandleApiError(response, ignoreNotFound); - if (OnResponseEvent != null) - OnResponseEvent.Invoke(null, ( - GetEndpointMetricsName(response.RequestMessage!), - (int)response.StatusCode, - stopwatch.ElapsedTicks - )); + OnResponseEvent?.Invoke(null, ( + GetEndpointMetricsName(response.RequestMessage!), + (int)response.StatusCode, + stopwatch.ElapsedTicks + )); return response; }, diff --git a/Myriad/Rest/DiscordApiClient.cs b/Myriad/Rest/DiscordApiClient.cs index 3082574b..601a1309 100644 --- a/Myriad/Rest/DiscordApiClient.cs +++ b/Myriad/Rest/DiscordApiClient.cs @@ -19,7 +19,7 @@ namespace Myriad.Rest public DiscordApiClient(string token, ILogger logger, string? baseUrl = null) { _client = new BaseRestClient(UserAgent, token, logger, baseUrl ?? DefaultApiBaseUrl); - _client.OnResponseEvent += OnResponseEvent; + _client.OnResponseEvent += (_, ev) => OnResponseEvent?.Invoke(null, ev); } public EventHandler<(string, int, long)> OnResponseEvent; diff --git a/PluralKit.Bot/Modules.cs b/PluralKit.Bot/Modules.cs index 7c54ef4a..c348c1ad 100644 --- a/PluralKit.Bot/Modules.cs +++ b/PluralKit.Bot/Modules.cs @@ -52,10 +52,12 @@ namespace PluralKit.Bot c.Resolve().DiscordBaseUrl ); + var metrics = c.Resolve(); + client.OnResponseEvent += ((_, ev) => { var (endpoint, statusCode, ticks) = ev; - var timer = c.Resolve().Provider.Timer.Instance(BotMetrics.DiscordApiRequests, new MetricTags( + var timer = metrics.Provider.Timer.Instance(BotMetrics.DiscordApiRequests, new MetricTags( new[] { "endpoint", "status_code" }, new[] { endpoint, statusCode.ToString() } ));