Skip to content

Commit

Permalink
test: Add PR GQL performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Feb 15, 2024
1 parent 7c546cb commit 2b39c13
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 20 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/performance-tests-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: GraphQL performance tests (PR)

on: [deployment_status]

jobs:
run_tests:
if: github.event.deployment_status.state == 'success'
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2
- name: Run k6
uses: addnab/docker-run-action@v3
with:
image: grafana/k6:latest
options: -v ${{ github.workspace }}:/root
run: |
k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/DataCubeComponents.js &&
k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/DataCubeComponents.js &&
k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/DataCubeComponents.js &&
k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/DataCubeMetadata.js &&
k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/DataCubeMetadata.js &&
k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/DataCubeMetadata.js &&
k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/DataCubeObservations.js &&
k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/DataCubeObservations.js &&
k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/DataCubeObservations.js &&
k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/DataCubePreview.js &&
k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/DataCubePreview.js &&
k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/DataCubePreview.js &&
k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/PossibleFilters.js &&
k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/PossibleFilters.js &&
k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/PossibleFilters.js
2 changes: 1 addition & 1 deletion .github/workflows/performance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ jobs:
k6 run -o experimental-prometheus-rw --tag testid=DataCubePreview --env ENV=prod --env ENDPOINT=https://visualize.admin.ch/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/DataCubePreview.js &&
k6 run -o experimental-prometheus-rw --tag testid=PossibleFilters --env ENV=prod --env ENDPOINT=https://visualize.admin.ch/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - </root/k6/performance-tests/graphql/PossibleFilters.js &&
k6 run -o experimental-prometheus-rw --tag testid=PossibleFilters --env ENV=prod --env ENDPOINT=https://visualize.admin.ch/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 - </root/k6/performance-tests/graphql/PossibleFilters.js &&
k6 run -o experimental-prometheus-rw --tag testid=PossibleFilters --env ENV=prod --env ENDPOINT=https://visualize.admin.ch/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/PossibleFilters.js
k6 run -o experimental-prometheus-rw --tag testid=PossibleFilters --env ENV=prod --env ENDPOINT=https://visualize.admin.ch/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom - </root/k6/performance-tests/graphql/PossibleFilters.js
85 changes: 66 additions & 19 deletions k6/performance-tests/generate-github-actions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ const queries = [
"PossibleFilters",
];

const commands = envs
.flatMap((env) =>
queries.flatMap((query) =>
cubes.map((cube) =>
getRunCommand(
env,
query,
cube,
`https://${
env === "prod" ? "" : `${env}.`
}visualize.admin.ch/api/graphql`
const generateAutoTests = () => {
const commands = envs
.flatMap((env) =>
queries.flatMap((query) =>
cubes.map((cube) =>
getRunCommand(
env,
query,
cube,
`https://${
env === "prod" ? "" : `${env}.`
}visualize.admin.ch/api/graphql`
)
)
)
)
)
.join(" &&\n ");

const generate = () => {
.join(" &&\n ");
const file = `name: GraphQL performance tests (auto)
on:
Expand All @@ -54,13 +53,61 @@ jobs:
-e K6_PROMETHEUS_RW_SERVER_URL=\${{ secrets.K6_PROMETHEUS_RW_SERVER_URL }}
-e K6_PROMETHEUS_RW_TREND_STATS=avg
run: |
${commands}`;
${commands}
`;

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

generate();
generateAutoTests();

const generatePRTests = () => {
const commands = queries
.flatMap((query) =>
cubes.map((cube) =>
getRunCommand(
"PR",
query,
cube,
"${{ github.event.deployment_status.target_url }}/api/graphql",
false
)
)
)

.join(" &&\n ");
const file = `name: GraphQL performance tests (PR)
on: [deployment_status]
jobs:
run_tests:
if: github.event.deployment_status.state == 'success'
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2
- name: Run k6
uses: addnab/docker-run-action@v3
with:
image: grafana/k6:latest
options: -v \${{ github.workspace }}:/root
run: |
${commands}
`;

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

generatePRTests();

function getRunCommand(env, query, cube, endpoint) {
return `k6 run -o experimental-prometheus-rw --tag testid=${query} --env ENV=${env} --env ENDPOINT=${endpoint} --env CUBE_IRI=${cube.iri} --env CUBE_LABEL=${cube.label} - </root/k6/performance-tests/graphql/${query}.js`;
function getRunCommand(env, query, cube, endpoint, sendToPrometheus = true) {
return `k6 run${
sendToPrometheus ? " -o experimental-prometheus-rw" : ""
} --tag testid=${query} --env ENV=${env} --env ENDPOINT=${endpoint} --env CUBE_IRI=${
cube.iri
} --env CUBE_LABEL=${
cube.label
} - </root/k6/performance-tests/graphql/${query}.js`;
}

0 comments on commit 2b39c13

Please sign in to comment.