Skip to content

Commit

Permalink
feat: Set up initial GraphQL performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 14, 2023
1 parent abd95a4 commit 4537160
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/performance-tests.yml
Original file line number Diff line number Diff line change
@@ -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/ - <k6/performance-tests/graphql/metadata.js && k6 run -o experimental-prometheus-rw --tag testid=StateAccounts_Office/4/ --env ENV=int --env CUBE=StateAccounts_Office/4/ - <k6/performance-tests/graphql/metadata.js && k6 run -o experimental-prometheus-rw --tag testid=StateAccounts_Office/4/ --env ENV=prod --env CUBE=StateAccounts_Office/4/ - <k6/performance-tests/graphql/metadata.js
37 changes: 37 additions & 0 deletions k6/performance-tests/generate-github-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require("fs");

const envs = ["test", "int", "prod"];
const queries = ["metadata"];
const cubes = ["StateAccounts_Office/4/"];

const generate = () => {
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} - <k6/performance-tests/graphql/${query}.js`;
});
});
})
.join(" && ")}`;

fs.writeFileSync("./.github/workflows/performance-tests.yml", file);
};

generate();
19 changes: 6 additions & 13 deletions k6/performance-tests/graphql/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,25 @@ const variables = {
},
};

const env = __ENV.ENV || "prod";
const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true";
const env = __ENV.ENV;
const cube = __ENV.CUBE;

/** @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/";
exec.vu.metrics.tags.env = env;
exec.vu.metrics.tags.cube = cube;

http.post(
"https://int.visualize.admin.ch/api/graphql",
`https://${env === "prod" ? "" : `${env}.`}visualize.admin.ch/api/graphql`,
JSON.stringify({ query, variables }),
{
headers: {
"Content-Type": "application/json",
"x-visualize-cache-control": "no-cache",
},
}
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"e2e:dev": "E2E_BASE_URL=http://localhost:3000 yarn playwright test",
"e2e": "percy exec -- playwright test",
"cube": "NODE_ENV=development ts-node app/scripts/cube.ts",
"dev:circular-deps": "madge --warning --extensions js,jsx,ts,tsx -b ./app -c ./app/pages/ --ts-config ./app/tsconfig.json | bun scripts/circular-deps-analysis.ts -"
"dev:circular-deps": "madge --warning --extensions js,jsx,ts,tsx -b ./app -c ./app/pages/ --ts-config ./app/tsconfig.json | bun scripts/circular-deps-analysis.ts -",
"github:codegen": "node k6/performance-tests/generate-github-action.js"
},
"dependencies": {
"@babel/runtime": "^7.11.2",
Expand Down

0 comments on commit 4537160

Please sign in to comment.