Turning data into understandable insights with K6 load testing

K6 Dashboard by K6.io

K6 makes performance testing easy with Prometheus and Grafana in Docker.

import http from 'k6/http';
import { describe } from 'https://jslib.k6.io/expect/0.0.4/index.js';
import { check, sleep } from 'k6';
export default function () {
describe('Basic k6 test', () => {
let res = http.get('https://test.k6.io');
check(res, {
'is status 200': (r) => r.status === 200
});
sleep(1);
});
}
FROM golang:1.17-alpine as builder
WORKDIR "$GOPATH"/src/go.k6.io/k6
COPY . .
RUN apk --no-cache add git &&\
go install -trimpath go.k6.io/xk6/cmd/xk6@latest &&\
xk6 build --with github.com/grafana/xk6-output-prometheus-remote@latest &&\
cp k6 "$GOPATH"/bin/k6
FROM alpine:3.13
RUN apk add --no-cache ca-certificates && \
adduser -D -u 12345 -g 12345 k6
COPY --from=builder /go/bin/k6 /usr/bin/k6
USER 12345
ENTRYPOINT ["k6"]
CMD [""]
version: '3.7'volumes:
prometheus-data:
grafana-data-storage:
services:
k6-prom:
build: .
depends_on:
- grafana
volumes:
- .:/app:delegated
environment:
- K6_PROMETHEUS_REMOTE_URL=http://prometheus:9090/api/v1/write
command: run --vus 150 --duration 30s -o output-prometheus-remote /app/tests/basic_k6_test.js
prometheus:
image: prom/prometheus:latest
depends_on:
- grafana
ports:
- 9000:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus
command: --enable-feature=remote-write-receiver --config.file=/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana:latest
volumes:
- grafana-data-storage:/var/lib/grafana
ports:
- 4000:4000
environment:
- GF_SERVER_HTTP_PORT=4000
global:
scrape_interval: 30s
scrape_timeout: 10s
scrape_configs:
- job_name: services
metrics_path: /metrics
static_configs:
- targets:
- 'prometheus:9090'
docker-compose up
Prometheus data source
Adding prometheus as http://prometheus:9090 URL
K6 data representation
K6 data representation

Senior QA Automation Engineer and tech enthusiast