From 4fa02099aa065dd988fb4a5f2793f543380fcb87 Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Wed, 23 Oct 2024 14:10:35 +0100 Subject: [PATCH 1/5] Add Grafana Bench action --- .github/workflows/grafana-bench.yml | 65 +++++++++++++++++++++++++++++ package.json | 1 + playwright.config.ts | 13 +++++- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/grafana-bench.yml diff --git a/.github/workflows/grafana-bench.yml b/.github/workflows/grafana-bench.yml new file mode 100644 index 00000000..04b0ed0a --- /dev/null +++ b/.github/workflows/grafana-bench.yml @@ -0,0 +1,65 @@ +name: Grafana Bench +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'yarn' + + - uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Build backend + uses: magefile/mage-action@v3 + with: + args: buildAll + version: latest + + - name: Install frontend dependencies + run: yarn install --frozen-lockfile + + - name: Build frontend + run: yarn build + env: + NODE_OPTIONS: '--max_old_space_size=4096' + + - name: Install and run Docker Compose + uses: hoverkraft-tech/compose-action@v2.0.2 + with: + compose-file: './docker-compose.yml' + + - name: Wait for Grafana to start + uses: nev7n/wait_for_response@v1 + with: + url: 'http://localhost:3000/' + responseCode: 200 + timeout: 60000 + interval: 500 + + - name: Run Grafana Bench tests + run: | + docker run --rm \ + --network=host \ + --volume="./:/home/bench/tests/" \ + ghcr.io/grafana/grafana-bench:v0.2.4 test \ + --test-suite-base "/home/bench/tests/" \ + --grafana-url "http://localhost:3000" \ + --grafana-username "admin" \ + --grafana-password "admin" \ + --test-runner "playwright" \ + --pw-prepare-cmd "yarn e2e:prepare" \ + --pw-execute-cmd "yarn e2e" \ + --log-level DEBUG + diff --git a/package.json b/package.json index f2693435..2da714e9 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", "dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", + "e2e:prepare": "yarn install --frozen-lockfile && yarn playwright install --with-deps", "e2e:report": "yarn playwright show-report", "e2e:ui": "yarn playwright test --ui", "e2e": "playwright test", diff --git a/playwright.config.ts b/playwright.config.ts index 2b3b068a..73e85542 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -26,12 +26,21 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: `http://localhost:${process.env.PORT || 3000}`, + baseURL: process.env.GRAFANA_URL || `http://localhost:${process.env.PORT || 3000}`, + + grafanaAPICredentials: { + user: process.env.GRAFANA_USER || 'admin', + password: process.env.GRAFANA_PASSWORD || 'admin', + }, + + launchOptions: { + executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, + }, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', screenshot: 'only-on-failure', - video: 'on' + video: 'on', }, /* Configure projects for major browsers */ From ed20575a6ceedf7a40681e572d5d4d000b97b655 Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Mon, 28 Oct 2024 14:29:04 +0000 Subject: [PATCH 2/5] Use grafana-bench:v0.3.0-rc3 --- .github/workflows/grafana-bench.yml | 17 +++++++++-------- package.json | 2 +- playwright.config.ts | 5 ----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/grafana-bench.yml b/.github/workflows/grafana-bench.yml index 04b0ed0a..d065cdbe 100644 --- a/.github/workflows/grafana-bench.yml +++ b/.github/workflows/grafana-bench.yml @@ -52,14 +52,15 @@ jobs: run: | docker run --rm \ --network=host \ - --volume="./:/home/bench/tests/" \ - ghcr.io/grafana/grafana-bench:v0.2.4 test \ - --test-suite-base "/home/bench/tests/" \ + --volume="./:/home/bench/tests/" \ + us-docker.pkg.dev/grafanalabs-global/docker-grafana-bench-prod/grafana-bench:v0.3.0-rc3 test \ + --grafana-admin-password "admin" \ + --grafana-admin-user "admin" \ --grafana-url "http://localhost:3000" \ - --grafana-username "admin" \ - --grafana-password "admin" \ - --test-runner "playwright" \ - --pw-prepare-cmd "yarn e2e:prepare" \ + --log-level DEBUG \ --pw-execute-cmd "yarn e2e" \ - --log-level DEBUG + --pw-prepare-cmd "yarn e2e:prepare" \ + --test-env-vars "CI=true" \ + --test-runner "playwright" \ + --test-suite-base "/home/bench/tests/" diff --git a/package.json b/package.json index 2da714e9..7e49ee53 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", "dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", - "e2e:prepare": "yarn install --frozen-lockfile && yarn playwright install --with-deps", + "e2e:prepare": "yarn install --frozen-lockfile && yarn playwright install", "e2e:report": "yarn playwright show-report", "e2e:ui": "yarn playwright test --ui", "e2e": "playwright test", diff --git a/playwright.config.ts b/playwright.config.ts index 73e85542..cf458f03 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -28,11 +28,6 @@ export default defineConfig({ /* Base URL to use in actions like `await page.goto('/')`. */ baseURL: process.env.GRAFANA_URL || `http://localhost:${process.env.PORT || 3000}`, - grafanaAPICredentials: { - user: process.env.GRAFANA_USER || 'admin', - password: process.env.GRAFANA_PASSWORD || 'admin', - }, - launchOptions: { executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, }, From 2f199bcb5130dd58c97153dc30b15beb098f824f Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Tue, 29 Oct 2024 14:41:00 +0000 Subject: [PATCH 3/5] Only run on push to the main branch --- .github/workflows/grafana-bench.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/grafana-bench.yml b/.github/workflows/grafana-bench.yml index d065cdbe..0a8f00e8 100644 --- a/.github/workflows/grafana-bench.yml +++ b/.github/workflows/grafana-bench.yml @@ -1,8 +1,7 @@ name: Grafana Bench on: push: - branches: [main, master] - pull_request: + # Only run on push to the main branch branches: [main, master] jobs: From 31900ebe87ca818333b834ecc9033b922ceb9f3e Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Tue, 29 Oct 2024 14:49:03 +0000 Subject: [PATCH 4/5] Remove e2e:prepare script --- .github/workflows/grafana-bench.yml | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/grafana-bench.yml b/.github/workflows/grafana-bench.yml index 0a8f00e8..348078a0 100644 --- a/.github/workflows/grafana-bench.yml +++ b/.github/workflows/grafana-bench.yml @@ -58,7 +58,7 @@ jobs: --grafana-url "http://localhost:3000" \ --log-level DEBUG \ --pw-execute-cmd "yarn e2e" \ - --pw-prepare-cmd "yarn e2e:prepare" \ + --pw-prepare-cmd "yarn install --frozen-lockfile && yarn playwright install" \ --test-env-vars "CI=true" \ --test-runner "playwright" \ --test-suite-base "/home/bench/tests/" diff --git a/package.json b/package.json index 7e49ee53..f2693435 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", "dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", - "e2e:prepare": "yarn install --frozen-lockfile && yarn playwright install", "e2e:report": "yarn playwright show-report", "e2e:ui": "yarn playwright test --ui", "e2e": "playwright test", From 24f8da8ccf592b5509903201ef1220414b443355 Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Tue, 29 Oct 2024 16:20:06 +0000 Subject: [PATCH 5/5] Use shell script for checking Grafana readyness --- .github/workflows/e2e.yml | 15 +++++++++------ .github/workflows/grafana-bench.yml | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a7c549a1..0cff25c0 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -43,12 +43,15 @@ jobs: compose-file: './docker-compose.yml' - name: Wait for Grafana to start - uses: nev7n/wait_for_response@v1 - with: - url: 'http://localhost:3000/' - responseCode: 200 - timeout: 60000 - interval: 500 + run: | + curl http://localhost:3000 + #RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000) + #echo $response + #if [ $RESPONSE -ne 200 ]; then + # sleep 5; + # echo "Grafana is not accessible" + # exit 1 + #fi - name: Run Playwright tests run: yarn playwright test diff --git a/.github/workflows/grafana-bench.yml b/.github/workflows/grafana-bench.yml index 348078a0..27ce2e18 100644 --- a/.github/workflows/grafana-bench.yml +++ b/.github/workflows/grafana-bench.yml @@ -40,12 +40,15 @@ jobs: compose-file: './docker-compose.yml' - name: Wait for Grafana to start - uses: nev7n/wait_for_response@v1 - with: - url: 'http://localhost:3000/' - responseCode: 200 - timeout: 60000 - interval: 500 + run: | + curl http://localhost:3000 + #RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000) + #echo $response + #if [ $RESPONSE -ne 200 ]; then + # sleep 5; + # echo "Grafana is not accessible" + # exit 1 + #fi - name: Run Grafana Bench tests run: |