1. Dans la CI #
Chaque version passe son test de performance.
GitHub Actions #
# .github/workflows/perf.yml
name: perf
on: [pull_request]
jobs:
k6:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Démarrer l'application
run: docker compose up -d && sleep 10
- uses: grafana/setup-k6-action@v1
- uses: grafana/run-k6-action@v1
with:
path: tests/perf/smoke.jsLes seuils non respectés font échouer l'étape (code 99) : la pull request est bloquée.
GitLab CI #
perf:
image: { name: grafana/k6:latest, entrypoint: [""] }
script:
- k6 run --summary-export=resume.json tests/perf/smoke.js
artifacts:
paths: [resume.json]Bonne Pratique : En CI, privilégiez un test smoke court à chaque pull request et un test de charge complet chaque nuit sur un environnement dédié : un test de charge sur un runner partagé mesure surtout le runner.
2. Tests distribués avec k6-operator #
Plus de charge qu'une machine.
Principe #
k6-operator exécute un test sur plusieurs pods Kubernetes en parallèle, chacun prenant une partie de la charge (execution segments).
helm repo add grafana https://grafana.github.io/helm-charts
helm install k6-operator grafana/k6-operator -n k6-operator --create-namespace
kubectl create configmap test-charge --from-file=charge.jsapiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
name: charge-boutique
spec:
parallelism: 4 # 4 pods se partagent la charge
script:
configMap:
name: test-charge
file: charge.js
arguments: -o experimental-prometheus-rw --tag testid=nightly
runner:
env:
- name: K6_PROMETHEUS_RW_SERVER_URL
value: http://prometheus.monitoring.svc:9090/api/v1/writekubectl apply -f testrun.yaml
kubectl get testrun charge-boutique -w
kubectl logs -l k6_cr=charge-boutique --tail=20