Http_req_failed high on output.json but succed on console output

Hi Team,

I just run loadtest k6 using this script

import http from 'k6/http';
import { check, sleep } from 'k6';


// Accept these status codes as successful
// http.setResponseCallback(
//   http.expectedStatuses(200, 201, 202, 204, 302);
// );

// export let options = {
//   vus: 5, // Number of virtual users
//   duration: '10s', // Test duration
// };

// Load test configuration
export const options = {
    stages: [
        { duration: '10s', target: 10 },
        { duration: '10s', target: 20 },
        { duration: '30s', target: 60 },
        { duration: '90s', target: 20 },
        { duration: '10s', target: 10 },
        { duration: '30s', target: 0 },
    ],
    // Explicit failure thresholds (optional)
    thresholds: {
      http_req_failed: ['rate<0.05'], // Allow <5% failures
      http_req_duration: ['p(95)<1500']
    }
  };

export default function () {
  let res = http.get('https://test.k6.io'); // Replace with your API URL
  
  // ✅ Check if response status is 200
  check(res, {
    'Response status is 200': (r) => r.status === 200,
  });

  

  sleep(1); // Simulate real user wait time
}

The result on console like this below
http_req_failed…: 0.00% 0 out of 3732

    execution: local
        script: ./script-dasar-copy.js
        output: -

     scenarios: (100.00%) 1 scenario, 60 max VUs, 3m30s max duration (incl. graceful stop):
              * default: Up to 60 looping VUs for 3m0s over 6 stages (gracefulRampDown: 30s, gracefulStop: 30s)



  █ THRESHOLDS 

    http_req_duration
    ✓ 'p(95)<1500' p(95)=1.07s

    http_req_failed
    ✓ 'rate<0.05' rate=0.00%


  █ TOTAL RESULTS 

    checks_total.......................: 3732    20.698302/s
    checks_succeeded...................: 100.00% 3732 out of 3732
    checks_failed......................: 0.00%   0 out of 3732

    ✓ Response status is 200

    HTTP
    http_req_duration.......................................................: avg=409.49ms min=249.09ms med=278.85ms max=4.91s p(90)=713.24ms p(95)=1.07s
      { expected_response:true }............................................: avg=409.49ms min=249.09ms med=278.85ms max=4.91s p(90)=713.24ms p(95)=1.07s
    http_req_failed.........................................................: 0.00%  0 out of 3732
    http_reqs...............................................................: 3732   20.698302/s

    EXECUTION
    iteration_duration......................................................: avg=1.44s    min=1.24s    med=1.28s    max=8.5s  p(90)=1.8s     p(95)=2.21s
    iterations..............................................................: 3732   20.698302/s
    vus.....................................................................: 1      min=1         max=60
    vus_max.................................................................: 60     min=60        max=60

    NETWORK
    data_received...........................................................: 43 MB  240 kB/s
    data_sent...............................................................: 400 kB 2.2 kB/s

But on output.json file we got http_req_failed 3732

"root_group": {
        "name": "",
        "path": "",
        "id": "d41d8cd98f00b204e9800998ecf8427e",
        "groups": {},
        "checks": {
                "Response status is 200": {
                    "id": "6231ab582661f5cb4ca95f62ebf36012",
                    "passes": 3732,
                    "fails": 0,
                    "name": "Response status is 200",
                    "path": "::Response status is 200"
                }
            }
    },
    "metrics": {
        "http_req_failed": {
            "passes": 0,
            "fails": 3732,
            "thresholds": {
                "rate<0.05": false
            },
            "value": 0
        },

Can anyone explain why this result ? how to fix it ?

Regards,
Harun

Hi @wilanjar,

Welcome to our community forums! :tada:

First of all, apologies for the delayed answer. Somehow this got lost among my inbox.

Second, I think your case is just a misunderstanding of how metrics are reflected in these two places you referred to.

The reality, is that in your load test execution, no HTTP request did fail. That’s why:

  • checks_succeeded is 100% (3732 out of 3732), which verify Response status is 200.
  • http_req_failed is `0.00 (0 out of 3732), so no failures.

Then, what happens is that you’re being confused by how k6 represents metrics and their values.

The problem with that is that k6 doesn’t understand if a metric reflects a positive or negative event.
So, if the event the metric represents succeeds, it’s a “pass”, if not, it’s a “fail”.

If the metric represents a “positive” event, like an HTTP request as in http_reqs, everything is clear. A “pass” is a successful HTTP request, and a “fail” is an unsuccessful one.
But when the metric represents a “negative” event, like a HTTP failure, then it’s very confusing. Because, it still counts as “pass” every time the event happened. In this case, HTTP failures. And so, that’s why in your case, “passes” are 0, and “fails” are 3732, which in other words means: none of the HTTP requests failed.

Historically, we experienced the same issue with the human-readable end-of-test summary output (see this pull request and the discussions and issues referred there), and I think this is the equivalent type of confusion but for the JSON output. Indeed, we’re right now discussing a new JSON schema for the JSON output which hopefully will use more clear names and avoid this type of confusion next time.

I hope that helps, and now it’s all clear! :person_bowing:
And again, apologies for the delay :folded_hands:

1 Like