From: Aleš Mrázek Date: Tue, 19 Aug 2025 13:44:13 +0000 (+0200) Subject: manager/metrics/prometheus: fix the answer latency histogram X-Git-Tag: v6.0.16~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58b43e2f6b1737487557518efee540add4b98252;p=thirdparty%2Fknot-resolver.git manager/metrics/prometheus: fix the answer latency histogram --- diff --git a/NEWS b/NEWS index 6246e7abf..9becaf0b4 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Improvements Bugfixes -------- - /options/query-case-randomization: respect this even on TCP issues (!1732) +- prometheus metrics: make the latency histogram cumulative (!1731, GH#117) Knot Resolver 6.0.15 (2025-07-17) diff --git a/python/knot_resolver/manager/metrics/prometheus.py b/python/knot_resolver/manager/metrics/prometheus.py index 5e8a130dc..4138b549f 100644 --- a/python/knot_resolver/manager/metrics/prometheus.py +++ b/python/knot_resolver/manager/metrics/prometheus.py @@ -52,12 +52,18 @@ if PROMETHEUS_LIB: # response latency histogram bucket_names_in_resolver = ("1ms", "10ms", "50ms", "100ms", "250ms", "500ms", "1000ms", "1500ms", "slow") bucket_names_in_prometheus = ("0.001", "0.01", "0.05", "0.1", "0.25", "0.5", "1.0", "1.5", "+Inf") + + # add smaller bucket counts + def _bucket_count(answer: Dict[str, int], duration: str) -> int: + index = bucket_names_in_resolver.index(duration) + return sum([int(answer[bucket_names_in_resolver[i]]) for i in range(index + 1)]) + yield _histogram( "resolver_response_latency", "Time it takes to respond to queries in seconds", label=("instance_id", sid), buckets=[ - (bnp, metrics["answer"][f"{duration}"]) + (bnp, _bucket_count(metrics["answer"], duration)) for bnp, duration in zip(bucket_names_in_prometheus, bucket_names_in_resolver) ], sum_value=metrics["answer"]["sum_ms"] / 1_000,