Skip to content

Parse the native histogram sum as a float#1192

Open
sean-kim05 wants to merge 1 commit into
prometheus:masterfrom
sean-kim05:fix/native-histogram-float-sum
Open

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

Conversation

@sean-kim05

Copy link
Copy Markdown

_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>
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