I want to get an alert when the recent job of a cronjob fails. The expr
kube_job_status_failed{job_name=~"cronjobname.*"}==1
works for most of time. But if a job fails and it's kept, even the next job succeeds, I still get an alert because there are two records in prometheus, one of which is the failure record, the other one is the success record.
I found I can get the latest job timestamp from kube_cronjob_status_last_schedule_time{cronjob="cronjobname"}
, then use kube_job_status_failed{job_name="cronjobname-TIMESTAMP"}
to query the last job status.
I wonder whether we have a way in one query to concatenate the jobname
from the result of the first query and filter in the second? like
kube_job_status_failed{job_name=string_concatenate("cronjobname-", kube_cronjob_status_last_schedule_time{cronjob="cronjobname"})}