prometheus/docs

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

sh01 opened this issue · 2 comments

sh01 commented

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

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.

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.