Skip to content

Commit b344d4e

Browse files
authored
Merge pull request #27 from grafana/bohandley/integration-tests
Bohandley/integration tests
2 parents cb71b17 + 6440d59 commit b344d4e

20 files changed

+3009
-1532
lines changed

.github/workflows/e2e.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: E2E Tests
2+
on:
3+
pull_request:
4+
paths-ignore:
5+
- 'docs/**'
6+
push:
7+
paths-ignore:
8+
- 'docs/**'
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
12+
jobs:
13+
test:
14+
timeout-minutes: 60
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Setup Go environment
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.21.6'
23+
check-latest: true
24+
cache-dependency-path: "**/*.sum"
25+
# NOT TESTING THE BACKEND YET
26+
# - name: Test backend
27+
# uses: magefile/mage-action@v2
28+
# with:
29+
# version: latest
30+
# args: coverage
31+
- name: Build backend
32+
uses: magefile/mage-action@v2
33+
with:
34+
version: latest
35+
args: buildAll
36+
- name: Setup Node
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: 20
40+
check-latest: true
41+
cache: 'yarn'
42+
- name: Install dependencies
43+
run: npm install -g yarn && yarn install --frozen-lockfile;
44+
- name: Build Frontend
45+
run: |
46+
yarn build;
47+
- name: Start the docker container for E2E
48+
run: |
49+
docker compose -f docker-compose-debug.yaml pull
50+
docker compose -f docker-compose-debug.yaml up -d
51+
- name: Wait for prometheus to start
52+
uses: nev7n/wait_for_response@v1
53+
with:
54+
url: 'http://localhost:9090/-/ready'
55+
responseCode: 200
56+
timeout: 20000
57+
interval: 500
58+
- name: Wait for grafana to start
59+
uses: nev7n/wait_for_response@v1
60+
with:
61+
url: 'http://localhost:3099/'
62+
responseCode: 200
63+
timeout: 20000
64+
interval: 500
65+
- name: Install Playwright Browsers
66+
run: yarn playwright install --with-deps
67+
- name: Run E2E tests
68+
run: yarn test:e2e
69+
- name: Run E2E report
70+
uses: actions/upload-artifact@v3
71+
if: always()
72+
with:
73+
name: playwright-report
74+
path: playwright-report/
75+
retention-days: 30
76+
- name: Run E2E videos
77+
uses: actions/upload-artifact@v3
78+
if: always()
79+
with:
80+
name: test-results
81+
path: test-results/
82+
retention-days: 30
83+
- name: Stop the docker container
84+
if: always()
85+
run: docker-compose -f docker-compose-debug.yaml down

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ e2e-results/
3232
# Editor
3333
.idea
3434

35-
.eslintcache
35+
.eslintcache
36+
/test-results/
37+
/playwright-report/
38+
/blob-report/
39+
/playwright/.cache/
40+
/playwright/.auth/

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Grafana data source plugin template
1+
# Prometheus Amazon Data Source
22

3-
This template is a starting point for building a Data Source Plugin for Grafana.
3+
This data source plugin is is for Amazon Prometheus. It has all the features of the Grafana core Prometheus plugin with Amazon specific authentication in the configuration page.
44

5-
## What are Grafana data source plugins?
5+
Amazon Managed Service for Prometheus is a Prometheus-compatible service that monitors and provides alerts on containerized applications and infrastructure at scale.
66

7-
Grafana supports a wide range of data sources, including Prometheus, MySQL, and even Datadog. There’s a good chance you can already visualize metrics from the systems you have set up. In some cases, though, you already have an in-house metrics solution that you’d like to add to your Grafana dashboards. Grafana Data Source Plugins enables integrating such solutions with Grafana.
7+
Read more about it here:
8+
9+
[https://aws.amazon.com/prometheus/](https://aws.amazon.com/prometheus/)
810

911
## Getting started
1012

@@ -33,55 +35,55 @@ Grafana supports a wide range of data sources, including Prometheus, MySQL, and
3335
1. Install dependencies
3436

3537
```bash
36-
npm install
38+
yarn install
3739
```
3840

3941
2. Build plugin in development mode and run in watch mode
4042

4143
```bash
42-
npm run dev
44+
yarn run dev
4345
```
4446

4547
3. Build plugin in production mode
4648

4749
```bash
48-
npm run build
50+
yarn run build
4951
```
5052

5153
4. Run the tests (using Jest)
5254

5355
```bash
5456
# Runs the tests and watches for changes, requires git init first
55-
npm run test
57+
yarn run test
5658

5759
# Exits after running all the tests
58-
npm run test:ci
60+
yarn run test:ci
5961
```
6062

6163
5. Spin up a Grafana instance and run the plugin inside it (using Docker)
6264

6365
```bash
64-
npm run server
66+
yarn run server
6567
```
6668

67-
6. Run the E2E tests (using Cypress)
69+
6. Run the E2E tests (using Playwright and @grafana/plugin-e2e)
6870

6971
```bash
70-
# Spins up a Grafana instance first that we tests against
71-
npm run server
72+
# Spins up a Grafana docker instance (port 3099) with an actual Prometheus instance (port 9090)
73+
docker compose -f docker-compose-debug.yaml
7274

7375
# Starts the tests
74-
npm run e2e
76+
yarn run test:e2e
7577
```
7678

7779
7. Run the linter
7880

7981
```bash
80-
npm run lint
82+
yarn run lint
8183

8284
# or
8385

84-
npm run lint:fix
86+
yarn run lint:fix
8587
```
8688

8789

docker-compose-debug.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "3.7"
2+
services:
3+
prometheus:
4+
image: prom/prometheus:v2.45.0
5+
container_name: prometheus-debug
6+
command:
7+
- '--config.file=/etc/prometheus/prometheus.yml'
8+
ports:
9+
- 9090:9090
10+
restart: unless-stopped
11+
volumes:
12+
- ./prometheus:/etc/prometheus
13+
- prom_data:/prometheus
14+
grafana:
15+
image: grafana/grafana-enterprise:${GF_VERSION:-main}
16+
container_name: grafana-prometheus-amazon-debug
17+
ports:
18+
- 3099:3099
19+
restart: unless-stopped
20+
environment:
21+
- GF_DEFAULT_APP_MODE=development
22+
# - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
23+
# - GF_AUTH_ANONYMOUS_ENABLED=true
24+
- GF_AUTH_BASIC_ENABLED=false
25+
- GF_SERVER_HTTP_PORT=3099
26+
volumes:
27+
- ./provisioning/datasources:/etc/grafana/provisioning/datasources
28+
- ./dist:/var/lib/grafana/plugins/prometheus-amazon
29+
depends_on:
30+
prometheus:
31+
condition: service_started
32+
volumes:
33+
prom_data:

docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.0'
1+
version: '3.7'
22

33
services:
44
grafana:
@@ -12,4 +12,4 @@ services:
1212
- 3000:3000/tcp
1313
volumes:
1414
- ./dist:/var/lib/grafana/plugins/prometheus-amazon-datasource
15-
- ./provisioning:/etc/grafana/provisioning
15+
- ./provisioning/datasources:/etc/grafana/provisioning

e2e/annotation-editor.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
2+
import { selectors } from '@grafana/e2e-selectors';
3+
import { test, expect } from '@grafana/plugin-e2e';
4+
import { PromOptions } from '@grafana/prometheus';
5+
6+
test.describe('Prometheus annotation query editor', () => {
7+
test('Check that the editor uses the code editor', async ({
8+
readProvisionedDataSource,
9+
annotationEditPage,
10+
page,
11+
}) => {
12+
const ds = await readProvisionedDataSource<DataSourcePluginOptionsEditorProps<PromOptions>>({ fileName: 'datasources.yml' });
13+
14+
await page.getByTestId('data-testid Select a data source').click();
15+
16+
await page.getByTestId('data-testid Select a data source').fill(ds.name);
17+
18+
await page.getByRole('button', { name: `${ds.name} Prometheus` }).click();
19+
20+
await expect(annotationEditPage
21+
.getByTestIdOrAriaLabel(selectors.components.DataSource.Prometheus.queryEditor.code.queryField)).toBeVisible();
22+
});
23+
});

0 commit comments

Comments
 (0)