Skip to content
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

Allow setting a time offset for individual metrics in a query #529

Closed
juliusv opened this Issue Feb 15, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@juliusv
Copy link
Member

juliusv commented Feb 15, 2015

This would help use cases like prometheus-junkyard/promdash#201.

Suggestions so far:

  • extending existing range syntax: mymetric[range,offset], where range is optional. Downside: would be confusing if [] could return both instant vectors and range vectors.
  • adding a modifier keyword: mymetric offset 1h.
  • adding a special operator that can only take literals: offset(mymetric, 1h)
  • ...maybe an even better solution that combines the benefits of the above with fewer drawbacks.
@juliusv

This comment has been minimized.

Copy link
Member Author

juliusv commented Feb 15, 2015

Potentially we could also decide that we don't want to have this as a server-side feature at all and instead leave it up to the presentation layer to do multiple queries for different ranges - this depends on whether we have use cases for actually combining different offsets in the same query. I can imagine some, like wanting to only graph the difference (-) between the current state and the state 1w ago, or so.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Feb 15, 2015

This is useful for alerts when comparing against the past, so it needs to be in the rule language.

I think the modifier is the cleanest, the others introduce semantic special cases.

juliusv added a commit that referenced this issue Feb 18, 2015

Implement offset operator.
This allows changing the time offset for individual instant and range
vectors in a query.

For example, this returns the value of `foo` 5 minutes in the past
relative to the current query evaluation time:

    foo offset 5m

Note that the `offset` modifier always needs to follow the selector
immediately. I.e. the following would be correct:

    sum(foo offset 5m) // GOOD.

While the following would be *incorrect*:

    sum(foo) offset 5m // INVALID.

The same works for range vectors. This returns the 5-minutes-rate that
`foo` had a week ago:

    rate(foo[5m] offset 1w)

This change touches the following components:

* Lexer/parser: additions to correctly parse the new `offset`/`OFFSET`
  keyword.
* AST: vector and matrix nodes now have an additional `offset` field.
  This is used during their evaluation to adjust query and result times
  appropriately.
* Query analyzer: now works on separate sets of ranges and instants per
  offset. Isolating different offsets from each other completely in this
  way keeps the preloading code relatively simple.

No storage engine changes were needed by this change.

The rules tests have been changed to not probe the internal
implementation details of the query analyzer anymore (how many instants
and ranges have been preloaded). This would also become too cumbersome
to test with the new model, and measuring the result of the query should
be sufficient.

This fixes #529
This fixed prometheus-junkyard/promdash#201

@juliusv juliusv closed this in #536 Feb 18, 2015

simonpasquier pushed a commit to simonpasquier/prometheus that referenced this issue Oct 12, 2017

Add standard exports into the documentation (prometheus#529)
Add standard exports into the documentation
@lock

This comment has been minimized.

Copy link

lock bot commented Mar 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 24, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.