prometheus/promql
beorn7 9eafed0f79 promql: Add histogram_count and histogram_sum
This follow a simple function-based approach to access the count and
sum fields of a native Histogram. It might be more elegant to
implement “accessors” via the dot operator, as considered in the
brainstorming doc [1]. However, that would require the introduction of
a whole new concept in PromQL. For the PoC, we should be fine with the
function-based approch. Even the obvious inefficiencies (rate'ing a
whole histogram twice when we only want to rate each the count and the
sum once) could be optimized behind the scenes.

Note that the function-based approach elegantly solves the problem of
detecting counter resets in the sum of observations in the case of
negative observations. (Since the whole native Histogram is rate'd,
the counter reset is detected for the Histogram as a whole.)

We will decide later if an “accessor” approach is really needed. It
would change the example expression for average duration in
functions.md from

      histogram_sum(rate(http_request_duration_seconds[10m]))
	/
      histogram_count(rate(http_request_duration_seconds[10m]))

to

      rate(http_request_duration_seconds.sum[10m])
	/
      rate(http_request_duration_seconds.count[10m])

[1]: https://docs.google.com/document/d/1ch6ru8GKg03N02jRjYriurt-CZqUVY09evPg6yKTA1s/edit

Signed-off-by: beorn7 <beorn@grafana.com>
2022-06-28 18:16:48 +02:00
..
fuzz-data
parser promql: Add histogram_count and histogram_sum 2022-06-28 18:16:48 +02:00
testdata Adds day_of_year function to PromQL 2022-05-20 14:08:34 +02:00
bench_test.go Track and report Samples Queried per query 2022-03-21 23:49:17 +01:00
engine_test.go promql: Add histogram_count and histogram_sum 2022-06-28 18:16:48 +02:00
engine.go Merge branch 'main' into beorn7/sparsehistogram 2022-06-09 20:50:30 +02:00
functions_test.go Avoid literal integer overflows in 32 bit arches. 2022-03-29 22:51:20 +02:00
functions.go promql: Add histogram_count and histogram_sum 2022-06-28 18:16:48 +02:00
fuzz_test.go error for invalid media type should not be completely swallowed (#10186) 2022-02-08 10:57:56 +01:00
fuzz.go refactor (promql): move from github.com/pkg/errors to 'errors' and 'fmt' (#10817) 2022-06-08 10:47:52 +02:00
promql_test.go add doc 2022-02-13 21:59:03 +08:00
quantile.go promql: Add histogram_fraction function 2022-06-28 15:58:03 +02:00
query_logger_test.go refactor: move from io/ioutil to io and os packages (#10528) 2022-04-27 11:24:36 +02:00
query_logger.go Improve error logging for missing config and QL dir (#10260) 2022-02-16 17:43:15 +01:00
test_test.go tsdb: Rework iterators (#9877) 2021-11-29 13:24:23 +05:30
test.go refactor (promql): move from github.com/pkg/errors to 'errors' and 'fmt' (#10817) 2022-06-08 10:47:52 +02:00
value.go Merge branch 'main' into beorn7/sparsehistogram 2022-06-09 20:50:30 +02:00