k6 Performance Pipeline
A CI-integrated performance testing pipeline using k6, TypeScript, and Grafana that runs synthetic load tests, validates SLOs, and publishes dashboards on every deployment.
5
Test types
Real-time
SLO validation
Automated
CI integration
About
The k6 Performance Pipeline automates performance testing as part of the CI/CD process. It uses k6 with TypeScript for scriptable load tests, runs them in Docker containers via GitHub Actions, validates SLO thresholds, and publishes results to Grafana dashboards. The pipeline supports smoke, load, stress, soak, and spike test types.
Problem
Performance testing is often an afterthought, done manually before releases. Teams discover regressions too late. This pipeline makes performance testing a first-class CI citizen with automated gates.
Architecture
The pipeline runs entirely in Docker containers orchestrated by Docker Compose. A GitHub Actions workflow spins up the target application, k6 containers, and the monitoring stack (Prometheus + Grafana). k6 executes TypeScript test scripts, writes results to Prometheus, and validates SLOs programmatically. Grafana provides real-time dashboards. The pipeline reports pass/fail status back to the PR.
Pipeline
K6_PERFORMANCE_PIPELINE_PIPELINE
Workflow
Code
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate, Trend } from 'k6/metrics';
const errorRate = new Rate('errors');
const responseTime = new Trend('response_time');
export const options = {
stages: [
{ duration: '2m', target: 50 },
{ duration: '5m', target: 50 },
{ duration: '2m', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<500'],
errors: ['rate<0.05'],
},
};
export default function () {
const res = http.get('http://app/health');
const passed = check(res, {
'status is 200': r => r.status === 200,
'response < 300ms': r => r.timings.duration < 300,
});
errorRate.add(!passed);
responseTime.add(res.timings.duration);
sleep(1);
}name: Performance Tests
on: [deployment_status]
jobs:
perf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker compose up -d
- name: Run k6 smoke
run: |
docker compose run k6 run \
--out prometheus \
scripts/smoke.ts
- name: Run k6 load
run: |
docker compose run k6 run \
--out prometheus \
scripts/load.ts
- name: Validate SLOs
run: python scripts/validate_slos.py
- name: Publish dashboards
uses: grafana/grafana-composite-action@v1
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const report = require('./report.json')
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: generatePerfComment(report),
})Quick start
Current functionality
- TypeScript k6 scripts with type safety
- Smoke, load, stress, soak, spike test types
- SLO validation with configurable thresholds
- Grafana dashboards per deployment
- Prometheus metrics for historical analysis
- GitHub Actions CI integration
- PR comment with performance summary
- Docker Compose local development
Limitations
- Requires Docker infrastructure
- k6 is single-threaded per instance
- Distributed load testing needs additional setup
- Grafana dashboards need manual configuration
Planned improvements
- Add distributed k6 for higher load
- Add browser-level performance metrics
- Integrate with Slack for threshold alerts
- Add performance budget tracking over time
Technology
Related capabilities
Status
experimentalThis project is an active experimental framework. It is not production-ready and should be evaluated for your specific use case.
Interested in this project?
Stagbyte builds practical automation systems. If this project aligns with a problem you are solving, reach out to discuss how it can be adapted or extended.