Files
grafana/playwright.config.ts
Josh Hunt 23c6c1e50b CI: Speed up Playwright e2e tests workflow (#119277)
* CI: Replace Dagger builds with native make for Playwright e2e tests

Switch from Dagger-based builds to native Go/JS builds for the
Playwright e2e test pipeline. Grafana now runs as a native binary
on the CI runner instead of in a Docker container.

Key changes:
- build-backend: actions/setup-go + make build-go (instead of Dagger)
- build-frontend: actions/setup-node + make build-js + yarn e2e:plugin:build
- run-playwright-tests: downloads artifacts, uses start-server script
  to run Grafana natively (instead of Docker container from GHCR)
- build-grafana: standalone full Dagger build, off the Playwright
  critical path (still produces Docker/tarball for push-docker-image
  and run-a11y-test)
- required-playwright-tests: no longer depends on build-grafana
- Remove debug env vars (ACTIONS_STEP_DEBUG, RUNNER_DEBUG)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Fix zizmor template-injection: use docker/login-action for GHCR login in Playwright job

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Replace GHA service container with docker run for Grafana

GHA service containers start before any step (including checkout), so
volume-mounted config files don't exist yet and Grafana crashes. The
health check never passes, blocking all steps from running.

Switch to docker run -d in a step after checkout, so all files are
available when the container starts. This eliminates the need for the
docker restart workaround and the zizmor unpinned-images suppression.

Verified locally: built all three Dagger steps (backend, frontend,
assembly with --import-dir + chmod +x), loaded the Docker image, and
confirmed Grafana starts successfully with volume-mounted config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Fix Docker image binary permissions lost by actions/upload-artifact

actions/upload-artifact strips execute permissions (all files become 644).
The backend binaries need +x restored before Dagger packages them into the
Docker image, otherwise the container fails with "Permission denied" when
trying to exec the grafana binary.

Verified locally: pulled the CI-built image from GHCR, confirmed binaries
had 664 permissions, added chmod +x, and tested the full service container
restart flow successfully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Fix CI failures: pin docker/login-action, fix docker tarball glob, suppress zizmor unpinned-images

- Pin docker/login-action@v3 to hash @5e57cd118135c172c3672efd75eb46360885c0ef
- Use glob *.docker.tar.gz in push-docker-image (Dagger produces versioned filenames)
- Add unpinned-images ignore for pr-e2e-tests.yml (dynamic build output image)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

CI: Fix missing bundled-plugins directory in build-grafana

actions/upload-artifact skips empty directories, so the bundled-plugins
dir (empty in OSS builds) doesn't exist after download. Create it before
running Dagger to prevent the --import-dir from failing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

CI: Speed up Playwright e2e tests workflow

Split the monolithic Grafana build into three Dagger jobs (backend, frontend, assembly) with granular caching. Use the --import-dir flag to pre-populate the artifact store, skipping compilation in the assembly step. Run Playwright shards in parallel with 4 workers instead of 1, reduced from 8 to 6 shards, and use GHA service containers with bind-mounted config instead of building custom e2e Docker images. Add workflow concurrency, job timeouts, and dependency caching. This reduces critical path from ~32 minutes to ~17 minutes on cold builds and ~9 minutes with warm caches.

Expected impact:
- Parallel backend/frontend builds save 6-8 minutes (vs sequential)
- GHA output cache hits reduce builds to 0 seconds on cache hit
- Docker service container approach eliminates per-shard overhead (5-7 min saved)
- 4 workers per shard and reduced retry count improve test throughput
- Workflow concurrency prevents wasted runs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

try merging frontend artifact

run the tests

shard tree artifact, delete artifacts, fix ts files being excluded

copy bin

fix path

fix path

fix script

another try

fix incorrect permissions

* try stitching together standalone grafana build

* include more dirs in frontend build

fix paths

* try caching node-modules better

try caching node-modules

disable YARN_ENABLE_HARDENED_MODE

temporarily stop caching node_modules to test performance

temp don't cache node_modules to measure perf

fix frontend cache

* add script for downloading the report and viewing it locally

* Update codeowners

* Add workflow to build grafana docker image

* add placeholder check

* Use hosted runners for everything

* Bump actions versions

* Don't cache playwright browser installs

* build e2e test plugins in each shard

* Split bench report into seperate step

and update bench to v1

* try packaging less of the public dir

* Package up whole public directory

its needed for some reason

* Run the grafana server migrations in the background while playwright installs

* Fix flaky time picker preferences tests

* Fix detect-changes always running e2e tests

* Skip building frontend source maps

* Don't check out repo in report steps

* Add per-shard failure instructions
2026-03-05 12:54:49 +00:00

216 lines
6.2 KiB
TypeScript

import { defineConfig, devices, PlaywrightTestConfig, Project } from '@playwright/test';
import path, { dirname } from 'path';
import { PluginOptions } from '@grafana/plugin-e2e';
export const testDirRoot = 'e2e-playwright';
const pluginDirRoot = path.join(testDirRoot, 'plugin-e2e');
export const DEFAULT_URL = 'http://localhost:3001';
export function withAuth(project: Project): Project {
project.dependencies ??= [];
project.use ??= {};
project.dependencies = project.dependencies.concat('authenticate');
project.use = {
...project.use,
storageState: `playwright/.auth/${process.env.GRAFANA_ADMIN_USER || 'admin'}.json`,
};
return project;
}
export const baseConfig: PlaywrightTestConfig<PluginOptions, {}> = {
fullyParallel: true,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 4 : undefined,
reporter: [
['html'], // pretty
['./e2e-playwright/utils/axe-a11y/reporter.ts'], // accessibility reporter
],
expect: {
timeout: 10_000,
},
use: {
...devices['Desktop Chrome'],
baseURL: process.env.GRAFANA_URL ?? DEFAULT_URL,
trace: 'retain-on-failure',
httpCredentials: {
username: 'admin',
password: 'admin',
},
screenshot: 'only-on-failure',
permissions: ['clipboard-read', 'clipboard-write'],
provisioningRootDir: path.join(process.cwd(), process.env.PROV_DIR ?? 'conf/provisioning'),
},
};
export default defineConfig<PluginOptions>({
...baseConfig,
...(!process.env.GRAFANA_URL && {
webServer: {
command: 'yarn e2e:plugin:build && ./e2e-playwright/start-server',
url: DEFAULT_URL,
stdout: 'pipe',
stderr: 'pipe',
},
}),
projects: [
// Login to Grafana with admin user and store the cookie on disk for use in other tests
{
name: 'authenticate',
testDir: `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`,
testMatch: [/.*\.js/],
},
// Login to Grafana with new user with viewer role and store the cookie on disk for use in other tests
{
name: 'createUserAndAuthenticate',
testDir: `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`,
testMatch: [/.*\.js/],
use: {
user: {
user: 'viewer',
password: 'password',
role: 'Viewer',
},
},
},
// Run all tests in parallel using user with admin role
withAuth({
name: 'admin',
testDir: path.join(pluginDirRoot, '/plugin-e2e-api-tests/as-admin-user'),
}),
// Run all tests in parallel using user with viewer role
{
name: 'viewer',
testDir: path.join(pluginDirRoot, '/plugin-e2e-api-tests/as-viewer-user'),
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/viewer.json',
},
dependencies: ['createUserAndAuthenticate'],
},
withAuth({
name: 'elasticsearch',
testDir: path.join(pluginDirRoot, '/elasticsearch'),
}),
withAuth({
name: 'mysql',
testDir: path.join(pluginDirRoot, '/mysql'),
}),
withAuth({
name: 'mssql',
testDir: path.join(pluginDirRoot, '/mssql'),
}),
withAuth({
name: 'extensions-test-app',
testDir: path.join(testDirRoot, '/test-plugins/grafana-extensionstest-app'),
}),
withAuth({
name: 'grafana-e2etest-datasource',
testDir: path.join(testDirRoot, '/test-plugins/grafana-test-datasource'),
}),
withAuth({
name: 'cloudwatch',
testDir: path.join(pluginDirRoot, '/cloudwatch'),
}),
withAuth({
name: 'azuremonitor',
testDir: path.join(pluginDirRoot, '/azuremonitor'),
}),
withAuth({
name: 'cloudmonitoring',
testDir: path.join(pluginDirRoot, '/cloudmonitoring'),
}),
withAuth({
name: 'graphite',
testDir: path.join(pluginDirRoot, '/graphite'),
}),
withAuth({
name: 'influxdb',
testDir: path.join(pluginDirRoot, '/influxdb'),
}),
withAuth({
name: 'opentsdb',
testDir: path.join(pluginDirRoot, '/opentsdb'),
}),
withAuth({
name: 'jaeger',
testDir: path.join(pluginDirRoot, '/jaeger'),
}),
withAuth({
name: 'grafana-postgresql-datasource',
testDir: path.join(pluginDirRoot, '/grafana-postgresql-datasource'),
}),
withAuth({
name: 'canvas',
testDir: path.join(testDirRoot, '/canvas'),
}),
withAuth({
name: 'zipkin',
testDir: path.join(pluginDirRoot, '/zipkin'),
}),
{
name: 'unauthenticated',
testDir: path.join(testDirRoot, '/unauthenticated'),
},
withAuth({
name: 'various',
testDir: path.join(testDirRoot, '/various-suite'),
}),
withAuth({
name: 'panels',
testDir: path.join(testDirRoot, '/panels-suite'),
}),
withAuth({
name: 'smoke',
testDir: path.join(testDirRoot, '/smoke-tests-suite'),
}),
withAuth({
name: 'dashboards',
testDir: path.join(testDirRoot, '/dashboards-suite'),
}),
withAuth({
name: 'loki',
testDir: path.join(testDirRoot, '/loki'),
}),
withAuth({
name: 'cloud-plugins',
testDir: path.join(testDirRoot, '/cloud-plugins-suite'),
}),
withAuth({
name: 'alerting',
testDir: path.join(testDirRoot, '/alerting-suite'),
}),
withAuth({
name: 'dashboard-new-layouts',
testDir: path.join(testDirRoot, '/dashboard-new-layouts'),
}),
// Setup project for dashboard CUJS tests
withAuth({
name: 'dashboard-cujs-setup',
testDir: path.join(testDirRoot, '/dashboard-cujs'),
testMatch: ['global-setup.spec.ts'],
}),
// Main dashboard CUJS tests
withAuth({
name: 'dashboard-cujs',
testDir: path.join(testDirRoot, '/dashboard-cujs'),
testIgnore: ['global-setup.spec.ts', 'global-teardown.spec.ts'],
dependencies: ['dashboard-cujs-setup'],
}),
// Teardown project for dashboard CUJS tests
withAuth({
name: 'dashboard-cujs-teardown',
testDir: path.join(testDirRoot, '/dashboard-cujs'),
testMatch: ['global-teardown.spec.ts'],
dependencies: ['dashboard-cujs'],
}),
withAuth({
name: 'grafana-e2etest-panel',
testDir: path.join(testDirRoot, '/test-plugins/grafana-test-panel'),
}),
],
});