Skip to content

promql: arithmetic on durations #12318

@aamkye

Description

@aamkye

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

-

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions