Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Shift Left with Reliability Testing: A Hands-on...

Shift Left with Reliability Testing: A Hands-on Introduction to k6

Shift Left with Reliability Testing: A Hands-on Introduction to k6 delivered at Cloud Native Days Norway 2026

Avatar for immavalls

immavalls

October 19, 2026

More Decks by immavalls

Other Decks in Technology

Transcript

  1. Shift left with Reliability Testing A hands-on introduction to k6

    Imma Valls Developer Advocate, Grafana Labs Tom Donohue Field Engineer, Grafana Labs
  2. Today's agenda Introduction Lab 4 - Assertions and CI/CD Lab

    1 - Setup Lab 5 - Infrastructure load test Lab 2 - Basic load test Lab 6 - Scale with the k6 Operator Lab 3 - Workload in rps k6 AI and wrap-up Introduction to reliability testing and k6 Setup your environment for the labs Run a simple k6 test Choosing the right model for your test Choosing the right model for your test Load test a DB and correlate your infrastructure tests Move to a distributed test on Kubernetes Demo, take-home exercises and Q&A
  3. Introduction to k6 What is k6? • • Cross-platform binary

    (runs on your machine and in CI import http from 'k6/http' Command-Line interface CLI export default function () { script.js http.get('https: • You write tests in JavaScript } • Supports modern protocols HTTP, WebSocket, gRPC $ k6 run script.js • Extensible using plugins (xk6) quickpizza.grafana.com')
  4. k6 Testing Capabilities Types of performance tests Smoke Load Stress

    Spike Does it work at minimal load? Holding at expected traffic level Where does it break? Does it survive a surge? Verifies system functionality under tiny traffic before running heavier tests. Assesses performance under normal and peak concurrent user activity. Pushes beyond normal limits to find breaking points and maximum capacity. Tests response and recovery during sudden, extreme traffic bursts. Minimal load Expected traffic Maximum capacity https://grafana.com/load-testing/types-of-load-testing Sudden surge
  5. Lab 1 - Setup Today’s lab architecture OBSERVABILITY Prometheus HTTP

    QuickPizza :3333 OTLP Loki Alloy Tempo Pyroscope SQL Postgres :5432 Grafana
  6. Lab 1 - Setup Setup checklist Docker and Docker compose

    are running Stuck? Let us know! (optional) k6 installed (k6 version) Cloned the workshop repo (github.com/immavalls/cnd-norway-2026-k6-workshop) Compose stack is up k3d or kind and kubectl installed (for later labs)
  7. Lab 2 - Basic load test How k6 defines a

    test Virtual Users (VUs) Iteration Duration How many users are simulated One single run of the main function How long the test runs VU1 -> login -> request func() { Run test for 1 minute VU2 -> login -> request doSomething() VU3 -> login -> request doSomethingElse() ... doAFinalThing() }
  8. Lab 2 - Basic load test Anatomy of a k6

    test script Modules Test options Main function
  9. Lab 2 - Basic load test Running your first test

    Execution mode Live progress Scenarios
  10. Lab 2 - Basic load test Understanding the test output

    HTTP metrics Execution metrics Network metrics
  11. Lab 3 - Workload in rps Choosing the right model

    Steady stream "Open model" 100 rps 70 rps Response time Iteration arrival rate Iteration arrival rate Fixed virtual users "Closed model" 100 rps Response time
  12. Lab 4 - Assertions and CI/CD Defining pass/fail criteria Thresholds

    A rule that's evaluated against the whole run export let options = { thresholds: { http_req_duration: ["p(95) Performs an assertion on each response Doesn't stop the test fails the test run }}; export default function () { const res = http.get("https: Checks 200"], quickpizza.com"); check(res, { 'status is 200': (r) } r.status 200 });
  13. Lab 4 - Assertions and CI/CD Failing a build if

    a test fails on: pull_request jobs: load-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: docker compose up -d /-wait - uses: grafana/setup-k6-action@v1 # exits non-zero if a threshold fails - run: k6 run loadtest.js
  14. Lab 4 - Assertions and CI/CD Failing a build if

    a test fails - GitLab edition performance-test: image: name: grafana/k6:latest entrypoint: [''] stage: test script: - k6 run -e BASE_URL=https://staging.example.com tests/performance/test.js
  15. Lab 4 - Assertions and CI/CD 📚 /docs/k6/latest/extensions/explore/ k6 is

    extensible Protocols Outputs Use cases • •HTTP • •Browser testing • •InfluxDB • •Websocket • •Infrastructure testing • •Prometheus • •SQL / NoSQL • •Chaos testing • •TimescaleDB • •AMQP / Kafka • …. • •Grafana Cloud • •Crypto • •NewRelic • •Redis • •Dynatrace • …. • …. JAVASCRIPT RUNTIME xk6 EXTENSIONS GOLANG
  16. Lab 5 - Infrastructure testing Load testing the database with

    k6/x/sql TODO: SAY SOMETHING ABOUT CORRELATING REMOTE WRITE INFRA METRICS Prometheus TCP Postgres :5432 Alloy Grafana
  17. Lab 6 - Scale with the k6 Operator Scaling testing

    beyond your laptop YOUR LAPTOP K6 OPERATOR CLUSTER App App SAME SCRIPT, LOAD SHARED ACROSS JOBS
  18. Lab 6 - Scale with the k6 Operator Defining a

    TestRun with the k6 Operator apiVersion: k6.io/v1alpha1 kind: TestRun metadata: name: pizza-please spec: parallelism: 4 script: configMap: name: my-test script: test.js kubectl create configmap \ my-test \ --from-file /path/to/test.js
  19. Lab 6 - Scale with the k6 Operator Run a

    distributed test Create or access a k8s cluster Install the k6 Operator Apply the TestRun Watch the runner pods See the results in Grafana
  20. k6 AI and wrap-up AI as a first-class feature Ships

    agent integration, skills, and configuration for your AI workflow of choice k6 x agent k6 x mcp k6 x docs Brings MCP server to k6, agents can run k6 and interpret results natively. Programmatic access to k6 documentation via CLI.
  21. k6 AI and wrap-up A roadmap to shift-left testing with

    k6 Test one thing Run it on every change Observe and scale it
  22. Workshop wrap-up Thank you for attending! Have more questions? Join

    us at community.grafana.com or Grafana public slack grafana.slack.com #grafana /grafana community.grafana.com