K6
K6 check runs the k6 load testing suite and ingests the junit exported result in a container at a specified path as defined in testResults
.
k6-junitapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: k6-junit
spec:
interval: 120
junit:
- testResults: "/tmp/"
name: k6-junit
display:
template: |
✅ {{.results.passed}} ❌ {{.results.failed}} in 🕑 {{.results.duration}}
{{ range $r := .results.suites}}
{{- if gt (conv.ToInt $r.failed) 0 }}
{{$r.name}} ✅ {{$r.passed}} ❌ {{$r.failed}} in 🕑 {{$r.duration}}
{{- end }}
{{- end }}
spec:
containers:
- name: k6
image: ghcr.io/flanksource/canary-k6:latest
command: ["/start.sh"]
Using the k6-junit utility to export JUnit results to the testResults
folder, canary-checker picks up the results and make then available display formatting and health evaluation.
start.shmkdir -p /tmp/junit-results
k6 -q run script.js
cp /tmp/*.xml /tmp/junit-results/
touch /tmp/junit-results/done
script.jsimport { check } from "k6";
import * as http from "k6/http";
import { Rate } from "k6/metrics";
import { jUnit } from "./node_modules/k6-junit/index.js";
export const errors = new Rate("errors");
export const options = {
iterations: 20,
thresholds: {
checks: ["rate<2"],
}
};
let i = 1;
export default function() {
const res = http.get(`http://jsonplaceholder.typicode.com/users/${i++}`);
const result = check(res, {
"is status 200": r => r.status === 201,
"not empty": r => Object.keys(r.json()).length > 0
});
errors.add(result ? 0 : 1);
}
export function handleSummary(data) {
return {
"/tmp/junit.xml": jUnit(data)
};
}
For a complete working example, see canary-checker-examples/k6
Field | Description | Scheme |
---|---|---|
name* | Name of the check, must be unique within the canary |
|
spec* | Pod specification | |
testResults* | Path to JUnit test results |
|
artifacts | Specify what files/folders created in the pod need to be archived | |
timeout | Timeout in minutes to wait for specified container to finish its job. Defaults to |
|
description | Description for the check |
|
display | Expression to change the formatting of the display | |
icon | Icon for overwriting default icon on the dashboard | |
labels | Labels for check | map[string]string |
metrics | Metrics to export from | |
test | Evaluate whether a check is healthy | |
transform | Transform data from a check into multiple individual checks |
Test Result Variables
See JUnit Test Results for the schema that is ingested and can be used for evaluating health or formatting the display.