Skip to content

Parse the native histogram sum as a float - #1192

Merged
csmarchbanks merged 1 commit into
prometheus:masterfrom
sean-kim05:fix/native-histogram-float-sum
Jul 24, 2026
Merged

Parse the native histogram sum as a float#1192
csmarchbanks merged 1 commit into
prometheus:masterfrom
sean-kim05:fix/native-histogram-float-sum

Conversation

@sean-kim05

Copy link
Copy Markdown
Contributor

_parse_nh_struct parsed the sum field with int(), so a native histogram
whose sum is not integral failed to parse with

ValueError: invalid literal for int() with base 10: '100.5'

NativeHistogram.sum_value is a float and the OpenMetrics writer emits the
sum verbatim (e.g. sum:100.5), so the library could not parse its own
output for the common case of a non-integer sum. Parse sum with float()
to match; count, schema and zero_count remain int as they are genuinely
integers.

Add test_native_histogram_float_sum, which parses a native histogram
with a fractional sum and checks it round-trips to sum_value 100.5.

@csmarchbanks

_parse_nh_struct parsed the sum field with int(), so a native histogram
whose sum is not integral failed to parse with

    ValueError: invalid literal for int() with base 10: '100.5'

NativeHistogram.sum_value is a float and the OpenMetrics writer emits the
sum verbatim (e.g. sum:100.5), so the library could not parse its own
output for the common case of a non-integer sum. Parse sum with float()
to match; count, schema and zero_count remain int as they are genuinely
integers.

Add test_native_histogram_float_sum, which parses a native histogram
with a fractional sum and checks it round-trips to sum_value 100.5.

Signed-off-by: Sean Kim <skim8705@gmail.com>

@csmarchbanks csmarchbanks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@csmarchbanks
csmarchbanks merged commit 5b09479 into prometheus:master Jul 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants