Skip to content

Commit e386570

Browse files
committed
WIP: Run E2E against Grafana Cloud
1 parent 887c2cb commit e386570

File tree

4 files changed

+140
-8
lines changed

4 files changed

+140
-8
lines changed

.github/workflows/cloud-e2e.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Grafana Cloud E2E tests
2+
3+
on:
4+
schedule:
5+
- cron: '0 9 * * *' # Daily at 09:00 UTC
6+
7+
# TODO: test, remove later
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
# @TODO: Remove the `build` job later
22+
build:
23+
name: Build
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v5
27+
with:
28+
persist-credentials: false
29+
30+
- uses: actions/setup-go@v6
31+
with:
32+
go-version: 'stable'
33+
34+
- name: Build backend
35+
uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b
36+
with:
37+
args: buildAll
38+
version: latest
39+
40+
- name: Install frontend dependencies
41+
run: npm ci --no-audit --fund=false
42+
43+
- name: Build frontend
44+
run: npm run build
45+
env:
46+
NODE_OPTIONS: '--max_old_space_size=4096'
47+
48+
e2e:
49+
name: Bench Tests
50+
needs: build
51+
runs-on: ubuntu-latest
52+
timeout-minutes: 60
53+
54+
permissions:
55+
contents: read
56+
id-token: write
57+
58+
steps:
59+
- uses: actions/checkout@v5
60+
with:
61+
persist-credentials: false
62+
63+
- name: Setup Node.js environment
64+
uses: actions/setup-node@v6
65+
with:
66+
node-version-file: .nvmrc
67+
cache: 'npm'
68+
69+
- name: Get secrets from Vault
70+
id: get-secrets
71+
# Only execute this action in a trusted context
72+
if: |
73+
github.event_name != 'pull_request' ||
74+
github.event.pull_request.head.repo.full_name == github.repository
75+
uses: grafana/shared-workflows/actions/get-vault-secrets@get-vault-secrets/v1.3.0
76+
with:
77+
common_secrets: |
78+
PLAYWRIGHT_GRAFANA_PASSWORD=data-sources/e2e:grafana-pw
79+
PLAYWRIGHT_GRAFANA_USERNAME=data-sources/e2e:grafana-username
80+
repo_secrets: |
81+
DS_INSTANCE_HOST=ds-instance:host
82+
DS_INSTANCE_PASSWORD=ds-instance:password
83+
DS_INSTANCE_PORT=ds-instance:port
84+
DS_INSTANCE_USERNAME=ds-instance:username
85+
export_env: false
86+
87+
- name: Install npm dependencies
88+
run: |
89+
if [ -f yarn.lock ]; then
90+
yarn install --frozen-lockfile --non-interactive
91+
else
92+
npm ci --no-audit --fund=false
93+
fi
94+
95+
- name: Install Playwright Browsers
96+
run: npx playwright install --with-deps chromium
97+
98+
- name: Run Grafana Bench tests
99+
run: |
100+
set -euo pipefail
101+
docker run \
102+
--rm \
103+
--network=host \
104+
--volume "$PWD:/tests" \
105+
us-docker.pkg.dev/grafanalabs-global/docker-grafana-bench-prod/grafana-bench-playwright:v0.6.3 test \
106+
--grafana-admin-password "${{ fromJSON(steps.get-secrets.outputs.secrets).PLAYWRIGHT_GRAFANA_PASSWORD }}" \
107+
--grafana-admin-user "${{ fromJSON(steps.get-secrets.outputs.secrets).PLAYWRIGHT_GRAFANA_USERNAME }}" \
108+
--grafana-url "https://datasourcese2e.grafana-dev.net" \
109+
--log-level debug \
110+
--pw-execute "npm run e2e" \
111+
--pw-prepare "npm ci --no-audit --fund=false; npx playwright install" \
112+
--test-env-vars 'CI=true DS_INSTANCE_HOST=${{ fromJSON(steps.get-secrets.outputs.secrets).DS_INSTANCE_HOST }} DS_INSTANCE_PASSWORD=${{ fromJSON(steps.get-secrets.outputs.secrets).DS_INSTANCE_PASSWORD }} DS_INSTANCE_PORT=${{ fromJSON(steps.get-secrets.outputs.secrets).DS_INSTANCE_PORT }} DS_INSTANCE_USERNAME=${{ fromJSON(steps.get-secrets.outputs.secrets).DS_INSTANCE_USERNAME }}' \
113+
--test-runner playwright
114+
115+
- name: Archive Playwright artifacts
116+
uses: actions/upload-artifact@v4
117+
if: ${{ !cancelled() }}
118+
with:
119+
name: playwright-report
120+
path: playwright-report/
121+
retention-days: 30

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ jobs:
1616
contents: read
1717
id-token: write
1818
with:
19-
plugin-version-suffix: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
2019
go-version: '1.24'
2120
golangci-lint-version: '2.1.6'
21+
plugin-version-suffix: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}

playwright.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { dirname } from 'path';
2+
13
import { defineConfig, devices } from '@playwright/test';
24
import type { PluginOptions } from '@grafana/plugin-e2e';
35

@@ -42,14 +44,14 @@ export default defineConfig<PluginOptions>({
4244
projects: [
4345
{
4446
name: 'auth',
45-
testDir: 'node_modules/@grafana/plugin-e2e/dist/auth',
47+
testDir: `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`,
4648
testMatch: [/.*\.js/],
4749
},
4850
{
4951
name: 'run-tests',
5052
use: {
5153
...devices['Desktop Chrome'],
52-
storageState: 'playwright/.auth/admin.json',
54+
storageState: `playwright/.auth/${process.env.GRAFANA_ADMIN_USER || 'admin'}.json`,
5355
},
5456
dependencies: ['auth'],
5557
},

tests/e2e/configEditor.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import { expect, test } from '@grafana/plugin-e2e';
22

33
const PLUGIN_UID = 'grafana-clickhouse-datasource';
4-
const CLICKHOUSE_DB_URL = Boolean(process.env.CI) ? 'clickhouse-server' : 'localhost';
4+
5+
// Determine ClickHouse DB URL based on environment
6+
function resolveClickhouseUrl(env = process.env) {
7+
const { CI, DS_INSTANCE_HOST } = env;
8+
return CI ? (DS_INSTANCE_HOST || 'clickhouse-server') : 'localhost';
9+
}
510

611
test.describe('Config Editor', () => {
712
test('invalid credentials should return an error', async ({ createDataSourceConfigPage, page }) => {
813
const configPage = await createDataSourceConfigPage({ type: PLUGIN_UID });
9-
await page.getByPlaceholder('Server address').fill(CLICKHOUSE_DB_URL);
14+
await page.getByPlaceholder('Server address').fill(resolveClickhouseUrl());
1015
await expect(configPage.saveAndTest()).not.toBeOK();
1116
});
1217

1318
test('valid credentials should display a success alert on the page', async ({ createDataSourceConfigPage, page }) => {
1419
const configPage = await createDataSourceConfigPage({ type: PLUGIN_UID });
1520

16-
await page.getByPlaceholder('Server address').fill(CLICKHOUSE_DB_URL);
17-
await page.getByPlaceholder('9000').fill('9000');
18-
await page.getByPlaceholder('default').fill('default');
21+
await page.getByPlaceholder('Server address').fill(resolveClickhouseUrl());
22+
await page.getByPlaceholder('9000').fill(process.env.DS_INSTANCE_PORT ?? '9000');
23+
await page.getByPlaceholder('default').fill(process.env.DS_INSTANCE_USERNAME ?? 'default');
24+
25+
if (process.env.DS_INSTANCE_PASSWORD) {
26+
await page.getByPlaceholder('password').fill(process.env.DS_INSTANCE_PASSWORD);
27+
}
1928

2029
await configPage.saveAndTest();
2130
await expect(configPage).toHaveAlert('success', { hasNotText: 'Datasource updated' });

0 commit comments

Comments
 (0)