Skip to content

Commit b1d6eaf

Browse files
feat(performance): Expands search for serviceowners, improved tracing and logging (#1439)
Implements more GET testcalls to serviceowner apis and improves tracing and logging ## Description <!--- Describe your changes in detail --> ## Related Issue(s) - #1326 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a `sentinelPerformanceValue` for enhanced performance tracking. - Added flexibility to performance tests by implementing `isSingleUserMode` for better user scenario handling. - **Improvements** - Enhanced logging and traceability in dialog creation and purging processes. - Expanded performance thresholds for more detailed monitoring. - Updated functions to accept dynamic GET request functions, improving modularity. - **Bug Fixes** - Improved error handling and conditions for single vs. multi-user modes in various performance test scripts. - **Documentation** - Updated comments for clarity regarding options and parameters in several scripts. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 0972243 commit b1d6eaf

File tree

12 files changed

+73
-37
lines changed

12 files changed

+73
-37
lines changed

tests/k6/common/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ export const tokenGeneratorEnv = __ENV.API_ENVIRONMENT == "yt01" ? "yt01" : "tt0
6565
export const baseUrlGraphql = baseUrls[__ENV.API_VERSION]["graphql"][__ENV.API_ENVIRONMENT];
6666

6767
export const sentinelValue = "dialogporten-e2e-sentinel";
68+
export const sentinelPerformanceValue = "dialogporten-e2e-sentinel-performance";

tests/k6/tests/enduser/performance/enduser-search.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { enduserSearch } from '../../performancetest_common/simpleSearch.js'
22
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
33
import { endUsersWithTokens } from '../../performancetest_common/readTestdata.js';
4+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
45

56
export let options = {
67
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
@@ -19,8 +20,10 @@ export let options = {
1920
export default function() {
2021
if (!endUsersWithTokens || endUsersWithTokens.length === 0) {
2122
throw new Error('No end users loaded for testing');
22-
}
23-
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
23+
}
24+
25+
const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
26+
if (isSingleUserMode) {
2427
enduserSearch(endUsersWithTokens[0]);
2528
}
2629
else {

tests/k6/tests/graphql/performance/graphql-search.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Run: k6 run tests/k6/tests/graphql/performance/graphql-search.js --vus 1 --iterations 1 -e env=yt01
44
*/
55

6-
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
6+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
77
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
88
import { endUsersWithTokens as endUsers } from '../../performancetest_common/readTestdata.js';
99
import { graphqlSearch } from "../../performancetest_common/simpleSearch.js";
1010

11+
1112
/**
1213
* The options object for configuring the performance test for GraphQL search.
1314
*
@@ -26,7 +27,8 @@ export default function() {
2627
if (!endUsers || endUsers.length === 0) {
2728
throw new Error('No end users loaded for testing');
2829
}
29-
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
30+
const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
31+
if (isSingleUserMode) {
3032
graphqlSearch(endUsers[0]);
3133
}
3234
else {

tests/k6/tests/performancetest_common/createDialog.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import dialogToInsert from "../performancetest_data/01-create-dialog.js";
1414
* @param {Object} endUser - The end user object.
1515
*/
1616
export function createDialog(serviceOwner, endUser) {
17+
var traceparent = uuidv4();
1718
var paramsWithToken = {
1819
headers: {
1920
Authorization: "Bearer " + serviceOwner.token,
20-
traceparent: uuidv4()
21+
traceparent: traceparent
2122
},
22-
tags: { name: 'create dialog' }
23+
tags: { name: 'create dialog', traceparent: traceparent, enduser: endUser.ssn }
2324
};
2425

2526
describe('create dialog', () => {
@@ -35,12 +36,14 @@ export function createDialog(serviceOwner, endUser) {
3536
* @param {Object} serviceOwner - The service owner object.
3637
* @param {Object} endUser - The end user object.
3738
*/
38-
export function createAndRemoveDialog(serviceOwner, endUser) {
39+
export function createAndRemoveDialog(serviceOwner, endUser) {
40+
var traceparent = uuidv4();
3941
var paramsWithToken = {
4042
headers: {
41-
Authorization: "Bearer " + serviceOwner.token
43+
Authorization: "Bearer " + serviceOwner.token,
44+
traceparent: traceparent
4245
},
43-
tags: { name: 'create dialog' }
46+
tags: { name: 'create dialog', traceparent: traceparent, enduser: endUser.ssn }
4447
}
4548

4649
let dialogId = 0;
@@ -52,7 +55,10 @@ export function createAndRemoveDialog(serviceOwner, endUser) {
5255
});
5356

5457
describe('remove dialog', () => {
58+
traceparent = uuidv4();
5559
paramsWithToken.tags.name = 'remove dialog';
60+
paramsWithToken.tags.traceparent = traceparent;
61+
paramsWithToken.headers.traceparent = traceparent
5662
if (dialogId) {
5763
let r = purgeSO('dialogs/' + dialogId, paramsWithToken);
5864
expect(r.status, 'response status').to.equal(204);

tests/k6/tests/performancetest_common/simpleSearch.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ import { getGraphqlParty } from '../performancetest_data/graphql-search.js';
1616
* @param {Object} paramsWithToken - The parameters with token.
1717
* @returns {void}
1818
*/
19-
function retrieveDialogContent(response, paramsWithToken) {
19+
function retrieveDialogContent(response, paramsWithToken, getFunction = getEU) {
2020
const items = response.json().items;
2121
if (!items?.length) return;
2222

2323
const dialogId = items[0].id;
2424
if (!dialogId) return;
2525

26-
getContent(dialogId, paramsWithToken, 'get dialog');
27-
getContentChain(dialogId, paramsWithToken, 'get dialog activities', 'get dialog activity', '/activities/')
28-
getContentChain(dialogId, paramsWithToken, 'get seenlogs', 'get seenlog', '/seenlog/')
29-
getContent(dialogId, paramsWithToken, 'get labellog', '/labellog');
30-
getContentChain(dialogId, paramsWithToken, 'get transmissions', 'get transmission', '/transmissions/')
26+
getContent(dialogId, paramsWithToken, 'get dialog', '', getFunction);
27+
getContentChain(dialogId, paramsWithToken, 'get dialog activities', 'get dialog activity', '/activities/', getFunction);
28+
getContentChain(dialogId, paramsWithToken, 'get seenlogs', 'get seenlog', '/seenlog/', getFunction);
29+
if (getFunction == getEU) {
30+
getContent(dialogId, paramsWithToken, 'get labellog', '/labellog', getFunction);
31+
}
32+
getContentChain(dialogId, paramsWithToken, 'get transmissions', 'get transmission', '/transmissions/', getFunction);
3133
}
3234

3335
/**
@@ -61,12 +63,12 @@ export function enduserSearch(enduser) {
6163
* @param {string} path - The path to append to the URL. Can be empty or /labellog.
6264
* @returns {void}
6365
*/
64-
export function getContent(dialogId, paramsWithToken, tag, path = '') {
66+
export function getContent(dialogId, paramsWithToken, tag, path = '', getFunction = getEU) {
6567
const listParams = {
6668
...paramsWithToken,
6769
tags: { ...paramsWithToken.tags, name: tag }
6870
};
69-
getUrl('dialogs/' + dialogId + path, listParams);
71+
getUrl('dialogs/' + dialogId + path, listParams, getFunction);
7072
}
7173

7274
/**
@@ -78,19 +80,19 @@ export function getContent(dialogId, paramsWithToken, tag, path = '') {
7880
* @param {string} endpoint - The endpoint to append to the URL.
7981
* @returns {void}
8082
*/
81-
export function getContentChain(dialogId, paramsWithToken, tag, subtag, endpoint) {
83+
export function getContentChain(dialogId, paramsWithToken, tag, subtag, endpoint, getFunction = getEU) {
8284
const listParams = {
8385
...paramsWithToken,
8486
tags: { ...paramsWithToken.tags, name: tag }
8587
};
86-
let d = getUrl('dialogs/' + dialogId + endpoint, listParams);
88+
let d = getUrl('dialogs/' + dialogId + endpoint, listParams, getFunction);
8789
let json = d.json();
8890
if (json.length > 0) {
8991
const detailParams = {
9092
...paramsWithToken,
9193
tags: { ...paramsWithToken.tags, name: subtag }
9294
};
93-
getUrl('dialogs/' + dialogId + endpoint + randomItem(json).id, detailParams);
95+
getUrl('dialogs/' + dialogId + endpoint + randomItem(json).id, detailParams, getFunction);
9496
}
9597
}
9698

@@ -100,8 +102,8 @@ export function getContentChain(dialogId, paramsWithToken, tag, subtag, endpoint
100102
* @param {Object} paramsWithToken - The parameters with token.
101103
* @returns {Object} The response object.
102104
*/
103-
export function getUrl(url, paramsWithToken) {
104-
let r = getEU(url, paramsWithToken);
105+
export function getUrl(url, paramsWithToken, getFunction = getEU) {
106+
let r = getFunction(url, paramsWithToken);
105107
expectStatusFor(r).to.equal(200);
106108
expect(r, 'response').to.have.validJsonBody();
107109
return r;
@@ -114,12 +116,14 @@ export function getUrl(url, paramsWithToken) {
114116
* @returns {void}
115117
*/
116118
export function graphqlSearch(enduser) {
119+
let traceparent = uuidv4();
117120
let paramsWithToken = {
118121
headers: {
119122
Authorization: "Bearer " + enduser.token,
120-
traceparent: uuidv4()
123+
traceparent: traceparent,
124+
'User-Agent': 'dialogporten-k6-graphql-search'
121125
},
122-
tags: { name: 'graphql search' }
126+
tags: { name: 'graphql search', traceparent: traceparent }
123127
};
124128
describe('Perform graphql dialog list', () => {
125129
let r = postGQ(getGraphqlParty(enduser.ssn), paramsWithToken);
@@ -134,12 +138,13 @@ export function graphqlSearch(enduser) {
134138
* @param {*} enduser
135139
*/
136140
export function serviceownerSearch(serviceowner, enduser, tag_name) {
141+
let traceparent = uuidv4();
137142
let paramsWithToken = {
138143
headers: {
139144
Authorization: "Bearer " + serviceowner.token,
140-
traceparent: uuidv4()
145+
traceparent: traceparent
141146
},
142-
tags: { name: tag_name }
147+
tags: { name: tag_name, traceparent: traceparent, enduser: enduser.ssn }
143148
}
144149

145150
let enduserid = encodeURIComponent(`urn:altinn:person:identifier-no:${enduser.ssn}`);
@@ -149,5 +154,6 @@ export function serviceownerSearch(serviceowner, enduser, tag_name) {
149154
let r = getSO('dialogs' + defaultFilter, paramsWithToken);
150155
expectStatusFor(r).to.equal(200);
151156
expect(r, 'response').to.have.validJsonBody();
157+
retrieveDialogContent(r, paramsWithToken, getSO);
152158
});
153159
}

tests/k6/tests/performancetest_data/01-create-dialog.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {default as createDialogPayload} from "../serviceowner/testdata/01-create-dialog.js"
2+
import { sentinelPerformanceValue } from "../../common/config.js";
23

34
const ACTIVITY_TYPE_INFORMATION = 'Information';
45

@@ -7,7 +8,10 @@ function cleanUp(originalPayload) {
78
throw new Error('Invalid payload');
89
}
910

10-
const payload = { ...originalPayload };
11+
const payload = {
12+
...originalPayload,
13+
searchTags: [...(originalPayload.searchTags || []), { "value": sentinelPerformanceValue }]
14+
};
1115
const { visibleFrom, ...payloadWithoutVisibleFrom } = payload;
1216

1317
const activities = payload.activities?.map(activity => {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org,orgno,scopes,resource
2-
digdir,991825827,digdir:dialogporten.serviceprovider,super-simple-service
2+
digdir,991825827,digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search,super-simple-service

tests/k6/tests/scenarios/performance/create-dialog-and-search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Performance test for creating dialogs and searching dialogs.
33
* Run: k6 run tests/k6/tests/scenarios/performance/create-dialog-and-search.js -e env=yt01 -e svus=1 -e evus=1 -e duration=1m
44
*/
5-
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
5+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
66
import { enduserSearch } from '../../performancetest_common/simpleSearch.js';
77
import { createDialog } from '../../performancetest_common/createDialog.js';
88
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';

tests/k6/tests/serviceowner/performance/create-dialog.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Performance test for creating a dialog
33
* Run: k6 run tests/k6/tests/serviceowner/performance/create-dialog.js --vus 1 --iterations 1
44
*/
5-
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
5+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
66
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
77
import { createDialog } from '../../performancetest_common/createDialog.js';
88
import { serviceOwners, endUsers } from '../../performancetest_common/readTestdata.js';
@@ -19,7 +19,8 @@ export default function() {
1919
if (!serviceOwners || serviceOwners.length === 0) {
2020
throw new Error('No service owners loaded for testing');
2121
}
22-
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
22+
const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
23+
if (isSingleUserMode) {
2324
createDialog(serviceOwners[0], endUsers[0]);
2425
}
2526
else {

tests/k6/tests/serviceowner/performance/create-remove-dialog.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Performance test for creating and removing a dialog
33
* Run: k6 run tests/k6/tests/serviceowner/performance/create-remove-dialog.js --vus 1 --iterations 1
44
*/
5-
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
5+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
66
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
77
import { serviceOwners, endUsers } from "../../performancetest_common/readTestdata.js";
88
import { createAndRemoveDialog } from '../../performancetest_common/createDialog.js';
@@ -22,7 +22,9 @@ export default function() {
2222
if (!serviceOwners || serviceOwners.length === 0) {
2323
throw new Error('No service owners loaded for testing');
2424
}
25-
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
25+
26+
const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
27+
if (isSingleUserMode) {
2628
createAndRemoveDialog(serviceOwners[0], endUsers[0]);
2729
}
2830
else {

tests/k6/tests/serviceowner/performance/purge-dialogs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*
88
* Run: k6 run tests/k6/tests/serviceowner/performance/purge-dialogs.js -e env=yt01
99
*/
10+
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
1011
import { getSO, purgeSO } from '../../../common/request.js';
1112
import { serviceOwners } from '../../performancetest_common/readTestdata.js';
1213
import { expect, expectStatusFor } from "../../../common/testimports.js";
1314
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
1415
import { describe } from '../../../common/describe.js';
15-
import { sentinelValue } from '../../../common/config.js';
16+
import { sentinelPerformanceValue as sentinelValue } from '../../../common/config.js';
1617

1718
/**
1819
* Retrieves the dialog ids to purge.
@@ -21,9 +22,12 @@ import { sentinelValue } from '../../../common/config.js';
2122
* @returns {Array} - The dialog ids to purge.
2223
*/
2324
function getDialogs(serviceOwner) {
25+
var traceparent = uuidv4();
26+
console.log("Searching for dialogs to purge, tracevalue: " + traceparent);
2427
var paramsWithToken = {
2528
headers: {
26-
Authorization: "Bearer " + serviceOwner.token
29+
Authorization: "Bearer " + serviceOwner.token,
30+
traceparent: traceparent
2731
}
2832
}
2933
let hasNextPage = false;

tests/k6/tests/serviceowner/performance/serviceowner-search.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
1+
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
22
import { serviceownerSearch } from '../../performancetest_common/simpleSearch.js'
33
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
44
import { serviceOwners ,endUsersWithTokens } from '../../performancetest_common/readTestdata.js';
@@ -7,7 +7,14 @@ const tag_name = 'serviceowner search';
77

88
export let options = {
99
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
10-
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[tag_name])
10+
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[tag_name,
11+
'get dialog',
12+
'get dialog activities',
13+
'get dialog activity',
14+
'get seenlogs',
15+
'get seenlog',
16+
'get transmissions',
17+
'get transmission'])
1118
};
1219

1320
/**

0 commit comments

Comments
 (0)