diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-09-07 18:27:54 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-09-07 18:27:54 -0500 |
| commit | 0c395f46df8b966d149fbcba697b026b1605b62c (patch) | |
| tree | 1ef09c3c135f42ef0ed8026433fa208536351747 /src/slskd/Telemetry/PrometheusService.cs | |
| parent | 129227032ffcf2ec03cdb15f68f65caaf30985c5 (diff) | |
| download | slskd-0c395f46df8b966d149fbcba697b026b1605b62c.tar.gz | |
fix bug with object-based metric generation
Diffstat (limited to 'src/slskd/Telemetry/PrometheusService.cs')
| -rw-r--r-- | src/slskd/Telemetry/PrometheusService.cs | 25 |
1 files changed, 25 insertions, 0 deletions
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 @@ -30,6 +30,25 @@ public class PrometheusService private static Regex PrometheusLabelSplittingRegex { get; } = new Regex("([a-zA-Z_][a-zA-Z0-9_]*)\\s*=\\s*\"([^\"]*)\"", RegexOptions.Compiled); /// <summary> + /// 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. + /// </summary> + 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), + }; + + /// <summary> /// Get the current list of Prometheus metrics in Prometheus exposition format (text based). /// </summary> /// <returns></returns> @@ -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 }; |
