diff --git a/.github/workflows/performance-tests-pr.yml b/.github/workflows/performance-tests-pr.yml index f047caf66..6181e436c 100644 --- a/.github/workflows/performance-tests-pr.yml +++ b/.github/workflows/performance-tests-pr.yml @@ -10,24 +10,27 @@ jobs: steps: - name: Check out uses: actions/checkout@v2 + - name: Send an HTTP request to start up the server + run: | + curl '${{ github.event.deployment_status.target_url }}/api/graphql' -X 'POST' -H 'Content-Type: application/json' -d '{"operationName":"DataCubeObservations","variables":{"locale":"en","sourceType":"sparql","sourceUrl":"https://lindas.admin.ch/query","cubeFilter":{"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"}}}},"query":"query DataCubeObservations($sourceType: String!, $sourceUrl: String!, $locale: String!, $cubeFilter: DataCubeObservationFilter!) { dataCubeObservations(sourceType: $sourceType, sourceUrl: $sourceUrl, locale: $locale, cubeFilter: $cubeFilter) }"}' - 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 --env ROOT_PATH=/root/ - { cube, `https://${ env === "prod" ? "" : `${env}.` - }visualize.admin.ch/api/graphql` + }visualize.admin.ch/api/graphql`, + true, + false ) ) ) @@ -70,7 +72,8 @@ const generatePRTests = () => { query, cube, "${{ github.event.deployment_status.target_url }}/api/graphql", - false + false, + true ) ) ) @@ -88,8 +91,9 @@ jobs: steps: - name: Check out uses: actions/checkout@v2 - - name: Send an HTTP request to get the start up the server - run: curl 'https://test.visualize.admin.ch/api/graphql' -X 'POST' -H 'Content-Type: application/json' -d '{"operationName":"DataCubeObservations","variables":{"locale":"en","sourceType":"sparql","sourceUrl":"https://lindas.admin.ch/query","cubeFilter":{"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"}}}},"query":"query DataCubeObservations($sourceType: String!, $sourceUrl: String!, $locale: String!, $cubeFilter: DataCubeObservationFilter!) {\n dataCubeObservations(\n sourceType: $sourceType\n sourceUrl: $sourceUrl\n locale: $locale\n cubeFilter: $cubeFilter\n )\n}\n"}' + - name: Send an HTTP request to start up the server + run: | + curl '\${{ github.event.deployment_status.target_url }}/api/graphql' -X 'POST' -H 'Content-Type: application/json' -d '{"operationName":"DataCubeObservations","variables":{"locale":"en","sourceType":"sparql","sourceUrl":"https://lindas.admin.ch/query","cubeFilter":{"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"}}}},"query":"query DataCubeObservations($sourceType: String!, $sourceUrl: String!, $locale: String!, $cubeFilter: DataCubeObservationFilter!) { dataCubeObservations(sourceType: $sourceType, sourceUrl: $sourceUrl, locale: $locale, cubeFilter: $cubeFilter) }"}' - name: Run k6 uses: addnab/docker-run-action@v3 with: @@ -104,12 +108,19 @@ jobs: generatePRTests(); -function getRunCommand(env, query, cube, endpoint, sendToPrometheus = true) { +function getRunCommand( + env, + query, + cube, + endpoint, + sendToPrometheus = true, + checkTiming = 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 - } --env ROOT_PATH=/root/ - cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -37,11 +38,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeComponents.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Components() { body.data.dataCubeComponents.measures.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeComponents.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubeMetadata.js b/k6/performance-tests/graphql/DataCubeMetadata.js index ddeb17534..749500f12 100644 --- a/k6/performance-tests/graphql/DataCubeMetadata.js +++ b/k6/performance-tests/graphql/DataCubeMetadata.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -37,11 +38,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeMetadata.expectedDuration}`, - ], - }, }; const headers = { @@ -66,5 +62,15 @@ export default function Components() { body.data.dataCubeMetadata.iri === cubeIri ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeMetadata.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubeObservations.js b/k6/performance-tests/graphql/DataCubeObservations.js index e76726568..e6bed7f73 100644 --- a/k6/performance-tests/graphql/DataCubeObservations.js +++ b/k6/performance-tests/graphql/DataCubeObservations.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -38,11 +39,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubeObservations.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Observations() { body.data.dataCubeObservations.sparqlEditorUrl ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubeObservations.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/DataCubePreview.js b/k6/performance-tests/graphql/DataCubePreview.js index 396fefe87..ea26f0573 100644 --- a/k6/performance-tests/graphql/DataCubePreview.js +++ b/k6/performance-tests/graphql/DataCubePreview.js @@ -24,6 +24,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { locale: "en", @@ -38,11 +39,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.DataCubePreview.expectedDuration}`, - ], - }, }; const headers = { @@ -72,5 +68,15 @@ export default function Components() { body.data.dataCubePreview.observations.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.DataCubePreview.expectedDuration + ); + }, + } + : {}), }); } diff --git a/k6/performance-tests/graphql/PossibleFilters.js b/k6/performance-tests/graphql/PossibleFilters.js index 58bc5241a..9142e8eae 100644 --- a/k6/performance-tests/graphql/PossibleFilters.js +++ b/k6/performance-tests/graphql/PossibleFilters.js @@ -28,6 +28,7 @@ const cubeIri = __ENV.CUBE_IRI; const cubeLabel = __ENV.CUBE_LABEL; const endpoint = __ENV.ENDPOINT; const metadata = cubes.find((cube) => cube.iri === cubeIri); +const checkTiming = __ENV.CHECK_TIMING === "true"; const variables = { iri: cubeIri, @@ -40,11 +41,6 @@ const variables = { /** @type {import("k6/options").Options} */ export const options = { iterations: 2, - thresholds: { - http_req_duration: [ - `avg<${2 * metadata.queries.PossibleFilters.expectedDuration}`, - ], - }, }; const headers = { @@ -69,5 +65,15 @@ export default function Observations() { body.data.possibleFilters.length > 0 ); }, + ...(checkTiming + ? { + "Response time must be fast": (res) => { + return ( + res.timings.duration < + 2 * metadata.queries.PossibleFilters.expectedDuration + ); + }, + } + : {}), }); }