prometheus/util
György Krajcsovits db46de3dcb
feat(api): add histogram_format=native to query endpoints
Add a new optional histogram_format query parameter to /api/v1/query
and /api/v1/query_range. When set to native, native histograms in the
JSON response are emitted in a schema-aware shape.

For exponential schemas:

  {
    "count":          "<count>",
    "sum":            "<sum>",
    "schema":         <int>,
    "zero_threshold": "<threshold>",
    "zero_count":     "<count>",                       // when non-zero
    "negative_buckets": [ [ <index>, "<count>" ], ... ], // when non-empty
    "buckets":          [ [ <index>, "<count>" ], ... ]  // when non-empty
  }

zero_threshold is always emitted because, together with schema, it
fully describes the bucket layout. The negative/positive bucket
arrays carry the schema-defined bucket index and count, so empty
buckets that fall between non-empty ones are not transmitted.

For custom-bucket histograms (schema -53):

  {
    "count":      "<count>",
    "sum":        "<sum>",
    "schema":     -53,
    "boundaries": [ "<upper_bound>", ... ],
    "buckets":    [ [ <index>, "<count>" ], ... ]
  }

boundaries lists the bucket upper bounds; each bucket entry's index
is the 0-based index into boundaries.

This lets clients that already understand the schema (e.g. Grafana
rendering NHCB heatmaps) reconstruct every bucket including empty
custom-bucket slots, and is also substantially more compact than the
boundary-based representation for histograms with many buckets.

The existing boundary-based representation is unchanged when
histogram_format is absent or set to any other value.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2026-05-22 19:13:40 +02:00
..
almost Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
annotations annotations: add warning for ineffective sort in range queries 2026-04-09 15:21:11 +02:00
compression Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
convertnhcb convertnhcb: reject NaN bucket boundary in SetBucketCount (#18383) 2026-03-31 14:23:17 +02:00
documentcli chore: fix emptyStringTest issues from gocritic (#18226) 2026-03-04 08:24:50 +01:00
features API: Add a /api/v1/features endpoint 2025-12-09 16:13:14 +01:00
fmtutil refactor: simplify of calling functions 2026-05-03 10:34:35 +02:00
fuzzing Revert "PromQL: Promote duration expressions as stable" 2026-05-13 09:59:50 +02:00
gate Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
httputil chore: fix httpNoBody issues from gocritic 2026-03-02 20:06:30 +01:00
jsonutil feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
junitxml Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
kahansum perf(PromQL): make floatHistogram.KahanAdd inlineable on Go 1.26 (#18568) 2026-04-27 08:43:13 +02:00
logging chore(kubernetes): deduplicate warning logs from the API 2026-03-12 08:34:33 +01:00
namevalidationutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
netconnlimit Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
notifications Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
osutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
pool Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
runtime util/runtime: simplify TestFsType comment per review 2026-04-15 15:54:02 +05:00
runutil Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
stats Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
strutil strutil/subsequence: rank exact matches above non-exact matches 2026-04-24 18:55:19 +02:00
testrecord tsdb(wal): st-per-sample for histograms initial code and benchmarks (#18221) 2026-05-06 14:33:03 -04:00
teststorage chore: enable staticcheck linter and update golangci-lint to 2.10.1 2026-02-18 15:58:16 +00:00
testutil chore: remove util/testutil/synctest now that we use Go>=1.25 2026-03-30 19:48:39 +02:00
testwal post merge conflict fixes 2026-03-12 09:03:08 +00:00
treecache chore(lint): enable wg.Go 2026-02-17 15:21:51 +01:00
zeropool Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00