prometheus/web
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
..
api feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
ui Merge pull request #18687 from roidelapluie/roidelapluie/greatest_least 2026-05-21 10:34:29 +02:00
federate.go Refactor parse.go into an instance-based Parser interface 2026-02-11 11:21:49 +01:00
federate_test.go chore: fix httpNoBody issues from gocritic 2026-03-02 20:06:30 +01:00
web.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
web_test.go web/api: remove deprecated DELETE /api/v1/series endpoint (#18083) 2026-04-07 13:49:24 +02:00