Skip to content

Commit

Permalink
Plugin E2E: Use custom data source for internal tests (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunker authored Jan 20, 2025
1 parent bc31bd9 commit 94c886f
Show file tree
Hide file tree
Showing 39 changed files with 904 additions and 1,596 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ jobs:
run: |
cd packages/plugin-e2e
docker compose pull
AWS_SECRET_ACCESS_KEY=${{secrets.AWS_SECRET_ACCESS_KEY}} AWS_ACCESS_KEY_ID=${{secrets.AWS_ACCESS_KEY_ID}} GOOGLE_JWT_FILE=${{secrets.GOOGLE_JWT_FILE}} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} docker compose up -d
ANONYMOUS_AUTH_ENABLED=false GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} docker compose up -d
- name: Wait for grafana server
uses: grafana/plugin-actions/wait-for-grafana@main
with:
url: http://localhost:3000/login

- name: Run Playwright tests
id: run-tests
run: npm run playwright:test --w @grafana/plugin-e2e
env:
GOOGLE_JWT_FILE: ${{ secrets.GOOGLE_JWT_FILE }}

- name: Publish report to GCS
if: ${{ github.repository_owner == 'grafana' && (failure() && steps.run-tests.outcome == 'failure') }}
Expand Down
44 changes: 20 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 11 additions & 20 deletions packages/plugin-e2e/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,30 @@ npm run build # used to build @grafana/plugin-e2e
npm run dev # watches for changes to files and rebuilds @grafana/plugin-e2e automatically
```

#### Running e2e tests locally
### Tests

There are two types of Playwright tests - those that require data source credentials (only available to members of the Grafana team) and those that don't.
The [tests](./tests/) folder contains a suite of Playwright tests designed to validate that the plugin-e2e APIs work as expected. These tests run continuously for every PR in the plugin-tools repository to identify potential breakages in the plugin-e2e package. Since all plugin-e2e APIs must remain compatible with Grafana 9.5 and later, the tests are executed against a matrix of Grafana versions. The test environment is configured using the docker-compose file in this workspace, which installs a set of plugins to ensure comprehensive coverage of the plugin-e2e APIs throughout the test suite.

To run the Playwright tests that don't require credentials.
To run the tests locally:

1. Start the e2e test server:
1. Start the Grafana e2e instance:

```shell
# starts the test server using the main branch of Grafana
npm run server

```

2. Run the Playwright tests

```shell
npm run playwright:test # runs all the playwright tests that don't require credentials
# if you want to test a specific version of Grafana
GRAFANA_VERSION=11.2.1 npm run server
```

To run the e2e tests that require data source credentials, you need to add a `/packages/plugin-e2e/.env` file and provide the necessary credentials (see `/packages/plugin-e2e/.env.example` to get an understanding of what variables you need to provide). You'll find all the necessary credentials in the [plugin-provisioning](https://github.com/grafana/plugin-provisioning) repo.

1. Start the e2e test server:
2. Run the tests

```shell
npm run server

npm run playwright:test # runs all the playwright
```

2. Run the Playwright integration tests
### The [Test DataSource](https://github.com/grafana/grafana-test-datasource)

```shell
npm run playwright:test:integration #runs all the playwright tests that integrates with third-party services
```
Many of the Playwright tests in the [test suite](./tests/) use a custom made data source plugin. This data source it not published to the catalog - its only purpose is to verify that the plugin-e2e APIs work as expected. If you need to change the functionality of this plugin, refer to the [plugin readme](https://github.com/grafana/grafana-test-datasource?tab=readme-ov-file#distributing-changes-in-the-plugin).

### VS Code Playwright extension

Expand Down
8 changes: 3 additions & 5 deletions packages/plugin-e2e/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ services:
grafana:
image: grafana/${GRAFANA_IMAGE:-grafana-enterprise}:${GRAFANA_VERSION:-11.4.0}
environment:
- GF_INSTALL_PLUGINS=grafana-clock-panel 2.1.3,grafana-googlesheets-datasource 1.2.4,grafana-redshift-datasource 1.13.0,marcusolsson-json-datasource 1.3.12,redis-app 2.2.1
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=grafana-test-datasource
- GF_INSTALL_PLUGINS=https://github.com/grafana/grafana-test-datasource/releases/download/v0.0.7/grafana-test-datasource-0.0.7.zip;grafana-test-datasource,grafana-clock-panel 2.1.3,marcusolsson-json-datasource 1.3.12,redis-app 2.2.1
- GF_AUTH_ANONYMOUS_ENABLED=${ANONYMOUS_AUTH_ENABLED:-true}
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_ANONYMOUS_ORG_NAME=Main Org.
- GF_AUTH_ANONYMOUS_ORG_ID=1
- GF_PANELS_ENABLE_ALPHA=true
- GOOGLE_JWT_FILE=${GOOGLE_JWT_FILE}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ports:
- 3000:3000/tcp
volumes:
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"server": "docker compose up --build",
"typecheck": "tsc --emitDeclarationOnly false --noEmit",
"test": "vitest --passWithNoTests",
"playwright:test": "npx playwright test --grep-invert @integration",
"playwright:test:integration": "npx playwright test --grep @integration",
"playwright:all": "npx playwright test"
"playwright:test": "npx playwright test"
},
"engines": {
"node": ">=18 <=22"
Expand Down
20 changes: 18 additions & 2 deletions packages/plugin-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { defineConfig, devices } from '@playwright/test';
import { PluginOptions } from './src';
import dotenv from 'dotenv';
import path from 'path';

dotenv.config();

Expand All @@ -14,12 +15,12 @@ export default defineConfig<PluginOptions>({
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
// provisioningRootDir: './packages/plugin-e2e/provisioning',
provisioningRootDir: process.env.PROVISIONING_ROOT_DIR || path.join(process.cwd(), 'provisioning'),
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',

Expand Down Expand Up @@ -75,6 +76,21 @@ export default defineConfig<PluginOptions>({
},
dependencies: ['authenticate'],
},

// Run all tests in parallel using user with admin role but with wide screen
{
name: 'admin-wide-screen',
testDir: './tests/as-admin-user',
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/admin.json',
viewport: {
width: 1920,
height: 1080,
},
},
dependencies: ['authenticate'],
},
// Run all tests in parallel using user with viewer role
{
name: 'viewer',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
apiVersion: 1


deleteRules:
- name: working_rule
- name: broken_rule

groups:
- orgId: 1
name: test_group
folder: redshift
interval: 5m
name: test-datasource
folder: testdatasource
interval: 1m
rules:
- uid: uid1
title: working_rule
- uid: ee6sapq2x30u8a
title: successful-alert
condition: C
data:
- refId: A
relativeTimeRange:
from: 600
to: 0
datasourceUid: P7DC3E4760CFAC4AH
datasourceUid: P6E498B96656A7F9B
model:
constant: 6.5
datasource:
type: grafana-redshift-datasource
uid: P7DC3E4760CFAC4AH
type: grafana-test-datasource
uid: P6E498B96656A7F9B
hide: false
intervalMs: 1000
maxDataPoints: 43200
rawSQL: select * from long_format_example
project: project-2
queryText: test
refId: A
- refId: B
relativeTimeRange:
from: 600
to: 0
datasourceUid: __expr__
model:
conditions:
Expand All @@ -57,9 +51,6 @@ groups:
refId: B
type: reduce
- refId: C
relativeTimeRange:
from: 600
to: 0
datasourceUid: __expr__
model:
conditions:
Expand All @@ -86,31 +77,28 @@ groups:
type: threshold
noDataState: NoData
execErrState: Error
for: 5m
annotations: {}
labels: {}
for: 1m
isPaused: false
- uid: uid2
title: broken_rule
condition: A
- uid: ce6say4zyst1ce
title: broken-alert
condition: C
data:
- refId: A
relativeTimeRange:
from: 600
to: 0
datasourceUid: P7DC3E4760CFAC4AH
datasourceUid: P6E498B96656A7F9B
model:
constant: 6.5
datasource:
type: grafana-redshift-datasource
uid: P7DC3E4760CFAC4AH
type: grafana-test-datasource
uid: P6E498B96656A7F9B
intervalMs: 1000
maxDataPoints: 43200
rawSQL: \!select
project: project-2
queryText: error
refId: A
- refId: B
relativeTimeRange:
from: 600
to: 0
datasourceUid: __expr__
model:
conditions:
Expand All @@ -136,9 +124,6 @@ groups:
refId: B
type: reduce
- refId: C
relativeTimeRange:
from: 600
to: 0
datasourceUid: __expr__
model:
conditions:
Expand All @@ -165,8 +150,6 @@ groups:
type: threshold
noDataState: NoData
execErrState: Error
for: 5m
annotations: {}
labels: {}
for: 1m
isPaused: false

Loading

0 comments on commit 94c886f

Please sign in to comment.