PromQL - How to filter metric entries based on first occurence?

53 Views Asked by At

The kube_job_status_failed is a constant metric (either 1 or 0) for which we have entries that already appeared before a selected time range.

How do we filter those jobs that reported their first metrics in the given time range?

Or ask differently:

How do we filter the metric entries for those jobs that were created and finished in the given time range?


Further explanation

As far as I understand kube_job_status_failed, as long as the kubernetes job isn't deleted, the metric will stay 1 and doesn't change until the job is removed.

Failed job test-sync was executed 3 hours ago, filtering for kube_job_status_failed{job_name="test-sync"} > 0 within the last 2 days makes this visible as the line for that job starts only 12:00:

test-sync

Failed job test-sync-old was executed 14.01.2024 at 03:00, filtering for kube_job_status_failed{job_name="test-sync-old"} > 0 within the last 2 days, the job line starts at the beginning of the selected range:

test-sync-old

As there are many reported job metrics with kube_job_status_failed of jobs that started before our selected time range, I only want to select those metrics which first reported value started within our time range, excluding those metrics where the line is there at the beginning of our selected range.

So in this example only test-sync should show up.

0

There are 0 best solutions below