From d0cf56ab683aa6a8546d904c78465ed4c6f75a0c Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 13 Feb 2024 13:51:10 +0100 Subject: [PATCH 1/3] fix: DataCubePreview GQL performance test --- .../graphql/DataCubePreview.js | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/k6/performance-tests/graphql/DataCubePreview.js b/k6/performance-tests/graphql/DataCubePreview.js index 4886c842d..cf347c193 100644 --- a/k6/performance-tests/graphql/DataCubePreview.js +++ b/k6/performance-tests/graphql/DataCubePreview.js @@ -3,35 +3,17 @@ import exec from "k6/execution"; import http from "k6/http"; const query = `query DataCubePreview( - $iri: String! $sourceType: String! $sourceUrl: String! $locale: String! - $latest: Boolean - $disableValuesLoad: Boolean = true + $cubeFilter: DataCubePreviewFilter! ) { - dataCubeByIri( - iri: $iri + dataCubePreview( sourceType: $sourceType sourceUrl: $sourceUrl locale: $locale - latest: $latest - disableValuesLoad: $disableValuesLoad - ) { - iri - title - description - publicationStatus - observations( - sourceType: $sourceType - sourceUrl: $sourceUrl - preview: true - limit: 10 - ) { - data - sparqlEditorUrl - } - } + cubeFilter: $cubeFilter + ) }`; const env = __ENV.ENV; @@ -39,11 +21,13 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const variables = { - iri: cubeIri, + locale: "en", sourceType: "sparql", sourceUrl: "https://lindas.admin.ch/query", - locale: "en", - latest: false, + cubeFilter: { + iri: cubeIri, + latest: false, + }, }; /** @type {import("k6/options").Options} */ From a1a33f8bff56c065995f1e3eff27d2ee2b836473 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 13 Feb 2024 14:19:58 +0100 Subject: [PATCH 2/3] chore: Add DataCubeObservations query to GQL performance tests --- .github/workflows/performance-tests.yml | 27 ++-- .../generate-github-action.js | 13 +- .../graphql/DataCubeObservations.js | 116 ++++++++++++++++++ 3 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 k6/performance-tests/graphql/DataCubeObservations.js diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml index f0bfe6d88..e907cb795 100644 --- a/.github/workflows/performance-tests.yml +++ b/.github/workflows/performance-tests.yml @@ -23,29 +23,38 @@ jobs: -e K6_PROMETHEUS_RW_SERVER_URL=${{ secrets.K6_PROMETHEUS_RW_SERVER_URL }} run: | k6 run -o experimental-prometheus-rw --tag testid=DataCubeComponents --env ENV=test --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - - queries.flatMap((q) => cubes.map((c) => getRunCommand(e, q, c))) + .flatMap((env) => + queries.flatMap((query) => + cubes.map((cube) => getRunCommand(env, query, cube)) + ) ) .join(" &&\n "); diff --git a/k6/performance-tests/graphql/DataCubeObservations.js b/k6/performance-tests/graphql/DataCubeObservations.js new file mode 100644 index 000000000..a22548a2f --- /dev/null +++ b/k6/performance-tests/graphql/DataCubeObservations.js @@ -0,0 +1,116 @@ +import { check, fail } from "k6"; +import exec from "k6/execution"; +import http from "k6/http"; + +const query = `query DataCubeObservations( + $sourceType: String! + $sourceUrl: String! + $locale: String! + $cubeFilter: DataCubeObservationFilter! +) { + dataCubeObservations( + sourceType: $sourceType + sourceUrl: $sourceUrl + locale: $locale + cubeFilter: $cubeFilter + ) +}`; + +const cubeFilterByCubeIri = { + "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9": + { + iri: "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9", + filters: { + "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/Kanton": + { + type: "single", + value: "https://ld.admin.ch/canton/1", + }, + }, + }, + "https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3": { + iri: "https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3", + filters: { + "https://environment.ld.admin.ch/foen/nfi/unitOfReference": { + type: "single", + value: "https://ld.admin.ch/country/CHE", + }, + "https://environment.ld.admin.ch/foen/nfi/classificationUnit": { + type: "single", + value: + "https://environment.ld.admin.ch/foen/nfi/ClassificationUnit/Total", + }, + "https://environment.ld.admin.ch/foen/nfi/inventory": { + type: "single", + value: "https://environment.ld.admin.ch/foen/nfi/Inventory/150", + }, + "https://environment.ld.admin.ch/foen/nfi/unitOfEvaluation": { + type: "single", + value: "https://environment.ld.admin.ch/foen/nfi/UnitOfEvaluation/2382", + }, + "https://environment.ld.admin.ch/foen/nfi/evaluationType": { + type: "single", + value: "https://environment.ld.admin.ch/foen/nfi/EvaluationType/1", + }, + }, + }, + "https://energy.ld.admin.ch/elcom/electricityprice": { + iri: "https://energy.ld.admin.ch/elcom/electricityprice", + filters: { + "https://energy.ld.admin.ch/elcom/electricityprice/dimension/municipality": + { + type: "single", + value: "https://ld.admin.ch/municipality/1", + }, + "https://energy.ld.admin.ch/elcom/electricityprice/dimension/category": { + type: "single", + value: "https://energy.ld.admin.ch/elcom/electricityprice/category/C1", + }, + "https://energy.ld.admin.ch/elcom/electricityprice/dimension/operator": { + type: "single", + value: "https://energy.ld.admin.ch/elcom/electricityprice/operator/486", + }, + "https://energy.ld.admin.ch/elcom/electricityprice/dimension/product": { + type: "single", + value: + "https://energy.ld.admin.ch/elcom/electricityprice/product/standard", + }, + }, + }, +}; + +const env = __ENV.ENV; +const cubeIri = __ENV.CUBE_IRI; +const cubeLabel = __ENV.CUBE_LABEL; + +const variables = { + locale: "en", + sourceType: "sparql", + sourceUrl: "https://lindas.admin.ch/query", + cubeFilter: cubeFilterByCubeIri[cubeIri], +}; + +/** @type {import("k6/options").Options} */ +export const options = { + iterations: 1, +}; + +const headers = { + "Content-Type": "application/json", + "x-visualize-cache-control": "no-cache", +}; + +export default function Observations() { + exec.vu.metrics.tags.env = env; + exec.vu.metrics.tags.cube = cubeLabel; + + const res = http.post( + `https://${env === "prod" ? "" : `${env}.`}visualize.admin.ch/api/graphql`, + JSON.stringify({ query, variables }), + { headers } + ); + + if (!check(res, { "Status code must be 200": (res) => res.status == 200 })) { + fail("Status code was *not* 200!"); + } +} From 683262e0c0f0c6e2405ffc6a4b9fbe92c7688c51 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 13 Feb 2024 15:20:55 +0100 Subject: [PATCH 3/3] chore: Add PossibleFilters query to GQL performance tests --- .github/workflows/performance-tests.yml | 11 +- .../generate-github-action.js | 1 + .../graphql/PossibleFilters.js | 121 ++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 k6/performance-tests/graphql/PossibleFilters.js diff --git a/.github/workflows/performance-tests.yml b/.github/workflows/performance-tests.yml index e907cb795..0c2d60a3a 100644 --- a/.github/workflows/performance-tests.yml +++ b/.github/workflows/performance-tests.yml @@ -34,6 +34,9 @@ jobs: k6 run -o experimental-prometheus-rw --tag testid=DataCubePreview --env ENV=test --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 - res.status == 200 })) { + fail("Status code was *not* 200!"); + } +}