prometheus/web/api/v1
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
..
testdata feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
api.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
api_scenarios_test.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
api_test.go Use ProtoJSON, allow regex-based filtering of metric names 2026-04-10 16:05:40 +02:00
codec.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
codec_test.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
errors_test.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
helpers_test.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
json_codec.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
json_codec_native_histogram.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
json_codec_test.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
openapi.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
openapi_coverage_test.go Add OpenAPI 3.2 specification generation for Prometheus HTTP API (#17825) 2026-01-29 13:36:13 +01:00
openapi_examples.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
openapi_golden_test.go web: switch from gopkg.in/yaml to go.yaml.in/yaml (#17979) 2026-02-03 14:15:35 +00:00
openapi_helpers.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
openapi_paths.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
openapi_schemas.go feat(api): add histogram_format=native to query endpoints 2026-05-22 19:13:40 +02:00
openapi_test.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
search.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
search_filters.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
search_filters_bench_test.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
search_filters_test.go web/api: add search API endpoint (#18573) 2026-05-19 13:58:00 +02:00
search_test.go web/api: reject 0 for limit and batch_size in search endpoints (#18724) 2026-05-19 15:05:45 +00:00
translate_ast.go web/api: emit duration expression trees 2026-05-06 12:10:03 +02:00
translate_ast_test.go PromQL: Rename greatest, least, to max_of, min_of. 2026-05-19 13:07:16 +02:00