Skip to content

grafana/testing-with-grafana-cloud

testing-with-grafana-cloud

Dreaming of using Grafana Cloud for all your testing needs? This repository will help you get started.

Note: The demo app used for all examples is QuickPizza.

What you'll find here:

  • src/
    • backend/ – k6 tests for backend APIs
    • web_app/ – k6 tests for frontend
    • _lib/http_client.ts – client autogenerated using openapi-to-k6
    • _studio/k6 studio artifacts
      • data/ – reusable datasets (e.g. users.json)
      • generators/ – test generators
      • recordings/ – recordings of different user flows (HTTP)
  • specs/
    • quickpizza.openapi.yaml – OpenAPI spec for QuickPizza
  • terraform/
  • k8s/
    • plz.definition.yaml – GCk6 PLZ test definition
    • plz.quota.yaml – GCk6 PLZ quota config
  • .github/workflows/
    • ci.yaml – runs on every push to main
      • spins up a local QuickPizza container
      • runs backend tests locally with run-k6-action
      • annotates test runs with branch/PR metadata
    • release.yaml – runs on new GitHub Releases
      • runs backend tests in GCk6 with run-k6-action (targeting a public QuickPizza deployment)
      • annotates runs with release metadata
      • sets the runs as baselines in GCk6
  • extensions/
    • Dockerfile – Dockerfile to build a custom image with k6 extensions
    • xk6-judge/ – custom k6 extension

How to apply the Terraform resources to your Grafana Cloud stack

Make sure you have the following prerequisites installed:

  • Node (>= 22.x)
  • Terraform (>= 1.3.0)
  • A Grafana Cloud account with an existing stack

After cloning the repository create a .env file based on the .env.example file.

cp .env.example .env

Then, edit the .env file and add a Grafana Cloud API Key and the details of your stack.

STACK_SLUG=mystack
CLOUD_REGION=prod-eu-west-2
CLOUD_ACCESS_POLICY_TOKEN=abdc123

That's it! Now run the following command to create the resources in your Grafana Cloud Stack.

make tf-bootstrap

Once you are done, you can check your Grafana Cloud stack to see the new resources.

If you want to clean up and remove all the resources created, just run:

make tf-destroy

Where to find the Stack Slug and Cloud Region?

  1. Log in to your Grafana Cloud account.
  2. Select your organization from the organization drop-down menu.
  3. In the Stacks section, click Details next to the stack you want to use.
  4. Copy the Slug and the Region.

How do I create a Grafana Cloud API key?
With a Grafana Cloud Access Policy. Make sure that you configure the minimun required scopes:

  • stacks:read
  • stacks:write
  • subscriptions:read
  • orgs:read
  • stack-service-accounts:write

How to regenerate the client after updating the OpenAPI spec

Just run:

make gen-openapi-client

How to work with k6 Studio artifacts

You can sync them between your local Studio installation and this repository using:

# Copy artifacts from the repo to your local Studio install
make studio-update-local

# Copy artifacts from your local Studio install to the repo
make studio-update-repo

Only generators, recordings and data files will be synced.

The commands are non-destructive, meaning they will only add or update files, never delete them.