-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDataCubeComponents.js
More file actions
103 lines (90 loc) · 2.56 KB
/
DataCubeComponents.js
File metadata and controls
103 lines (90 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { check } from "k6";
import exec from "k6/execution";
import http from "k6/http";
const cubes = JSON.parse(
open(`${__ENV.WORKSPACE}/k6/performance-tests/data.json`)
);
const query = `query DataCubeComponents(
$sourceType: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeComponentFilter!
) {
dataCubeComponents(
sourceType: $sourceType
sourceUrl: $sourceUrl
locale: $locale
cubeFilter: $cubeFilter
)
}`;
const env = __ENV.ENV;
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",
sourceType: "sparql",
sourceUrl: "https://lindas.admin.ch/query",
cubeFilter: {
iri: cubeIri,
},
};
/** @type {import("k6/options").Options} */
export const options = {
iterations: 3,
};
const headers = {
"Content-Type": "application/json",
"x-visualize-cache-control": "no-cache",
};
export default function Components() {
exec.vu.metrics.tags.env = env;
exec.vu.metrics.tags.cube = cubeLabel;
const res = http.post(endpoint, JSON.stringify({ query, variables }), {
headers,
tags: { warmup: exec.scenario.iterationInTest === 0 ? "true" : "false" },
});
check(res, {
"Response must have data": (res) => {
const body = res.json();
return (
body.data &&
body.data.dataCubeComponents &&
body.data.dataCubeComponents.dimensions &&
body.data.dataCubeComponents.dimensions.length > 0 &&
body.data.dataCubeComponents.measures &&
body.data.dataCubeComponents.measures.length > 0
);
},
});
if (checkTiming) {
check(res, {
"Response time must be fast": (res) => {
return !durationExceedsThreshold(res.timings.duration);
},
});
}
}
export function handleSummary(data) {
const warmupMetrics = data.metrics["http_req_duration{warmup:true}"];
const actualMetrics = data.metrics["http_req_duration{warmup:false}"];
const avgDuration = actualMetrics
? actualMetrics.values.avg
: data.metrics.http_req_duration.values.avg;
if (durationExceedsThreshold(avgDuration)) {
return {
stdout: `${Math.round(
(100 * avgDuration) /
metadata.queries.DataCubeComponents.expectedDuration
)}% – DataCubeComponents – ${cubeLabel}. `,
};
}
return {
stdout: "",
};
}
function durationExceedsThreshold(duration) {
return duration > 2 * metadata.queries.DataCubeComponents.expectedDuration;
}