0

In Prometheus recording rules, I want to record the rate of job failure in each of my Jenkins job.

This expression will allow me to do that. Rate of failure for MyJenkinsJob_1.

 ( sum(jenkins_job_last_build_failed_tests{jobname="MyJenkinsJob_1"})
                or (absent(jenkins_job_last_build_failed_tests{jobname="MyJenkinsJob_1"})*0) )
          /
( sum(jenkins_job_last_build_total_tests{jobname="MyJenkinsJob_1"})
                or (absent(jenkins_job_last_build_total_tests{jobname="MyJenkinJobs_1"})*0) )

Since the logic(equation) is common for all jobs !, I could make use of the same expression by changing the variable value jobname.

Can we do it with some reg expression, so that i don't have to repeatedly hard code(create new rule) the Jenkins job name(eg: MyJenkinsJob_1, MyJenkinsJob_2, MyJenkinsJob_3, ......). Is there any feature available in Prometheus for that !

Vaisakh Rajagopal
  • 1,189
  • 1
  • 14
  • 23

1 Answers1

0

For this particular query this is not possible, as you need to provide a list of all jobname values that should exist somehow. I'd suggest looking at the templating support for your configuration management system to generate your rules for you.

brian-brazil
  • 31,678
  • 6
  • 93
  • 86