Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bohandley/integration tests #27

Merged
merged 74 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
ca63d5d
update dependencies and add plugin-e2e and playwright
bohandley Feb 21, 2024
7bb3bb9
fix plugin.json for missing property
bohandley Feb 21, 2024
7fa95b1
remove unnecessary @ts-ignore
bohandley Feb 21, 2024
6eb91cb
add plugin-e2e and playwright
bohandley Feb 21, 2024
8c87d93
add docker debug file with provisioning
bohandley Feb 24, 2024
748f079
update provisioning for docker
bohandley Feb 24, 2024
2a40343
update grafana deps with actual versions
bohandley Feb 24, 2024
8c6c624
update provisioning for plugin-e2e tests
bohandley Feb 24, 2024
ba04e71
begin setting up integration tests
bohandley Feb 24, 2024
4cb61f0
update README with instructions for e2e tests
bohandley Feb 29, 2024
b7d7691
update docker debug to use grafana port that does not interfere with …
bohandley Feb 29, 2024
987f7c9
remove playwright auth dependency as not needed because we are turnin…
bohandley Feb 29, 2024
dd9b24b
add script for playwright e2e tests
bohandley Feb 29, 2024
93255e4
get playwright working and update readme
bohandley Mar 1, 2024
7f3c6d7
add first configuration test
bohandley Mar 1, 2024
d9f56b0
update config spec e2e tests
bohandley Mar 2, 2024
0141329
make tests work correctly and test correctly
bohandley Mar 5, 2024
55ff0cb
remove unused imports
bohandley Mar 6, 2024
514ecf4
clean comments
bohandley Mar 6, 2024
b7865c3
update to latest version of prom
bohandley Mar 6, 2024
e0e3cbe
add special data source provisioning file for testing config
bohandley Mar 6, 2024
6506c6f
rewrite cypress tests in playwright for query editor
bohandley Mar 6, 2024
fb73140
remove unused data import
bohandley Mar 6, 2024
3a80071
add tests for variable query editor
bohandley Mar 7, 2024
2c6f5fa
add e2e test for annotation editor
bohandley Mar 7, 2024
34b0c1d
removed unnecessary test
bohandley Mar 7, 2024
78d3108
add dashboard json for future tests
bohandley Mar 7, 2024
55264de
begin testing e2e workflow
bohandley Mar 7, 2024
4a43717
fix workflow for broken tests
bohandley Mar 7, 2024
5109b31
simplify workflow for only testing e2e tests
bohandley Mar 7, 2024
9b47674
fix docker command
bohandley Mar 7, 2024
4bd1757
checkout branch in workflow so files are available
bohandley Mar 7, 2024
3a47d70
fix provisioning error
bohandley Mar 7, 2024
7580e27
run container detached
bohandley Mar 8, 2024
4d60ae0
update docker compose versions
bohandley Mar 8, 2024
b27af6f
add node workflow
bohandley Mar 8, 2024
1441c9d
install deps
bohandley Mar 8, 2024
6dfcbb7
remove package manager for workflow
bohandley Mar 8, 2024
b8b4c57
test build
bohandley Mar 8, 2024
d36b942
fix for prometheus bug
bohandley Mar 8, 2024
ec5bc4e
add report
bohandley Mar 8, 2024
ece4d73
less flaky tests for github actions
bohandley Mar 8, 2024
6ce7ebf
confirming components are visible means less flaky tests
bohandley Mar 8, 2024
a5275b1
wait for prometheus to be up in github workflow
bohandley Mar 8, 2024
01724f4
more explicit route with response for wait for prometheus
bohandley Mar 8, 2024
d37f5d1
wait for prometheus health in grafana to be ok
bohandley Mar 8, 2024
c1d974e
check that data source has been provisioned
bohandley Mar 8, 2024
ccce54e
add time to wait for grafana w/ prometheus
bohandley Mar 8, 2024
27b4f8a
start prometheus service first
bohandley Mar 8, 2024
ed88f55
remove healthcheck test
bohandley Mar 8, 2024
685f3b1
need to build the backend
bohandley Mar 11, 2024
bf4d7fa
update data source provisioning files to be simpler
bohandley Mar 11, 2024
60cff29
add timeouts to query editor e2e tests
bohandley Mar 11, 2024
014ed0c
add timeouts to variable query editor e2e tests
bohandley Mar 11, 2024
3d3c3e3
test checking if visible
bohandley Mar 11, 2024
53cb73e
add e2e video storage
bohandley Mar 11, 2024
79b889a
use async await for setting data source
bohandley Mar 11, 2024
64e2497
retain videos on failure
bohandley Mar 11, 2024
2acd402
test with explicit navigation to explore page
bohandley Mar 11, 2024
356176b
explicitly change the data source picker
bohandley Mar 11, 2024
297860e
update checkout and setup go to use caching
bohandley Mar 12, 2024
0576175
remove reports from git
bohandley Mar 12, 2024
9412e6a
remove unnecessary code
bohandley Mar 12, 2024
b68ceb6
remove deleteDataSourceAfterTest and use toHaveAlert in config tests
bohandley Mar 12, 2024
8e3b0cd
update plugin-e2e version
bohandley Mar 12, 2024
62955e1
test with plugin-e2e auth instead of anonymous admin
bohandley Mar 12, 2024
e6cb8bf
remove await from autowaiting actions
bohandley Mar 12, 2024
6af3010
set default timeout to 10s for tests
bohandley Mar 12, 2024
673e9b8
remove unused code
bohandley Mar 12, 2024
b86b09a
try fixing caching
bohandley Mar 12, 2024
9b7df1a
fix caching
bohandley Mar 12, 2024
ef48b54
remove healthcheck because anonymous auth was removed
bohandley Mar 12, 2024
f53f785
yarn cache workflow
bohandley Mar 13, 2024
6440d59
yarn cache workflow fix
bohandley Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/e2e.yml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth updating to actions/checkout@v4, actions/setup-go@v5, and actions/setup-node@v4. The latest versions of the Go and Node actions have the most capabilities with respect to dependency caching, which can significantly speed up CI/CD.

For more info:

An important difference between the latest Go & Node actions is that the Go one enables caching by default, and the Node one does not - it requires a few lines of config.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I'm going to add this as an issue to improve CI/CD for this repo!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#28

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go caching is working! Saved 6 minutes of workflow time. I'm a little stuck on the node caching currently but it is captured in the issue.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: E2E Tests
on:
pull_request:
paths-ignore:
- 'docs/**'
push:
paths-ignore:
- 'docs/**'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go environment
uses: actions/setup-go@v4
with:
go-version: '1.21.6'
# NOT TESTING THE BACKEND YET
# - name: Test backend
# uses: magefile/mage-action@v2
# with:
# version: latest
# args: coverage
- name: Build backend
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building the backend here @itsmylife

uses: magefile/mage-action@v2
with:
version: latest
args: buildAll
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm install -g yarn && yarn install --frozen-lockfile;
- name: Build Frontend
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building the frontend here @itsmylife

run: |
yarn build;
- name: Start the docker container for E2E
run: |
docker compose -f docker-compose-debug.yaml pull
docker compose -f docker-compose-debug.yaml up -d
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this PR only tests your plugin against the latest enterprise main build. I see you have specified grafana 10.4.0 as min dep in the plugin.json. If the plugin is supposed to be compatible with all grafana versions beyond 10.4.0, I suggest you start using the e2e-versions Action. This Action will resolve a range of Grafana versions to test against so you can be sure you plugin is compatible with that entire range. It's documented here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! We still need to decide what versions we will support so I will add this to an issue to update the workflow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#29

- name: Wait for prometheus to start
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:9090/-/ready'
responseCode: 200
timeout: 20000
interval: 500
- name: Wait for grafana to start
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:3099/'
responseCode: 200
timeout: 20000
interval: 500
- name: Wait for prometheus to be configured in grafana
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:3099/api/datasources/uid/prometheus-amazon/health'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't just waiting for this url be enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean? Waiting for this response ensures that the Grafana can make a request to Prometheus and the response is a 200. This might not be necessary though, waiting for Prometheus and Grafana might be enough.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I mean if this url returns 200, it means Grafana and Prometheus are running so we can remove those steps in the workflow?

responseCode: 200
timeout: 20000
interval: 500
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run E2E tests
run: yarn test:e2e
- name: Run E2E report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Run E2E videos
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: test-results/
retention-days: 30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloading the report manually and firing it up locally is pretty time consuming. The example workflow for a backend ds plugin in this guide has a step that pushes the playwright report to a GCS bucket. It also drops a link to the report in the workflow summary, so you can browse the report directly from the PR without having to download it manually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super helpful. We will have to choose a storage location appropriate for the team that will take this repository on, so I will add this as an issue to improve the debugging experience.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super helpful. We will have to choose a storage location appropriate for the team that will take this repository on, so I will add this as an issue to improve the debugging experience.

If you use the publish-report Action, you won't be able to choose storage location. It uses Grafana's dev artifact storage bucket, and the url to the report will be:
https://storage.googleapis.com/releng-pipeline-artifacts-dev/<repo-name>/<pr-number>/<the-version-of-grafana-you're-testing-against>/

- name: Stop the docker container
if: always()
run: docker-compose -f docker-compose-debug.yaml down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ e2e-results/
# Editor
.idea

.eslintcache
.eslintcache
/test-results/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you uncomment this - there's not reason to version control you local generated reports.
Also add /playwright/.auth/

# /playwright-report/
/blob-report/
/playwright/.cache/
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Grafana data source plugin template
# Prometheus Amazon Data Source

This template is a starting point for building a Data Source Plugin for Grafana.
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.

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

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.
Read more about it here:

[https://aws.amazon.com/prometheus/](https://aws.amazon.com/prometheus/)

## Getting started

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

```bash
npm install
yarn install
```

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

```bash
npm run dev
yarn run dev
```

3. Build plugin in production mode

```bash
npm run build
yarn run build
```

4. Run the tests (using Jest)

```bash
# Runs the tests and watches for changes, requires git init first
npm run test
yarn run test

# Exits after running all the tests
npm run test:ci
yarn run test:ci
```

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

```bash
npm run server
yarn run server
```

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

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

# Starts the tests
npm run e2e
yarn run test:e2e
```

7. Run the linter

```bash
npm run lint
yarn run lint

# or

npm run lint:fix
yarn run lint:fix
```


Expand Down
33 changes: 33 additions & 0 deletions docker-compose-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.7"
services:
prometheus:
image: prom/prometheus:v2.45.0
container_name: prometheus-debug
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- 9090:9090
restart: unless-stopped
volumes:
- ./prometheus:/etc/prometheus
- prom_data:/prometheus
grafana:
image: grafana/grafana-enterprise:${GF_VERSION:-main}
container_name: grafana-prometheus-amazon-debug
ports:
- 3099:3099
restart: unless-stopped
environment:
- GF_DEFAULT_APP_MODE=development
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_BASIC_ENABLED=false
- GF_SERVER_HTTP_PORT=3099
volumes:
- ./provisioning/datasources:/etc/grafana/provisioning/datasources
- ./dist:/var/lib/grafana/plugins/prometheus-amazon
depends_on:
prometheus:
condition: service_started
volumes:
prom_data:
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.0'
version: '3.7'

services:
grafana:
Expand All @@ -12,4 +12,4 @@ services:
- 3000:3000/tcp
volumes:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this to be "3000:3000"
with quotes around and without tcp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! That docker file is not what we use to test things currently, but it comes "out of the box" with a backend plugin.

The docker compose file with all the nice things is docker-compose-debug.yaml.

- ./dist:/var/lib/grafana/plugins/prometheus-amazon-datasource
- ./provisioning:/etc/grafana/provisioning
- ./provisioning/datasources:/etc/grafana/provisioning
20 changes: 20 additions & 0 deletions e2e/annotation-editor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { test, expect } from '@grafana/plugin-e2e';
import { PromOptions } from '@grafana/prometheus';

test.describe('Prometheus annotation query editor', () => {
test('Check that the editor uses the code editor', async ({
readProvisionedDataSource,
annotationEditPage
}) => {
const ds = await readProvisionedDataSource<DataSourcePluginOptionsEditorProps<PromOptions>>({ fileName: 'datasources.yml' });

await annotationEditPage.datasource.set(ds.name);
await annotationEditPage
.getByTestIdOrAriaLabel(selectors.components.DataSource.Prometheus.queryEditor.code.queryField).focus();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I don't think I need the focus or setting the DS, because the default DS is Prometheus.


await expect(annotationEditPage
.getByTestIdOrAriaLabel(selectors.components.DataSource.Prometheus.queryEditor.code.queryField)).toBeVisible();
});
});
Loading
Loading