Originally published on kuryzhev.cloud
The scenario
Your latency histogram has 14 buckets, 400 label combinations and a p99 alert that jumps around whenever someone adds a service with a different bucket layout. Every label combination produces one series per bucket plus _sum and _count, and your hand-picked le boundaries are wrong for half the endpoints. This is the situation native histograms are designed for: one series per histogram, exponential buckets chosen automatically, and a bounded relative error instead of guessed boundaries.
The timing is good. Prometheus 3.16 shipped in November 2026. Native histograms became a stable, documented feature during the 3.x line, so on current releases they no longer need to be explained as an experiment. If you are already planning a 3.16 upgrade, this is a sensible change to bundle with it, as long as you roll it out in phases.
Short answer:
- Instrument services so they expose classic and native histograms at the same time.
- Enable native histogram scraping in Prometheus while keeping classic scraping.
- Rewrite dashboards and alerts to the native form one at a time.
- Drop the classic buckets only after the native queries have run in parallel for a full alert and SLO window.
Skip the migration if your remote storage does not accept native histograms, or if your SLOs depend on exact custom bucket boundaries.
Prerequisites
Check these before touching a config file:
- Prometheus 3.x (3.16.0 is current). Option names for native histograms have moved between 3.x releases, so compare the snippets below with the configuration reference for your exact version.
-
A client library with native histogram support. The Go client (
client_golang) supports them. For Java, Python and others, check the library's release notes and the native histograms specification. The examples use Go 1.27. - Protobuf exposition. The established way to transfer native histograms at scrape time is the Prometheus protobuf format. Support in text formats depends on your Prometheus and client versions. Any proxy or sidecar between Prometheus and the target must pass protobuf through untouched.
-
Downstream support. If you use
remote_writeto Mimir, Thanos, Grafana Cloud or another vendor, confirm in their docs that native histograms are accepted and what they cost. Do not assume. -
An inventory of consumers. List the dashboards, recording rules, alert rules and SLO tooling that reference
*_bucketseries. Agrep -rn "_bucket" rules/ dashboards/in your config repo is a good start.
Also decide your rollback. Classic buckets stay in place through steps 1 to 3, so rollback means reverting the Prometheus config and leaving the instrumentation alone.
Step 1: Expose classic and native buckets together
In client_golang, a histogram becomes native-capable when you set the native histogram options. If you also keep Buckets, the same metric is exposed in both forms, which is exactly what the migration needs. Do not add a job label in instrumentation. Prometheus attaches job as a target label and would rename yours to exported_job.
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "HTTP request latency.",
// Keep the old layout so existing dashboards and alerts keep working.
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5},
// Native histogram settings.
NativeHistogramBucketFactor: 1.1, // each bucket at most ~10% wider than the previous
NativeHistogramMaxBucketNumber: 100, // cap on buckets per histogram
NativeHistogramMinResetDuration: time.Hour, // minimum time between resets when the cap is hit
}, []string{"route", "code"})
๐งช Lab โ try this in your browser
- PromQL Builder โ Build Prometheus PromQL queries from metric name, labels, aggregation and range selectors.
Watch out for the bucket cap. When a histogram exceeds NativeHistogramMaxBucketNumber, client_golang first checks NativeHistogramMinResetDuration. If that much time has passed since the last reset, the histogram is reset, and Prometheus sees this as a counter reset. Otherwise the client widens the zero bucket (if NativeHistogramMaxZeroThreshold allows it) or halves the resolution.
The default of 0 means the histogram never resets and only loses resolution. Set the option deliberately in a high-variance service instead of leaving the default.
Step 2: Scrape native histograms next to classic ones
Now tell Prometheus to ingest them. Start with a single scrape job so the blast radius is small.
# prometheus.yml
scrape_configs:
- job_name: checkout-api
scrape_native_histograms: true # ingest native histograms (recent 3.x option; check your version's docs)
always_scrape_classic_histograms: true # keep _bucket series during migration
scrape_protocols: # protobuf first, so native histograms can be negotiated
- PrometheusProto
- OpenMetricsText1.0.0
- OpenMetricsText0.0.1
- PrometheusText0.0.4
kubernetes_sd_configs:
- role: pod
relabel_configs: # only scrape checkout-api pods, not the whole cluster
- source_labels: [__meta_kubernetes_pod_label_app]
regex: checkout-api
action: keep
# Only if you forward to a backend that accepts native histograms:
remote_write:
- url: https://metrics.example.internal/api/v1/push
send_native_histograms: true
Older 3.x releases gate native histograms behind --enable-feature=native-histograms on the command line instead of the per-job option. The release notes for your version will say which applies.
For services you cannot re-instrument, convert_classic_histograms_to_nhcb: true converts classic histograms into native histograms with custom buckets. That gives you the single-series storage model but not the automatic exponential resolution, so treat it as a stopgap.
Reload with curl -X POST localhost:9090/-/reload (requires --web.enable-lifecycle), send SIGHUP, or restart. While both forms are ingested, expect the series count and memory to go up, not down. The savings from fewer series only arrive after classic scraping is switched off in step 4, and each native histogram sample is larger than a single classic sample.
Step 3: Rewrite queries, rules and alerts
Native histograms live under the base metric name. There is no _bucket suffix and no le label, so the classic pattern changes shape.
# Classic
histogram_quantile(0.99,
sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))
# Native: no le, no _bucket
histogram_quantile(0.99,
sum by (job) (rate(http_request_duration_seconds[5m])))
# Request count and mean latency from the same series
histogram_count(sum by (job) (rate(http_request_duration_seconds[5m])))
histogram_sum(sum by (job) (rate(http_request_duration_seconds[5m])))
/ histogram_count(sum by (job) (rate(http_request_duration_seconds[5m])))
# Share of requests under 250 ms (an SLI)
histogram_fraction(0, 0.25, sum by (job) (rate(http_request_duration_seconds[5m])))
Gotcha: histogram_fraction and histogram_quantile interpolate inside exponential buckets. A threshold that falls mid-bucket yields an estimate, not an exact count. If your SLO contract names a precise boundary such as 300 ms and auditors expect exact counts, keep a classic (or custom-bucket) histogram that includes that boundary for that metric.
Recording rules can output native histograms too. For example, recording sum by (job) (rate(http_request_duration_seconds[5m])) lets dashboards run quantiles on a pre-aggregated histogram.
Duplicate each alert as a temporary *_native rule and compare firing behavior before replacing the original. In Grafana 13.3, use the Prometheus data source with the heatmap panel for native histograms. See the Grafana what's new page for current panel support.
Step 4: Cut over and drop the classic buckets
Only shrink the footprint once every consumer reads the native form:
- Remove
always_scrape_classic_histogramsfrom the job. - In code, delete the
Bucketsfield. - Do it job by job, not fleet-wide.
- Keep the previous config in Git so a revert is one commit.
Historical classic data stays queryable until retention expires, so old dashboards over past ranges still work. New data will not appear in them.
Verify and test
First, confirm Prometheus is actually storing native histograms. A raw instant query returns a histogram field instead of a value field:
curl -s localhost:9090/api/v1/query \
--data-urlencode 'query=http_request_duration_seconds{job="checkout-api"}' \
| jq '.data.result[0]'
# Expected shape: { "metric": {...}, "histogram": [ <timestamp>, { "count": "...", "sum": "...", "buckets": [...] } ] }
# If you only see "value" or no result, Prometheus is still ingesting classic series only.
# Compare classic and native p99 side by side; expect close, not identical, values
promtool query instant http://localhost:9090 \
'histogram_quantile(0.99, sum by (job) (rate(http_request_duration_seconds[5m])))'
promtool query instant http://localhost:9090 \
'histogram_quantile(0.99, sum by (job, le) (rate(http_request_duration_seconds_bucket[5m])))'
Then check three more things:
-
Series counts.
count({job="checkout-api"})should drop once classic scraping is off, andprometheus_tsdb_head_seriesshould trend down. -
Scrape health. Check
up{job="checkout-api"}and the Prometheus logs for scrape errors after the protocol change. - Alert parity. Run both alert versions in parallel for at least a full alert and SLO evaluation window before deleting the old rule. One daily traffic cycle is not enough for a 28- or 30-day SLO.
Wrap-up
Native histograms trade bucket guesswork for automatic resolution and fewer series, but the cost is real:
- client library upgrades
- rewritten PromQL
- larger samples
- a temporary increase in series during dual exposition
- a hard dependency on every backend in your pipeline understanding the format
Run both forms in parallel, migrate one job and its alerts at a time, and keep a classic or custom-bucket histogram where a contract needs an exact boundary. Check the Prometheus release notes for version-specific details, find more infrastructure guides on kuryzhev.cloud, and keep the official Prometheus documentation open for option names that change between 3.x releases.
Top comments (0)