Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus refuses to parse valid-by-spec metrics (Golang hex floats) #2287

Open
sh01 opened this issue Jan 31, 2023 · 2 comments
Open

Prometheus refuses to parse valid-by-spec metrics (Golang hex floats) #2287

sh01 opened this issue Jan 31, 2023 · 2 comments

Comments

@sh01
Copy link

sh01 commented Jan 31, 2023

What did you do?

$ echo 'testmetric 0x1p0' | promtool check metrics

What did you expect to see?

testmetric no help text

According to https://prometheus.io/docs/instrumenting/exposition_formats/ , valid input to https://pkg.go.dev/strconv#ParseFloat should be a valid metric value.
Go's ParseFloat supports hexademical fp numbers, like e.g. "0x1p0"

What did you see instead? Under which circumstances?

error while linting: text format parsing error in line 1: expected float as value, got "0x1p0"

Prometheus, contrary to go's ParseFloat() does not support hexademical fp values, due to them containing a 'p'.
(I believe this is due to https://github.com/prometheus/common/blob/ca1f99be33b31b804a85a42cb7d3a1df23500bf8/expfmt/text_parse.go#L771 )

I encountered this issue after I wrote instrumentation code that outpus hexadecimal floats, and then noticed that Prometheus unexpectedly (and I believe contrary to spec) rejected them.

System information

No response

Prometheus version

2.30.3
(My distribution broke prometheus --version; I do not think this is crucial, since the relevant code seems to have been unchanged for multiple years.)

Prometheus configuration file

No response

Alertmanager version

No response

Alertmanager configuration file

No response

Logs

No response

@roidelapluie
Copy link
Member

Hello,

The spec is wrong and should be fixed. Prometheus should not accept those floats because it is quite specific and could be in many cases just typos.

The spec predates the introduction of that notation in golang.

@roidelapluie
Copy link
Member

This is a documentation change rather than a code change. I will move this issue to the documentation repository for further review and update the spec accordingly.

@roidelapluie roidelapluie transferred this issue from prometheus/prometheus Mar 6, 2023
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

No branches or pull requests

2 participants