Prometheus refuses to parse valid-by-spec metrics (Golang hex floats)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 717
- Forks
- 1.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 19
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Prometheus exposition format documentation and the promtool check metrics entry point described in the report. Compare the documented value syntax with Go's strconv.ParseFloat and inspect expfmt/text_parse.go around line 771. Done means the documented valid hexadecimal float example is accepted without the reported parsing error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100