question 477 Observability & Operations · medium
Turn durations into histogram buckets
Monitoring systems store durations as histograms with cumulative buckets: for each upper bound, how many requests took at most that long, plus a final bucket counting everything. From those counts any percentile can be estimated later. Build the buckets from raw durations.
Function
histogram(durations, bounds)boundsupper bounds in milliseconds, in increasing order (e.g.
[50, 100, 250, 1000])Returnsa list of
(bound, count) tuples, one per bound, where count is the number of durations ≤ bound, followed by ("+Inf", total)Rulethe inputs are not changed
Examples
callhistogram([12, 48, 50, 95, 180, 640, 2400], [50, 100, 250, 1000])returns[(50, 3), (100, 4), (250, 5), (1000, 6), ('+Inf', 7)]
callhistogram([5, 5], [10])returns[(10, 2), ('+Inf', 2)]
callhistogram([], [100, 200])returns[(100, 0), (200, 0), ('+Inf', 0)]