thresholdk6

Thresholds are passing but their values are zero


I am running a K6 script only for 1 VU on my local. However, "Create" threshold is displayed zero despite it passes. I wrote it in other way like "http_req_duration{name:${}/cases,method:PUT}": ["max < 100"] but nothing changed.

When I sent the results cloud, timings for "Cancel" request is displayed with this tag but for other one, it is displayed with its complete endpoint.

export const options = {
    scenarios: {
        ListIncidents: {
        executor: "per-vu-iterations",
        vus: 1,
        iterations: 1,
        maxDuration: "40s",
        gracefulStop: "50s",
        },
    },
    thresholds: {
    "http_req_duration{name:Create}": ["p(95) < 300", "p(99) < 400"],
    "http_req_duration{name:Cancel}": ["p(95) < 300", "p(99) < 400"],
   },
};

const URL = "URL";
const URL_2 = "URL_2";

export default function () {
    
    const access_token = Login();

    const headers = {
        //header for requests
        Authorization: "Bearer " + access_token,
        "Content-Type": "application/json",
    };

    //create 
    let res = http.put(
        `${URL_2}/cases`,
        "{}",
        { headers: headers },
        { tags: { name: "Create" } }
    );
    
    //Cancel 
    mainserverLogin();

    //cancel endpoint
    const cancel = http.post(`${URL}/api/cases/${res.body}/cancel`, "cancelled", {
        tags: { name: "Cancel" },
    });
}

export function handleSummary(data) {
    return {
        stdout: textSummary(data, { indent: "", enableColors: true }),
    };
}

Local Results

Cloud Results

(I had to change endpoints because of privacy)

I increased graceful stop time, wrote endpoints in different ways, used different endpoints but these did not solve.


Solution

  • Your http.put code sends the headers and tags as two different arguments

    let res = http.put(
        `${URL_2}/cases`, // 1st
        "{}",             // 2nd
        { headers: headers },  // 3rd
        { tags: { name: "Create" } } //4th
    );
    
    

    the 3rd argument of http.put (and most other http.* functions is an object with multiple fields. Two of which are headers and tags.

    In your case you set the headers but then send a forth argument http.put never looks at. So that it never tags the request correctly to begin with.

    The correct code is

    
    let res = http.put(
        `${URL_2}/cases`,
        "{}",
        { 
         headers: headers,
         tags: { name: "Create" },
        }
    );