Practice ยท 2 of 2
Counters, gauges, percentiles
1. static long p(List<Long> sortedMicros, double q) โ the q-th percentile of a
SORTED list: index = ceil(q * n) - 1, clamped to >= 0. p(x, 0.5) is the median.
2. static java.util.Map<String, Long> summarize(java.util.List<Long> durations) โ
sort internally, return {"p50":..., "p95":..., "p99":..., "count": n}.
3. static boolean avgHides(List<Long> durations) โ return true iff the MEAN is
less than p95 (the classic 'average looks fine' lie). Empty list โ false.
4. static boolean cardinalityOk(String labelKey) โ true iff labelKey is a CLASS
(one of "endpoint", "status", "region"), false for instance labels
("userId", "requestId", "url").
Difficulty: advanced
Press Submit to check your solution.
Back to lesson: Practice: Observability drills