-
Notifications
You must be signed in to change notification settings - Fork 136
Add support for relative time specifications in Prometheus queries #142
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
Add support for relative time specifications in Prometheus queries #142
Conversation
c986143
to
83c606b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @leandregagnonlewis! Thanks so much for adding this, really useful :)
I started playing with it and I got an error, it seems that ParseDuration
doesn't support days as relative time 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, one small comment!
removed openhands config removed openhands config remove extra file
fcc3502
to
a918f83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leandregagnonlewis, thanks for the PR!
My hunch would be that we should switch to a single of each start
and end
parameter and accept either RFC3339 or relative times (now
etc) in that single param, rather than having multiple. That would match the way Grafana's start/end times work in the UI and should be fairly easy to handle. Do you think that would work, or can you see any downsides to that approach?
I think you are right. I initially did not want to break the existing tool interface, but I guess it should not matter with an MCP server. I will work on this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests 👍 added a comment inline on the gtime package though.
… services have been started a while ago + added test for other durations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks so much @leandregagnonlewis 💪
We should be able to reuse this in other queries (e.g. Loki) but we can cross that bridge later. |
Add support for relative time specifications in Prometheus queries
Related issue
#121
Description
This PR adds support for relative time specifications in Prometheus queries by allowing relative times in the
StartTime
andEndTime
fields to theQueryPrometheusParams
struct. This enhancement allows users to specify time ranges using human-readable formats like "now" and "now-1h" instead of having to manually format RFC3339 timestamps.Changes
StartRFC3339
andEndRFC3339
fields ofQueryPrometheusParams
struct toStartTime
andEndTime
parseRelativeTime
helper function to convert relative time expressions to absolute timestampsqueryPrometheus
function to handle both RFC3339 and relative time formatsImplementation Details
The implementation supports two formats:
now
- representing the current timenow-<duration>
- representing a time in the past relative to now (e.g., "now-1h" for one hour ago)The duration format follows Go's standard duration format (e.g., "1h", "30m", "1h30m", etc.).
Testing
parseRelativeTime
function