fix: cap percentile at last finite bucket when target falls in open +Inf bucket
This commit is contained in:
@@ -8,6 +8,7 @@ Traefik exposes Prometheus metrics at /metrics. This module:
|
||||
and latency percentiles (p50, p95, p99) via linear histogram interpolation
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import math
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
@@ -171,10 +172,14 @@ def _percentile_ms(
|
||||
prev_le, prev_count = router_buckets[i - 1]
|
||||
if count == prev_count:
|
||||
return prev_le * 1000.0
|
||||
if math.isinf(le):
|
||||
# Percentile falls in the open (last_finite_le, +Inf] bucket;
|
||||
# cap at the last finite bucket upper bound.
|
||||
return prev_le * 1000.0
|
||||
fraction = (target - prev_count) / (count - prev_count)
|
||||
return (prev_le + fraction * (le - prev_le)) * 1000.0
|
||||
|
||||
return router_buckets[-2][0] * 1000.0 # last finite bucket upper bound
|
||||
return 0.0 # unreachable: +Inf bucket always satisfies count >= target
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user