prometheus / prometheus/prometheus

promql: arithmetic on durations

Open
#12,318 17 comments 0 reactions 1 assignee View on GitHub

@krajorama is already working on this.

Since Jan 29, 2025.

component/promql kind/feature not-as-easy-as-it-looks priority/P3
Dominant language
Go
Stars
66.1k
Forks
10.8k
Avg merge
2d 1h
Merged PRs (30d)
131

Description

What did you do?

I was trying to retrieve specific metrics at yesterdays midnight (23:59:59) by using something like this:

some_custom_metric @ <timestamp>

while

(time() - (hour(vector(time())) * 60 * 60 + minute(vector(time())) * 60) - 60)
and
0+(time() - (hour(vector(time())) * 60 * 60 + minute(vector(time())) * 60) - 60)

returns an OK timestamp, but while trying to use it like

some_custom_metric @ (time() - (hour(vector(time())) * 60 * 60 + minute(vector(time())) * 60) - 60)
or
some_custom_metric @ 0+(time() - (hour(vector(time())) * 60 * 60 + minute(vector(time())) * 60) - 60)

I'm receiving these kinds of errors

Error executing query: 1:10: parse error: unexpected "(" in @, expected timestamp
or
Error executing query: 1:1: parse error: @ modifier must be preceded by an instant vector selector or range vector selector or a subquery
What did you expect to see?

Metric at a specific time.

What did you see instead? Under which circumstances?

Errors:

Error executing query: 1:10: parse error: unexpected "(" in @, expected timestamp
or
Error executing query: 1:1: parse error: @ modifier must be preceded by an instant vector selector or range vector selector or a subquery
System information

Prometheus in K8s via Helm (2.43.0)

Prometheus version
Version	2.43.0
Revision	edfc3bcd025dd6fe296c167a14a216cab1e552ee
Branch	HEAD
BuildUser	root@8a0ee342e522
BuildDate	20230321-12:56:07
GoVersion	go1.19.7
Prometheus configuration file
-
Alertmanager version
-
Alertmanager configuration file
-
Logs
-

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.