From 0c395f46df8b966d149fbcba697b026b1605b62c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 7 Sep 2025 18:27:54 -0500 Subject: fix bug with object-based metric generation --- src/slskd/Telemetry/PrometheusService.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/slskd/Telemetry/PrometheusService.cs b/src/slskd/Telemetry/PrometheusService.cs index cead405a..06235981 100644 --- a/src/slskd/Telemetry/PrometheusService.cs +++ b/src/slskd/Telemetry/PrometheusService.cs @@ -29,6 +29,25 @@ public class PrometheusService private static Regex PrometheusLineSplittingRegex { get; } = new Regex(@"([a-zA-Z_:][a-zA-Z0-9_:]*)(?:{(.*)})?\s+([^\s]+)", RegexOptions.Compiled); private static Regex PrometheusLabelSplittingRegex { get; } = new Regex("([a-zA-Z_][a-zA-Z0-9_]*)\\s*=\\s*\"([^\"]*)\"", RegexOptions.Compiled); + /// + /// These metrics repeat many times with disambiguating labels, and this conflicts with the current approach + /// for building metrics in object format; dictionary entries (keyed by the names seen in this list) conflict, + /// and values are merged and potentially collide. This could be fixed by pulling disambiguating labels up into + /// the names, but these labels are things like HTTP route names, exception types, and server addresses. All of + /// which has very little value to an application that wants to display metrics to an end user (which is why this exists). + /// + /// The easy solution is to just ignore these classes of metrics, and that's what I'm going to do. + /// + /// This can be revisited if someone feels very strongly. + /// + private static Regex[] ExcludedMetrics { get; } = new[] + { + new Regex("^microsoft_aspnetcore_hosting_http_server_request_duration.*", RegexOptions.Compiled), + new Regex("^system_net_http_http_client_request_time_in_queue.*", RegexOptions.Compiled), + new Regex("^system_net_http_http_client_request_duration.*", RegexOptions.Compiled), + new Regex("^microsoft_aspnetcore_server_kestrel_kestrel_connection_duration.*", RegexOptions.Compiled), + }; + /// /// Get the current list of Prometheus metrics in Prometheus exposition format (text based). /// @@ -85,6 +104,12 @@ public class PrometheusService continue; } + // see the note above about excluded metrics and why this is necessary + if (ExcludedMetrics.Any(regex => regex.IsMatch(name))) + { + continue; + } + var type = lines[startIndex + 1].Substring(7).Split(' ', 2)[1]; var metric = new PrometheusMetric() { Name = name, Help = help, Type = type }; -- cgit v1.2.3