Is checks_rate metric sent if there are failed checks

I have a few checks in a test that I’m running on k6-operator and streaming the metrics to Grafana cloud Prometheus:

check(page, {'Title visible': page.locator('h1.site-heading').isVisible(),
            'Title correct': page.locator('h1.site-heading').textContent() == 'Next Wp Prod 627',
            'Live history section': page.locator('div#live-build-history-table').isVisible(),
            'Multidev section': page.locator('div#multidev-branch-table').isVisible(),
            'PR section': page.locator('div#pull-request-table').isVisible(),
            'Live deployment URL correct': page.locator('div.mb-4 a#deployment-url').textContent() ==
             some_url
        });

when some of the checks fail, i see it correctly in the report:

     checks..............................................: 83.33% βœ“ 5        βœ— 1

however, when i go check the k6_checks_rate value in Grafana, i don’t see any values. i only see values of 1 for tests where all the checks have passed. i see all other metric data for tests with failed checks but just not the checks metric. without it, i won’t know if the test passed or failed. Am I doing anything wrong or is that value not sent?

Hi @wjc ,

When a check fails, k6 will emit a value of 0.

The k6_checks_rate metric should yield a number between 0 and 1 that represents the percentage of successful checks.

For example, if I run this script:

import http from 'k6/http'
import { check, sleep } from 'k6'
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'

export const options = {
  vus: 10,
  duration: '1m'
}

export default function () {
  check(null, {
    'passing check': (r) => true,
    'failing check': (r) => false,
    'mixed': (r) => randomIntBetween(0, 1) === 0
  })
  
  sleep(1)
}

And use these PromQL queries:

k6_checks_rate{check="passing check"}
k6_checks_rate{check="failing check"}
k6_checks_rate{check="mixed"}

It produces output like this:

The last value reported by the line representing the mixed check that should fail roughly around half of the time is 0.47 which, when multiplied by 100, matches the number seen in the end-of-test summary:

     βœ“ passing check
     βœ— failing check
      ↳  0% β€” βœ“ 0 / βœ— 600
     βœ— mixed
      ↳  47% β€” βœ“ 282 / βœ— 318

Note, however, that I did not run this on k6-operator. Could you try the above in your cluster to see if you get similar results?

Are you using the -o cloud option when running your k6 command or -o output-prometheus-rw?

1 Like

thanks @tommiseur1

I’m using -o output-prometheus-rw

Ok I do see value of 0 for the failed checks, but what was hoping for is a aggregate percent of all the checks. So for your example above is there a way to see the combined percentage of your passing, failing, and mixed checks, for basically 1+0+.47/3 or just 0.49 instead of having to look at the checks_rate for each check? something like k6_checks_rate{check="all"}?

I guess in that case you just want the average:

avg(k6_checks_rate)