Hello Support,
I am working on a performance testing dashboard for our API project, which includes several endpoints. We have created test cases and are running them using the Docker k6-Grafana image, which exposes the web dashboard. Currently, the dashboard displays a summary report for all endpoints combined.
However, in addition to the overall summary, we would like to see detailed reports broken down by each endpoint.
Could someone please advise on how to achieve this?
I have attached the current report, as well as code snippets for the test cases and the Docker YAML file.
import { check, group } from "k6";
import http from "k6/http";
import { moduleUrl, tenantId, getAccessToken } from "./ab-common.js";
import { runDataExportTests } from "./ab-data-export.js";
const configData = import.meta.resolve("../resources/config-request-create.json");
const payloadFileContent = open(configData);
export function setup() {
const url = `${moduleUrl}/v1/${tenantId}/config`;
const accessToken = getAccessToken();
if (!accessToken) {
throw new Error("Could not obtain access token");
}
return {
url,
accessToken,
payload: payloadFileContent,
};
}
export default function (data) {
const { url, accessToken, payload } = data;
const headers = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
};
let identifier;
group("Create Configuration", function () {
const res = http.post(url, payload, { headers });
check(res, {
"created or conflict": (r) => r.status === 200 || r.status === 409,
});
if (res.status === 200 || res.status === 201) {
try {
identifier = res.json().body?.identifier || res.json().identifier;
} catch (e) {
identifier = null;
}
}
if (!identifier) {
try {
identifier = JSON.parse(payload).identifier;
} catch (e) {
identifier = null;
}
}
});
if (!identifier) {
console.error("No identifier found, skipping further tests.");
return;
}
group("Read Configuration", function () {
const res = http.get(`${url}/${identifier}`, { headers });
check(res, {
"read ok": (r) => r.status === 200,
});
});
group("Update Configuration", function () {
const updatedPayload = JSON.stringify({ ...JSON.parse(payload), moduleId: "UpdatedModuleId" });
const res = http.put(`${url}/${identifier}`, updatedPayload, { headers });
check(res, {
"update ok": (r) => r.status === 200 || r.status === 201,
});
});
group("Read Section", function () {
const section = "adapter";
const res = http.get(`${url}/${identifier}/${section}`, { headers });
check(res, {
"read section ok": (r) => r.status === 200,
});
});
group("Get Configuration Data by ModuleId", function () {
const moduleId = JSON.parse(payload).moduleId;
const res = http.get(`${url}/config-data/${moduleId}`, { headers });
check(res, {
"get config-data ok": (r) => r.status === 200,
});
});
group("Get Module Config by ModuleId", function () {
const moduleId = JSON.parse(payload).moduleId;
const res = http.get(`${url}/module-config/${moduleId}`, { headers });
check(res, {
"get module-config ok": (r) => r.status === 200,
});
});
group("Delete Configuration", function () {
const res = http.del(`${url}/${identifier}`, null, { headers });
check(res, {
"delete ok": (r) => r.status === 200,
});
});
// After config tests, run data export tests
runDataExportTests();
}
import { check, group } from "k6";
import http from "k6/http";
import { moduleUrl, tenantId, getAccessToken } from "./ab-common.js";
// Dummy data for export/restore endpoints
const moduleId = "TestModule5";
const bufferItems = [
" 2A2F60DE-B6DE-480F-8060-E4553CE1605C",
"36899278-E05B-4F41-BE44-D0DD2D5EF1C5"
];
const archiveId = "40D22F4F-7B6B-457B-A770-7371E53E4D51";
export function runDataExportTests() {
const url = `${moduleUrl}/v1/${tenantId}/export`;
const accessToken = getAccessToken();
if (!accessToken) {
throw new Error("Could not obtain access token");
}
const headers = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
};
let bundleId = null;
group("Process Export Request (POST /{moduleId})", function () {
const res = http.post(`${url}/${moduleId}`, JSON.stringify(bufferItems), { headers });
check(res, {
"export process ok": (r) => r.status === 200 || r.status === 406 || r.status === 400,
});
});
group("Get Export Bundles (GET /bundles)", function () {
const res = http.get(`${url}/bundles`, { headers });
check(res, {
"get bundles ok": (r) => r.status === 200,
});
try {
const bundles = res.json().body || res.json();
if (Array.isArray(bundles) && bundles.length > 0) {
bundleId = bundles[0].identifier || bundles[0].id || null;
}
} catch (e) {
bundleId = null;
}
});
group("Delete Export Bundle (DELETE /bundles/{identifier})", function () {
if (bundleId) {
const res = http.del(`${url}/bundles/${bundleId}`, null, { headers });
check(res, {
"delete bundle ok": (r) => r.status === 200 || r.status === 400,
});
}
});
group("Restore Archive (GET /restore/{moduleId}/{archiveId})", function () {
const res = http.get(`${url}/restore/${moduleId}/${archiveId}`, { headers });
check(res, {
"restore archive ok": (r) => r.status === 200 || r.status === 404,
});
});
}
docker:
services:
k6:
image: grafana/k6
command: run /src/tests/ab-config.js --insecure-skip-tls-verify --summary-mode full
ports:
- 5665:5665
env_file:
- ./env/dev.env
volumes:
- ./src:/src
Thank you!