api/prometheus: clamp out-of-range formatted timestamps#2040
Open
happysnaker wants to merge 1 commit into
Open
api/prometheus: clamp out-of-range formatted timestamps#2040happysnaker wants to merge 1 commit into
happysnaker wants to merge 1 commit into
Conversation
Author
|
Maintainer context for review:
So the behavior change is intentionally narrow: fix the extreme out-of-range edge case without changing normal query parameter formatting. |
Signed-off-by: Shirong Lu <73147033+happysnaker@users.noreply.github.com>
happysnaker
force-pushed
the
fix-951-earliest-time-format
branch
from
July 1, 2026 16:01
6081f02 to
38d309a
Compare
bwplotka
approved these changes
Jul 10, 2026
bwplotka
left a comment
Member
There was a problem hiding this comment.
This is interesting one! It's not great if HTTP client changes the time ranges you ask for underhood.
But for general practicality that would make sense. People use lowest and highest for "any" range purpose. Let's fix this this way 👍🏽
One nit only, thanks!
Comment on lines
+1579
to
+1583
| // Prometheus's HTTP API accepts these boundary timestamps explicitly even | ||
| // though Go's RFC3339 parser cannot round-trip years with more than four | ||
| // digits. Keep these values aligned with the server-side defaults so very | ||
| // low/high sentinels like model.Earliest and model.Latest map to something | ||
| // the API can parse without overflowing. |
Member
There was a problem hiding this comment.
Let's mention the relevant server side code
Suggested change
| // Prometheus's HTTP API accepts these boundary timestamps explicitly even | |
| // though Go's RFC3339 parser cannot round-trip years with more than four | |
| // digits. Keep these values aligned with the server-side defaults so very | |
| // low/high sentinels like model.Earliest and model.Latest map to something | |
| // the API can parse without overflowing. | |
| // Prometheus's HTTP API accepts these boundary timestamps explicitly even | |
| // though Go's RFC3339 parser cannot round-trip years with more than four | |
| // digits. Keep these values aligned with the server-side defaults so very | |
| // low/high sentinels like model.Earliest and model.Latest map to something | |
| // the API can parse without overflowing. | |
| // Reference: https://github.com/prometheus/prometheus/blob/10cbff99a9d5998c4a5ad998b6cf41ea269bde08/web/api/v1/api.go#L834 |
Member
|
@happysnaker Would you have a look? We will cut a release soon and this could be included. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Clamp extremely low/high
time.Timevalues to Prometheus's documented parseable API boundary timestamps before formatting query parameters.What this fixes
Issue #951 reports that passing
model.Earliest.Time()through the client ends up formatting to a rounded float value like-9223372036854776, which overflows back into a large positive timestamp on the server side.This patch keeps normal timestamp formatting in the existing numeric API style, but special-cases values at or beyond the Prometheus API boundary sentinels so they serialize to the same RFC3339 strings that the server already recognizes explicitly.
Details
time.Time.UnixNano()for out-of-range valuesminTimeFormatted/maxTimeFormattedstringsmodel.Earliest.Time()model.Latest.Time()Fixes #951