GitLab CI/CD k6 Load Test Performance Gate Prompt
Design a .gitlab-ci.yml stage that runs k6 load/performance tests against a review or staging environment, enforces threshold-based pass/fail gates, and surfaces results as artifacts and metrics reports in merge requests.
- Target user
- CI/CD and SRE engineers adding performance gates to deployment pipelines
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior CI/CD / SRE engineer who has added performance regression gates to real deployment pipelines using k6 and GitLab. I will provide: - The service under test and where it's deployed per-pipeline (review app URL, static staging, a `CI_ENVIRONMENT_URL`) - The critical user journeys or endpoints I care about - My current SLOs or target latencies (p95 response time, error rate, throughput) - Whether I want the gate blocking or advisory to start Your job: 1. **Author the k6 script** — a real `load-test.js` using `import http from 'k6/http'` with: - `options.scenarios` (ramping-vus or constant-arrival-rate) parameterized by env vars so I can scale load per environment, and - `options.thresholds` encoding the SLO (`http_req_duration: ['p(95)<500']`, `http_req_failed: ['rate<0.01']`) so k6 itself exits non-zero when the gate fails. 2. **Wire the CI stage** — a valid `.gitlab-ci.yml` `performance` job that: - runs the `grafana/k6` image (or installs k6), targets `$CI_ENVIRONMENT_URL` / a passed `BASE_URL`, - depends via `needs:` on the deploy/review-app job so it only runs after the environment is live, - exports `--summary-export` JSON and (optionally) the k6 web dashboard HTML as artifacts. 3. **Enforce the gate correctly** — explain that k6's non-zero exit on a breached threshold is what fails the job; do NOT swallow it with `|| true`. Show `rules:` that make the job **blocking** on the default/protected branch but `allow_failure: true` on MRs during tuning. 4. **Surface results in the MR** — attach the JSON/HTML summary as `artifacts:`, and where supported wire the browser-performance/metrics `reports:` so reviewers see the delta inline rather than digging through logs. 5. **Keep it stable** — advice on warm-up requests, VU ramp shape, running against an isolated review app (not shared staging), pinning the k6 image version, and seeding realistic test data so results aren't dominated by cold-cache noise. 6. **Failure modes** — job passes because thresholds were never defined, results skewed by an un-warmed review app, false reds from a shared/contended environment, and the gate accidentally pointing at a production URL. Output: (a) the complete `load-test.js` with scenarios + thresholds, (b) the `.gitlab-ci.yml` performance job with `needs:`, artifacts, and branch-scoped `rules:`, (c) a short guide to reading the summary and tuning thresholds, (d) a failure-mode table. Bias toward: thresholds that actually exit non-zero, isolated ephemeral environments, blocking on protected branches only after a stable baseline, and pinned tool versions.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab CI/CD cache:fallback_keys Warm-Start Tuning Prompt
Eliminate cold-cache penalties on new branches by layering cache:key:files, cache:fallback_keys, and per-path cache policies so first pipelines reuse a parent branch's cache instead of rebuilding from scratch.
-
GitLab CI/CD Package Manager Cache Keys Prompt
Design correct cache keys, fallback keys, and policies for npm/pnpm, Maven/Gradle, pip/Poetry, Go, and Bundler so dependency restores are fast, correct, and never stale across branches.
-
GitLab CI/CD Sparse-Checkout Monorepo Performance Prompt
Speed up GitLab CI clones in large monorepos with sparse-checkout, shallow depth, and partial clone — fetch only the paths a job needs without breaking builds.
-
GitLab CI/CD Publish to the Package Registry (npm, Maven, generic) Prompt
Design .gitlab-ci.yml jobs that build and publish versioned artifacts to the project or group Package Registry using CI_JOB_TOKEN auth, with proper version gating, immutability, and consumer install config.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.