solaris
September 9, 2022, 11:16am
1
three stages:
stage1:{ duration: ‘1m’, vus: 100 }
stage:2{ duration: ‘1m’, vus: 200 }
stage3: { duration: ‘1m’, vus: 300 }
and every stage have multiple post requests use graphql query
footballquery1 = query football{...}
footballquery2= query football2{...}
racingquery1=query racingquery{...}
racingquery2=query racingquery2{...}
footballquery1 and footballquery2 are same categories
racingquery1 and racingquery2 are same categories
stage1,stage2,stage3 just different vus, but they must do those four post graphqlqueries: footballquery1 , footballquery2, racingquery1, racingquery4
i want to ouput those
stage1 average response time | rate of response time < 6s | error rate(404/500) | request/sec
football
racing
stage2 average response time | rate of response time < 6s | error rate(404/500) | request/sec
football
racing
stage3 average response time | rate of response time < 6s | error rate(404/500) | request/sec
football
racing
I’m a k6 newer and I read k6 tutorials, still can’t solve this problem, please help me, thanks a lot
Hi @solaris !
Welcome to the community forums!
I think the most proper way of solving your need is using End of test .
However, you achieve something similar to your needs by using the thresholds and tags.
So the following script:
import http from "k6/http";
import { sleep } from "k6";
import { tagWithCurrentStageIndex } from 'https://jslib.k6.io/k6-utils/1.3.0/index.js';
export let options = {
stages: [
{ target: 5, duration: "5s"},
{ target: 5, duration: "5s"},
{ target: 15, duration: "5s"},
],
thresholds: {
'http_req_duration{stage:0,sport:football}': ['avg < 200'],
'http_req_duration{stage:0,sport:racing}': ['avg < 200'],
'http_reqs{stage:0,sport:football}': ['count>0'],
'http_reqs{stage:0,sport:racing}': ['count>0'],
'http_reqs{stage:1,sport:football}': ['count>0'],
'http_reqs{stage:1,sport:racing}': ['count>0'],
'http_reqs{stage:2,sport:football}': ['count>0'],
'http_reqs{stage:2,sport:racing}': ['count>0'],
}
};
export default function() {
tagWithCurrentStageIndex();
http.get("https://test.k6.io/", {
tags: {sport: "football"}
})
http.get("https://test.k6.io/", {
tags: {sport: "racing"}
})
http.get("https://test.k6.io/", {
tags: {sport: "racing"}
})
sleep(1);
}
can produce output like:
Let me know if that answers,
Cheers!
solaris
September 14, 2022, 1:36pm
5
thanks for your answer a lot.
I just add some custom metrics, group my post request and config my thresholds
is “post” method add tags to my graphql query post like “get” method.
group("football", () => {
const footballResponse = http.post(
API_BASE_URL,
JSON.stringify(footballSubgraphqlQuery),
{ headers, tags: { sport: "football"} },
);
footballLessThan6sRate.add(footballResponse.timings.duration < 3600);
footballErrorRate.add(
footballResponse.status === 500 || footballResponse.status === 404
);
footballRequestPerSecond.add(1/60)
});
Yes, it should, like any other HTTP request.