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.
Sure thing! It seems like you’re dealing with load testing scenarios in k6, and you want to monitor various metrics for GraphQL queries in different stages. It’s a bit complex, but I’ll try to break it down.
Firstly, ensure you’ve defined your queries and stages properly. Then, for each stage, you can use k6’s built-in metrics and custom functions to calculate the desired values. Here’s a rough outline:
javascriptCopy code
import http from 'k6/http';
import { sleep } from 'k6';
// Define your GraphQL queries here
const footballQuery1 = '...'; // Replace with actual query
const footballQuery2 = '...';
const racingQuery1 = '...';
const racingQuery2 = '...';
export const options = {
stages: [
{ duration: '1m', target: 100 }, // Adjust targets as needed
{ duration: '1m', target: 200 },
{ duration: '1m', target: 300 },
],
};
export default function () {
// Perform GraphQL queries here using http.post
// Sleep to control the request rate [service](https://servicezone.ae/furniture-movers), if needed
sleep(1);
}
// Add custom metrics and calculations
export function handleSummary(data) {
const footballResponseTimes = data.metrics.http_req_duration.filter((metric) => metric.tags.group === 'football');
const racingResponseTimes = data.metrics.http_req_duration.filter((metric) => metric.tags.group === 'racing');
// Calculate average response time, rate of response time < 6s, error rate, and request/sec for each stage
console.log(`Stage 1 - Football: Avg RT: ${average(footballResponseTimes)}, Rate < 6s: ${rateBelowThreshold(footballResponseTimes, 6000)}, Error Rate: ${errorRate(data.metrics.http_req_failed, 404, 500)}, Req/Sec: ${requestsPerSecond(data)}`);
// Repeat for other stages and categories
}
function average(values) {
// Calculate average of an array of values
return values.reduce((sum, value) => sum + value.value, 0) / values.length;
}
function rateBelowThreshold(values, threshold) {
// Calculate the rate of values below a threshold
return values.filter((value) => value.value < threshold).length / values.length;
}
function errorRate(failures, ...statusCodes) {
// Calculate error rate for specified status codes
const errorCount = failures.filter((failure) => statusCodes.includes(failure.tags.status)).length;
return errorCount / failures.length;
}
function requestsPerSecond(data) {
// Calculate requests per second
return data.metrics.http_reqs.rate;
}
This is a basic template to get you started. You may need to adapt it based on your specific service queries and requirements. Feel free to ask if you have more questions!