Skip to content

Omit _sum for negative-bucket histograms in multiprocess mode - #1254

Open
haeganm wants to merge 1 commit into
prometheus:masterfrom
haeganm:negative-bucket-histogram-count
Open

haeganm wants to merge 1 commit into
prometheus:masterfrom
haeganm:negative-bucket-histogram-count

Conversation

@haeganm

@haeganm haeganm commented Nov 10, 2026

Copy link
Copy Markdown

Histogram leaves out _sum when its lowest bucket is negative. that's been the case since #496, it's what OpenMetrics 1.0 says ("Negative threshold buckets MAY be used, but then the Histogram MetricPoint MUST NOT contain a sum value"), and it was confirmed as intended in #552 and #782. MultiProcessCollector builds histogram samples on its own and never checks for this, so in multiprocess mode the same histogram still has a _sum:

# Histogram('temp_delta', 'help', buckets=[-1, 0, 1]).observe(-0.5), multiprocess
temp_delta_sum -0.5
temp_delta_bucket{le="-1.0"} 0.0
temp_delta_bucket{le="0.0"} 1.0
temp_delta_bucket{le="1.0"} 1.0
temp_delta_bucket{le="+Inf"} 1.0
temp_delta_count 1.0

single process gives the same lines without temp_delta_sum.

this drops _sum on the accumulate path when the lowest bucket is negative, so both modes match. merge(files, accumulate=False) still returns the raw value, since that's for writing merged values back to files. I also added a line to the histogram docs, since they list _sum as always there.

heads up, this means multiprocess users with negative buckets lose _sum. and OpenMetrics 2.0 goes the other way (every histogram MUST have count and sum, and negative thresholds are allowed). if you'd rather keep _sum and change single process instead, happy to flip it.

test_histogram_negative_buckets fails on master (AssertionError: 1.5 is not None) and passes here. full suite passes on 3.10 (Linux) and 3.12 (Windows), and flake8, isort and mypy are clean.

@csmarchbanks

Histogram leaves out _sum when its lowest bucket is negative, since
OpenMetrics 1.0 doesn't allow a sum there. MultiProcessCollector builds
its own histogram samples and kept the _sum from the mmap files, so the
same histogram exposed an extra series in multiprocess mode.

Drop _sum on the accumulate path when the lowest bucket bound is
negative. merge(accumulate=False) still returns the raw value.

Signed-off-by: Haegan McGarry <haeganm@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant