Skip to content

Keep the sign of a negative OpenMetrics timestamp between -1 and 0 - #1253

Open
chrikrah wants to merge 2 commits into
prometheus:masterfrom
chrikrah:fix/openmetrics-negative-subsecond-timestamp
Open

chrikrah wants to merge 2 commits into
prometheus:masterfrom
chrikrah:fix/openmetrics-negative-subsecond-timestamp

Conversation

@chrikrah

@chrikrah chrikrah commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

@csmarchbanks, a small parser fix. _parse_timestamp() splits -0.5 at the dot and calls int("-0"), which gives 0, so a timestamp between -1 and 0 parses as +0.5. The spec allows negative timestamps, and since #1229 the library writes this exact value (tests/test_samples.py:19 expects -0.500000000). Exemplar timestamps take the same path.

The fix builds that case as Timestamp(-0.5, 500000000), the form the samples test already uses. The new test parses one sample at -0.500000000 and one exemplar at -0.250000000, next to a -1.5 control.

$ tox -e py3.12,flake8,isort,mypy   # base e2f2bf9 plus this branch
py3.12: OK (440 passed, 14 skipped)
flake8: OK
isort: OK
mypy: OK
# parser.py from e2f2bf9 with the new test kept: 1 failed (test_negative_subsecond_timestamps)
# not run: py3.10, py3.11, py3.13, py3.14, pypy

No issue exists for this; it follows #1229. I kept the fix in the parser and left Timestamp alone, because its constructor is public and the writer side already works. Does that split work for you?

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
…rics parser

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>

This branch has not been deployed

No deployments
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