caddyhttp: support Prometheus native histograms
Issue Details
Would Caddy be open to supporting Prometheus native histograms for its HTTP metrics?
Right now, the histograms in modules/caddyhttp/metrics.go use fixed buckets. This includes request and response durations and sizes. Each bucket creates another time series for every label combination, which can add up quickly when options such as per_host are enabled. Fixed buckets also mean operators have to choose the useful boundaries ahead of time.
prometheus.ExponentialBuckets, which Caddy uses for request and response sizes, still creates a fixed list of bucket boundaries. It is different from a Prometheus native histogram.
Caddy already uses client_golang v1.23.2. That version can collect native histograms when NativeHistogramBucketFactor is greater than 1, although the native histogram options are still marked experimental.
I think this should be opt-in at first. The existing buckets could remain enabled alongside the native histogram so current dashboards and recording rules keep working. It could be configured through the global metrics options in the Caddyfile and the corresponding JSON fields.
I'm not sure how much configuration Caddy should expose. A simple switch with sensible defaults may be enough, or it could expose the bucket factor and memory controls such as NativeHistogramMaxBucketNumber and NativeHistogramMinResetDuration. I'd be happy to follow whichever approach maintainers prefer.
On the Prometheus side, users would still need scrape_native_histograms: true. Remote write users may also need send_native_histograms: true. Caddy's existing Prometheus-to-OTel bridge can already convert native histograms to OTel exponential histograms.
The four metrics this would affect are:
caddy_http_request_duration_secondscaddy_http_response_duration_secondscaddy_http_request_size_bytescaddy_http_response_size_bytes
Assistance Disclosure
AI used
If AI was used, describe the extent to which it was used.
OMO/Sisyphus using GPT-5.6 Sol helped research and draft this proposal. I reviewed and verified the technical details before submitting it.
Source: caddyserver/caddy