From abd95a4665c205254e20b3f913e2cf49e99ca52b Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 14 Dec 2023 09:44:35 +0100 Subject: [PATCH] refactor: Move things around --- .../graphql/utils.js => graphql-utils.js} | 0 k6/{load-tests/utils.js => k6-utils.js} | 0 k6/load-tests/graphql/components.js | 5 +- k6/load-tests/graphql/observations.js | 5 +- k6/load-tests/har/int/edition.js | 2 +- k6/load-tests/har/prod/edition.js | 2 +- k6/load-tests/har/test/edition.js | 2 +- k6/performance-tests/graphql/metadata.js | 56 +++++++++++++++++++ 8 files changed, 63 insertions(+), 9 deletions(-) rename k6/{load-tests/graphql/utils.js => graphql-utils.js} (100%) rename k6/{load-tests/utils.js => k6-utils.js} (100%) create mode 100644 k6/performance-tests/graphql/metadata.js diff --git a/k6/load-tests/graphql/utils.js b/k6/graphql-utils.js similarity index 100% rename from k6/load-tests/graphql/utils.js rename to k6/graphql-utils.js diff --git a/k6/load-tests/utils.js b/k6/k6-utils.js similarity index 100% rename from k6/load-tests/utils.js rename to k6/k6-utils.js diff --git a/k6/load-tests/graphql/components.js b/k6/load-tests/graphql/components.js index 6543a4970..1744dd1ad 100644 --- a/k6/load-tests/graphql/components.js +++ b/k6/load-tests/graphql/components.js @@ -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! diff --git a/k6/load-tests/graphql/observations.js b/k6/load-tests/graphql/observations.js index ddf3e34f7..1c679e9ae 100644 --- a/k6/load-tests/graphql/observations.js +++ b/k6/load-tests/graphql/observations.js @@ -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! diff --git a/k6/load-tests/har/int/edition.js b/k6/load-tests/har/int/edition.js index 3f9195a1e..515e44c02 100644 --- a/k6/load-tests/har/int/edition.js +++ b/k6/load-tests/har/int/edition.js @@ -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"; diff --git a/k6/load-tests/har/prod/edition.js b/k6/load-tests/har/prod/edition.js index 1f0dc7e4a..76fc4ed98 100644 --- a/k6/load-tests/har/prod/edition.js +++ b/k6/load-tests/har/prod/edition.js @@ -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"; diff --git a/k6/load-tests/har/test/edition.js b/k6/load-tests/har/test/edition.js index ab340fb78..b0b160901 100644 --- a/k6/load-tests/har/test/edition.js +++ b/k6/load-tests/har/test/edition.js @@ -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"; diff --git a/k6/performance-tests/graphql/metadata.js b/k6/performance-tests/graphql/metadata.js new file mode 100644 index 000000000..9b4f90e74 --- /dev/null +++ b/k6/performance-tests/graphql/metadata.js @@ -0,0 +1,56 @@ +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 || "prod"; +const enableCache = __ENV.ENABLE_GQL_SERVER_SIDE_CACHE === "true"; + +/** @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/"; + + http.post( + "https://int.visualize.admin.ch/api/graphql", + JSON.stringify({ query, variables }), + { + headers: { + "Content-Type": "application/json", + }, + } + ); +}