Skip to content

Commit

Permalink
Merge pull request #1301 from visualize-admin/perf/graphql-performanc…
Browse files Browse the repository at this point in the history
…e-testing

perf: GraphQL performance testing
  • Loading branch information
bprusinowski authored Dec 14, 2023
2 parents 1b7a837 + 4537160 commit 50afe2c
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 20 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/manual-load-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ 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
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 }}

- 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
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 }}

- 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
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 }}
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
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions k6/utils.js → k6/k6-utils.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
2 changes: 1 addition & 1 deletion k6/har/int/edition.js → k6/load-tests/har/int/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
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();
49 changes: 49 additions & 0 deletions k6/performance-tests/graphql/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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;
const cube = __ENV.CUBE;

/** @type {import("k6/options").Options} */
export const options = {
iterations: 1,
};

export default function Components() {
exec.vu.metrics.tags.env = env;
exec.vu.metrics.tags.cube = cube;

http.post(
`https://${env === "prod" ? "" : `${env}.`}visualize.admin.ch/api/graphql`,
JSON.stringify({ query, variables }),
{
headers: {
"Content-Type": "application/json",
"x-visualize-cache-control": "no-cache",
},
}
);
}
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

1 comment on commit 50afe2c

@vercel
Copy link

@vercel vercel bot commented on 50afe2c Dec 14, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-alpha.vercel.app
visualization-tool-ixt1.vercel.app
visualization-tool-git-main-ixt1.vercel.app

Please sign in to comment.