Search code examples
prometheuspromql

Is there a way to get latest value of a metric in Prometheus while ignoring(without) a label?


PROMQL Query that I tried is - last_over_time(METRIC_ABC{ INDICATORNAME="INDICATORNAME_1"}[6h])

Returns metrics -

METRIC_ABC{DATE="2022-04-27", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_1", instance="i_1", job="DB"} 10
METRIC_ABC{DATE="2022-04-27", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_2", instance="i_1", job="DB"} 15
METRIC_ABC{DATE="2022-04-28", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_1", instance="i_1", job="DB"} 11
METRIC_ABC{DATE="2022-04-28", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_2", instance="i_1", job="DB"} 16

I would like to get only the latest one while ignoring DATE label. i.e.

METRIC_ABC{DATE="2022-04-28", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_1", instance="i_1", job="DB"} 11
METRIC_ABC{DATE="2022-04-28", INDICATORNAME="INDICATORNAME_1", PRODUCT_NAME="PR_2", instance="i_1", job="DB"} 16

Is there any way of ignoring a label with last_over_time function or another approach to that? I am sure this is a common use case so does a function already exists for this which I could not find ?


Solution

  • You need to use an aggregating function like sum before:

    last_over_time(sum without (DATE) (METRIC_ABC{ INDICATORNAME="INDICATORNAME_1"}[6h]))