From 05595329b5f9ddf1b387e3ef27a237920388f3e1 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 16 Apr 2020 18:20:53 +0200 Subject: [PATCH] Collect metrics about webhook rate limit cache size --- PluralKit.Bot/BotMetrics.cs | 1 + PluralKit.Bot/Services/PeriodicStatCollector.cs | 5 ++++- PluralKit.Bot/Services/WebhookRateLimitService.cs | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/BotMetrics.cs b/PluralKit.Bot/BotMetrics.cs index 04f21082..617ca307 100644 --- a/PluralKit.Bot/BotMetrics.cs +++ b/PluralKit.Bot/BotMetrics.cs @@ -16,6 +16,7 @@ namespace PluralKit.Bot public static GaugeOptions Channels => new GaugeOptions {Name = "Channels", MeasurementUnit = Unit.None, Context = "Bot"}; public static GaugeOptions ShardsConnected => new GaugeOptions { Name = "Shards Connected", Context = "Bot" }; public static GaugeOptions WebhookCacheSize => new GaugeOptions { Name = "Webhook Cache Size", Context = "Bot" }; + public static GaugeOptions WebhookRateLimitCacheSize => new GaugeOptions {Name = "Webhook Rate Limit Cache Size", Context = "Bot"}; public static TimerOptions WebhookResponseTime => new TimerOptions { Name = "Webhook Response Time", Context = "Bot", RateUnit = TimeUnit.Seconds, MeasurementUnit = Unit.Requests, DurationUnit = TimeUnit.Seconds }; } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/PeriodicStatCollector.cs b/PluralKit.Bot/Services/PeriodicStatCollector.cs index ba373be9..ce4ac953 100644 --- a/PluralKit.Bot/Services/PeriodicStatCollector.cs +++ b/PluralKit.Bot/Services/PeriodicStatCollector.cs @@ -21,12 +21,13 @@ namespace PluralKit.Bot private IDataStore _data; private WebhookCacheService _webhookCache; + private WebhookRateLimitService _webhookRateLimitCache; private DbConnectionCountHolder _countHolder; private ILogger _logger; - public PeriodicStatCollector(IDiscordClient client, IMetrics metrics, ILogger logger, WebhookCacheService webhookCache, DbConnectionCountHolder countHolder, IDataStore data, CpuStatService cpu) + public PeriodicStatCollector(IDiscordClient client, IMetrics metrics, ILogger logger, WebhookCacheService webhookCache, DbConnectionCountHolder countHolder, IDataStore data, CpuStatService cpu, WebhookRateLimitService webhookRateLimitCache) { _client = (DiscordShardedClient) client; _metrics = metrics; @@ -34,6 +35,7 @@ namespace PluralKit.Bot _countHolder = countHolder; _data = data; _cpu = cpu; + _webhookRateLimitCache = webhookRateLimitCache; _logger = logger.ForContext(); } @@ -80,6 +82,7 @@ namespace PluralKit.Bot // Other shiz _metrics.Measure.Gauge.SetValue(BotMetrics.WebhookCacheSize, _webhookCache.CacheSize); + _metrics.Measure.Gauge.SetValue(BotMetrics.WebhookRateLimitCacheSize, _webhookRateLimitCache.CacheSize); stopwatch.Stop(); _logger.Information("Updated metrics in {Time}", stopwatch.ElapsedDuration()); diff --git a/PluralKit.Bot/Services/WebhookRateLimitService.cs b/PluralKit.Bot/Services/WebhookRateLimitService.cs index 28c2477a..4977ee6a 100644 --- a/PluralKit.Bot/Services/WebhookRateLimitService.cs +++ b/PluralKit.Bot/Services/WebhookRateLimitService.cs @@ -24,6 +24,8 @@ namespace PluralKit.Bot _logger = logger.ForContext(); } + public int CacheSize => _info.Count; + public bool TryExecuteWebhook(IWebhook webhook) { // If we have nothing saved, just allow it (we'll save something once the response returns)