prometheus/promql
Jack Neely 896f951e68 Force buckets in a histogram to be monotonic for quantile estimation (#2610)
* Force buckets in a histogram to be monotonic for quantile estimation

The assumption that bucket counts increase monotonically with increasing
upperBound may be violated during:

  * Recording rule evaluation of histogram_quantile, especially when rate()
     has been applied to the underlying bucket timeseries.
  * Evaluation of histogram_quantile computed over federated bucket
     timeseries, especially when rate() has been applied

This is because scraped data is not made available to RR evalution or
federation atomically, so some buckets are computed with data from the N
most recent scrapes, but the other buckets are missing the most recent
observations.

Monotonicity is usually guaranteed because if a bucket with upper bound
u1 has count c1, then any bucket with a higher upper bound u > u1 must
have counted all c1 observations and perhaps more, so that c  >= c1.

Randomly interspersed partial sampling breaks that guarantee, and rate()
exacerbates it. Specifically, suppose bucket le=1000 has a count of 10 from
4 samples but the bucket with le=2000 has a count of 7, from 3 samples. The
monotonicity is broken. It is exacerbated by rate() because under normal
operation, cumulative counting of buckets will cause the bucket counts to
diverge such that small differences from missing samples are not a problem.
rate() removes this divergence.)

bucketQuantile depends on that monotonicity to do a binary search for the
bucket with the qth percentile count, so breaking the monotonicity
guarantee causes bucketQuantile() to return undefined (nonsense) results.

As a somewhat hacky solution until the Prometheus project is ready to
accept the changes required to make scrapes atomic, we calculate the
"envelope" of the histogram buckets, essentially removing any decreases
in the count between successive buckets.

* Fix up comment docs for ensureMonotonic

* ensureMonotonic: Use switch statement

Use switch statement rather than if/else for better readability.
Process the most frequent cases first.
2017-04-14 16:21:49 +02:00
..
fuzz-data Fuzzing corpus for ParseMetric. 2016-04-29 22:50:24 +02:00
testdata Force buckets in a histogram to be monotonic for quantile estimation (#2610) 2017-04-14 16:21:49 +02:00
ast.go Make the storage interface higher-level. 2016-07-25 13:59:22 +02:00
bench.go promql: Fix (and simplify) populating iterators 2016-08-24 18:37:09 +02:00
engine_test.go storage: Contextify storage interfaces. 2016-09-19 16:29:07 +02:00
engine.go Add promql.ErrStorage, which is interpreted by the API as a 500. 2017-04-06 14:41:23 +01:00
functions_test.go promql: Fix (and simplify) populating iterators 2016-08-24 18:37:09 +02:00
functions.go promql: handle NaN in changes() correctly 2016-09-30 11:04:25 +02:00
fuzz.go Updates fuzzers to discard less interesting data 2016-05-10 11:46:03 +02:00
lex_test.go Instantiate lexer inline for the test 2016-08-29 09:20:43 +02:00
lex.go Fix parsing of label names which are also keywords 2016-09-07 17:45:58 -04:00
parse_test.go Report type names in the form used in documentation 2016-11-18 10:12:55 +00:00
parse.go Report type names in the form used in documentation 2016-11-18 10:12:55 +00:00
printer_test.go Fix export of grouping modifier 2016-11-21 14:42:45 +00:00
printer.go Fix export of grouping modifier 2016-11-21 14:42:45 +00:00
promql_test.go Fix most golint warnings. 2015-08-26 12:44:46 +02:00
quantile.go Force buckets in a histogram to be monotonic for quantile estimation (#2610) 2017-04-14 16:21:49 +02:00
test.go storage: Contextify storage interfaces. 2016-09-19 16:29:07 +02:00