From e638168ff4fc99de0ae1781ca33c6174653b465f Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 11 Dec 2023 14:22:37 +0100 Subject: [PATCH 1/5] chore: Update k6 GitHub Action version --- .github/workflows/manual-load-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/manual-load-test.yml b/.github/workflows/manual-load-test.yml index 9dff34e11..d8a6821aa 100644 --- a/.github/workflows/manual-load-test.yml +++ b/.github/workflows/manual-load-test.yml @@ -36,7 +36,7 @@ jobs: - name: Testing GraphQL - Components if: always() - uses: grafana/k6-action@v0.2.0 + uses: grafana/k6-action@v0.3.1 with: filename: k6/graphql/components.js cloud: ${{ inputs.cloud }} @@ -45,7 +45,7 @@ jobs: - name: Testing GraphQL - Observations if: always() - uses: grafana/k6-action@v0.2.0 + uses: grafana/k6-action@v0.3.1 with: filename: k6/graphql/observations.js cloud: ${{ inputs.cloud }} @@ -54,7 +54,7 @@ jobs: - name: Testing HAR - Edition if: always() - uses: grafana/k6-action@v0.2.0 + uses: grafana/k6-action@v0.3.1 with: filename: k6/har/${{ env.ENV }}/edition.js cloud: ${{ inputs.cloud }} From 3207eefe4c9daca5c623e98253d161e4bec2e7a8 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 11 Dec 2023 14:22:53 +0100 Subject: [PATCH 2/5] chore: Update VS Code settings --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 275afb6cb..0adb5cdcc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,8 @@ { "typescript.tsdk": "node_modules/typescript/lib", "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "source.organizeImports": true + "source.fixAll.eslint": "explicit", + "source.organizeImports": "explicit" }, "eslint.validate": [ "javascript", From 5010d2beccb4225ab057b9c9f4e93e900f96971d Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 11 Dec 2023 14:23:12 +0100 Subject: [PATCH 3/5] refactor: Move load tests to their own folder --- .github/workflows/manual-load-test.yml | 6 +++--- k6/{ => load-tests}/graphql/components.js | 0 k6/{ => load-tests}/graphql/observations.js | 0 k6/{ => load-tests}/graphql/utils.js | 0 k6/{ => load-tests}/har/int/edition.js | 0 k6/{ => load-tests}/har/prod/edition.js | 0 k6/{ => load-tests}/har/test/edition.js | 0 k6/{ => load-tests}/utils.js | 6 ++++-- 8 files changed, 7 insertions(+), 5 deletions(-) rename k6/{ => load-tests}/graphql/components.js (100%) rename k6/{ => load-tests}/graphql/observations.js (100%) rename k6/{ => load-tests}/graphql/utils.js (100%) rename k6/{ => load-tests}/har/int/edition.js (100%) rename k6/{ => load-tests}/har/prod/edition.js (100%) rename k6/{ => load-tests}/har/test/edition.js (100%) rename k6/{ => load-tests}/utils.js (50%) diff --git a/.github/workflows/manual-load-test.yml b/.github/workflows/manual-load-test.yml index d8a6821aa..b5287c64f 100644 --- a/.github/workflows/manual-load-test.yml +++ b/.github/workflows/manual-load-test.yml @@ -38,7 +38,7 @@ jobs: if: always() uses: grafana/k6-action@v0.3.1 with: - filename: k6/graphql/components.js + filename: k6/load-tests/graphql/components.js cloud: ${{ inputs.cloud }} token: ${{ secrets.K6_CLOUD_API_TOKEN }} flags: --env ENV=${{ env.ENV }} --env ENABLE_GQL_SERVER_SIDE_CACHE=${{ env.ENABLE_GQL_SERVER_SIDE_CACHE }} @@ -47,7 +47,7 @@ jobs: if: always() uses: grafana/k6-action@v0.3.1 with: - filename: k6/graphql/observations.js + filename: k6/load-tests/graphql/observations.js cloud: ${{ inputs.cloud }} token: ${{ secrets.K6_CLOUD_API_TOKEN }} flags: --env ENV=${{ env.ENV }} --env ENABLE_GQL_SERVER_SIDE_CACHE=${{ env.ENABLE_GQL_SERVER_SIDE_CACHE }} @@ -56,7 +56,7 @@ jobs: if: always() uses: grafana/k6-action@v0.3.1 with: - filename: k6/har/${{ env.ENV }}/edition.js + filename: k6/load-tests/har/${{ env.ENV }}/edition.js cloud: ${{ inputs.cloud }} token: ${{ secrets.K6_CLOUD_API_TOKEN }} flags: --env ENABLE_GQL_SERVER_SIDE_CACHE=${{ env.ENABLE_GQL_SERVER_SIDE_CACHE }} diff --git a/k6/graphql/components.js b/k6/load-tests/graphql/components.js similarity index 100% rename from k6/graphql/components.js rename to k6/load-tests/graphql/components.js diff --git a/k6/graphql/observations.js b/k6/load-tests/graphql/observations.js similarity index 100% rename from k6/graphql/observations.js rename to k6/load-tests/graphql/observations.js diff --git a/k6/graphql/utils.js b/k6/load-tests/graphql/utils.js similarity index 100% rename from k6/graphql/utils.js rename to k6/load-tests/graphql/utils.js diff --git a/k6/har/int/edition.js b/k6/load-tests/har/int/edition.js similarity index 100% rename from k6/har/int/edition.js rename to k6/load-tests/har/int/edition.js diff --git a/k6/har/prod/edition.js b/k6/load-tests/har/prod/edition.js similarity index 100% rename from k6/har/prod/edition.js rename to k6/load-tests/har/prod/edition.js diff --git a/k6/har/test/edition.js b/k6/load-tests/har/test/edition.js similarity index 100% rename from k6/har/test/edition.js rename to k6/load-tests/har/test/edition.js diff --git a/k6/utils.js b/k6/load-tests/utils.js similarity index 50% rename from k6/utils.js rename to k6/load-tests/utils.js index ad29169da..ee7519d8d 100644 --- a/k6/utils.js +++ b/k6/load-tests/utils.js @@ -1,5 +1,7 @@ export const PROJECT_ID = 3643757; - export const DISTRIBUTION = { - paris: { loadZone: "amazon:fr:paris", percent: 100 }, + paris: { + loadZone: "amazon:fr:paris", + percent: 100, + }, }; From abd95a4665c205254e20b3f913e2cf49e99ca52b Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 14 Dec 2023 09:44:35 +0100 Subject: [PATCH 4/5] refactor: Move things around --- .../graphql/utils.js => graphql-utils.js} | 0 k6/{load-tests/utils.js => k6-utils.js} | 0 k6/load-tests/graphql/components.js | 5 +- k6/load-tests/graphql/observations.js | 5 +- k6/load-tests/har/int/edition.js | 2 +- k6/load-tests/har/prod/edition.js | 2 +- k6/load-tests/har/test/edition.js | 2 +- k6/performance-tests/graphql/metadata.js | 56 +++++++++++++++++++ 8 files changed, 63 insertions(+), 9 deletions(-) rename k6/{load-tests/graphql/utils.js => graphql-utils.js} (100%) rename k6/{load-tests/utils.js => k6-utils.js} (100%) create mode 100644 k6/performance-tests/graphql/metadata.js diff --git a/k6/load-tests/graphql/utils.js b/k6/graphql-utils.js similarity index 100% rename from k6/load-tests/graphql/utils.js rename to k6/graphql-utils.js diff --git a/k6/load-tests/utils.js b/k6/k6-utils.js similarity index 100% rename from k6/load-tests/utils.js rename to k6/k6-utils.js diff --git a/k6/load-tests/graphql/components.js b/k6/load-tests/graphql/components.js index 6543a4970..1744dd1ad 100644 --- a/k6/load-tests/graphql/components.js +++ b/k6/load-tests/graphql/components.js @@ -1,9 +1,8 @@ import { sleep } from "k6"; import http from "k6/http"; -import { DISTRIBUTION, PROJECT_ID } from "../utils.js"; - -import { getHeaders, getUrl } from "./utils.js"; +import { getHeaders, getUrl } from "../../graphql-utils.js"; +import { DISTRIBUTION, PROJECT_ID } from "../../k6-utils.js"; const query = `query Components( $iri: String! diff --git a/k6/load-tests/graphql/observations.js b/k6/load-tests/graphql/observations.js index ddf3e34f7..1c679e9ae 100644 --- a/k6/load-tests/graphql/observations.js +++ b/k6/load-tests/graphql/observations.js @@ -1,9 +1,8 @@ import { sleep } from "k6"; import http from "k6/http"; -import { DISTRIBUTION, PROJECT_ID } from "../utils.js"; - -import { getHeaders, getUrl } from "./utils.js"; +import { getHeaders, getUrl } from "../../graphql-utils.js"; +import { DISTRIBUTION, PROJECT_ID } from "../../k6-utils.js"; const query = `query DataCubeObservations( $iri: String! diff --git a/k6/load-tests/har/int/edition.js b/k6/load-tests/har/int/edition.js index 3f9195a1e..515e44c02 100644 --- a/k6/load-tests/har/int/edition.js +++ b/k6/load-tests/har/int/edition.js @@ -6,7 +6,7 @@ import { group, sleep } from "k6"; import http from "k6/http"; -import { DISTRIBUTION, PROJECT_ID } from "../../utils.js"; +import { DISTRIBUTION, PROJECT_ID } from "../../../k6-utils.js"; const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true"; const cache = enableCache ? "cache" : "no-cache"; diff --git a/k6/load-tests/har/prod/edition.js b/k6/load-tests/har/prod/edition.js index 1f0dc7e4a..76fc4ed98 100644 --- a/k6/load-tests/har/prod/edition.js +++ b/k6/load-tests/har/prod/edition.js @@ -6,7 +6,7 @@ import { group, sleep } from "k6"; import http from "k6/http"; -import { DISTRIBUTION, PROJECT_ID } from "../../utils.js"; +import { DISTRIBUTION, PROJECT_ID } from "../../../k6-utils.js"; const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true"; const cache = enableCache ? "cache" : "no-cache"; diff --git a/k6/load-tests/har/test/edition.js b/k6/load-tests/har/test/edition.js index ab340fb78..b0b160901 100644 --- a/k6/load-tests/har/test/edition.js +++ b/k6/load-tests/har/test/edition.js @@ -6,7 +6,7 @@ import { group, sleep } from "k6"; import http from "k6/http"; -import { DISTRIBUTION, PROJECT_ID } from "../../utils.js"; +import { DISTRIBUTION, PROJECT_ID } from "../../../k6-utils.js"; const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true"; const cache = enableCache ? "cache" : "no-cache"; diff --git a/k6/performance-tests/graphql/metadata.js b/k6/performance-tests/graphql/metadata.js new file mode 100644 index 000000000..9b4f90e74 --- /dev/null +++ b/k6/performance-tests/graphql/metadata.js @@ -0,0 +1,56 @@ +import exec from "k6/execution"; +import http from "k6/http"; + +const query = `query DataCubeMetadata( + $sourceType: String! + $sourceUrl: String! + $locale: String! + $cubeFilter: DataCubeMetadataFilter! +) { + dataCubeMetadata( + sourceType: $sourceType + sourceUrl: $sourceUrl + locale: $locale + cubeFilter: $cubeFilter + ) +}`; + +const variables = { + locale: "en", + sourceType: "sparql", + sourceUrl: "https://lindas.admin.ch/query", + cubeFilter: { + iri: "https://culture.ld.admin.ch/sfa/StateAccounts_Office/4/", + }, +}; + +const env = __ENV.ENV || "prod"; +const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true"; + +/** @type {import("k6/options").Options} */ +export const options = { + iterations: 1, + ext: { + loadimpact: { + name: `GraphQL - DataCubeMetadata (${env.toUpperCase()}, GQL ${ + enableCache ? "cache" : "no-cache" + })`, + }, + }, +}; + +export default function Components() { + // Set tags for metrics + exec.vu.metrics.tags.env = "int"; + exec.vu.metrics.tags.cube = "StateAccounts_Office/4/"; + + http.post( + "https://int.visualize.admin.ch/api/graphql", + JSON.stringify({ query, variables }), + { + headers: { + "Content-Type": "application/json", + }, + } + ); +} From 45371608b161a823ab7c65bc6c2a9a0b1cb61318 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 14 Dec 2023 09:44:44 +0100 Subject: [PATCH 5/5] feat: Set up initial GraphQL performance tests --- .github/workflows/performance-tests.yml | 17 +++++++++ .../generate-github-action.js | 37 +++++++++++++++++++ k6/performance-tests/graphql/metadata.js | 19 +++------- package.json | 3 +- 4 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/performance-tests.yml create mode 100644 k6/performance-tests/generate-github-action.js diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml new file mode 100644 index 000000000..81ae748ad --- /dev/null +++ b/.github/workflows/performance-tests.yml @@ -0,0 +1,17 @@ +name: Performance tests + +on: workflow_dispatch + +jobs: + compile: + name: Compile site assets + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Run the build process with Docker + uses: addnab/docker-run-action@v3 + with: + image: grafana/k6:latest + options: -rm -e K6_PROMETHEUS_RW_USERNAME=${{ secrets.K6_PROMETHEUS_RW_USERNAME }} -e K6_PROMETHEUS_RW_PASSWORD=${{ secrets.K6_PROMETHEUS_RW_PASSWORD }} -e K6_PROMETHEUS_RW_SERVER_URL=${{ secrets.K6_PROMETHEUS_RW_SERVER_URL }} + run: k6 run -o experimental-prometheus-rw --tag testid=StateAccounts_Office/4/ --env ENV=test --env CUBE=StateAccounts_Office/4/ - { + const file = `name: Performance tests + +on: workflow_dispatch + +jobs: + compile: + name: Compile site assets + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Run the build process with Docker + uses: addnab/docker-run-action@v3 + with: + image: grafana/k6:latest + options: -rm -e K6_PROMETHEUS_RW_USERNAME=\${{ secrets.K6_PROMETHEUS_RW_USERNAME }} -e K6_PROMETHEUS_RW_PASSWORD=\${{ secrets.K6_PROMETHEUS_RW_PASSWORD }} -e K6_PROMETHEUS_RW_SERVER_URL=\${{ secrets.K6_PROMETHEUS_RW_SERVER_URL }} + run: ${envs + .map((env) => { + return queries.map((query) => { + return cubes.map((cube) => { + return `k6 run -o experimental-prometheus-rw --tag testid=${cube} --env ENV=${env} --env CUBE=${cube} -