Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more performance tests #1373

Merged
merged 43 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
37a83d6
Added more tests
dagfinno Oct 31, 2024
0c2acae
add graphql endpoints
dagfinno Oct 31, 2024
d124a54
add POST request for graphql
dagfinno Oct 31, 2024
3f060c8
add POST request for graphql
dagfinno Oct 31, 2024
da0e851
add get for all enduser dialog paths
dagfinno Oct 31, 2024
2010d94
change performance to yt01
dagfinno Oct 31, 2024
fa65063
Use different create dialog mal
dagfinno Oct 31, 2024
3a94b76
simple search trough graphQL
dagfinno Oct 31, 2024
3f4753b
graphql post sample
dagfinno Oct 31, 2024
7a7b63d
endusers for yt01
dagfinno Oct 31, 2024
8200dc0
graphql post sample
dagfinno Oct 31, 2024
e213d25
serviceowner for yt01
dagfinno Oct 31, 2024
968eef3
test that runs create dialog and search in parallell
dagfinno Oct 31, 2024
401127d
test that first create and then delete a dialog
dagfinno Oct 31, 2024
cdcff0e
fixed filepath for graphql
dagfinno Oct 31, 2024
c677bd4
using dynamic name of workflow run
dagfinno Nov 1, 2024
2b9264d
using dynamic name of workflow run
dagfinno Nov 1, 2024
155fb44
using dynamic name of workflow run
dagfinno Nov 1, 2024
828851d
add http_req_failed rate to thresholds
dagfinno Nov 1, 2024
f4e5f0e
Merge branch 'main' into performance/create-tests
dagfinno Nov 1, 2024
fb08882
Merge branch 'main' into performance/create-tests
dagfinno Nov 1, 2024
cb037e4
chore: perf test url config refactor suggestion (#1375)
oskogstad Nov 1, 2024
80abedf
refactored to lower duplicated code rate
dagfinno Nov 1, 2024
2037132
Merge branch 'main' into performance/create-tests
dagfinno Nov 1, 2024
3af3e1e
Merge branch 'performance/create-tests' of github.com:digdir/dialogpo…
dagfinno Nov 1, 2024
28679dc
implements coderabbitai suggestions
dagfinno Nov 4, 2024
7e02e63
gets duplicated code rate down
dagfinno Nov 4, 2024
e7cf0da
gets duplicated code rate down
dagfinno Nov 4, 2024
74d678c
gets duplicated code rate down
dagfinno Nov 4, 2024
88b4b2b
gets duplicated code rate down
dagfinno Nov 4, 2024
8ff74c2
Merge branch 'main' into performance/create-tests
dagfinno Nov 4, 2024
6546395
implements suggestions from coderabbitai
dagfinno Nov 4, 2024
cc01bc5
implements suggestions from coderabbitai
dagfinno Nov 4, 2024
423962d
Merge branch 'performance/create-tests' of github.com:digdir/dialogpo…
dagfinno Nov 4, 2024
bd5bc8d
Merge branch 'main' into performance/create-tests
arealmaas Nov 5, 2024
d92b9ff
ci: ensure we use secrets from github secrets from env
arealmaas Nov 5, 2024
cbadc0b
Add traceparent header for otel
dagfinno Nov 5, 2024
bd0be61
refactoring; mainly moving tests and methods to new directories and f…
dagfinno Nov 5, 2024
088fc3c
refactoring, directory and file missed the previous commit
dagfinno Nov 5, 2024
5d13c27
documentation performed by github copilot
dagfinno Nov 5, 2024
87faf62
use newer version of k6-utils
dagfinno Nov 5, 2024
d19010b
Merge branch 'main' into performance/create-tests
dagfinno Nov 5, 2024
a864d86
Merge branch 'main' into performance/create-tests
dagfinno Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/dispatch-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ on:
environment:
description: 'Environment'
required: true
default: 'staging'
default: 'yt01'
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
type: choice
options:
- test
- staging
- performance
- yt01
tokens:
description: 'Tokens to generate; for create dialog, search, none, or both'
required: true
Expand All @@ -26,6 +26,11 @@ on:
- enterprise
- personal
- none
tag:
description: 'tag the performance test'
required: true
default: 'Performance test'
type: string
vus:
description: 'Number of VUS'
required: true
Expand All @@ -43,8 +48,11 @@ on:
type: choice
options:
- 'tests/k6/tests/serviceowner/performance/create-dialog.js'
- 'tests/k6/tests/serviceowner/performance/create-remove-dialog.js'
- 'tests/k6/tests/enduser/performance/simple-search.js'
- 'tests/k6/tests/enduser/performance/graphql-search.js'

run-name: ${{ inputs.tag }} vus ${{ inputs.vus }} duration ${{ inputs.duration }}
jobs:
k6-performance:
name: "Run K6 performance test"
Expand Down
12 changes: 11 additions & 1 deletion tests/k6/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ export const baseUrls = {
yt01: "https://platform.yt01.altinn.cloud/dialogporten/api/v1/serviceowner/",
staging: "https://platform.tt02.altinn.no/dialogporten/api/v1/serviceowner/",
prod: "https://platform.altinn.no/dialogporten/api/v1/serviceowner/"
}
},
graphql: {
localdev: "https://localhost:7214/graphql",
localdev_docker: "https://host.docker.internal:7214/graphql",
test: "https://altinn-dev-api.azure-api.net/dialogporten/graphql",
yt01: "https://platform.yt01.altinn.cloud/dialogporten/graphql",
staging: "https://platform.tt02.altinn.no/dialogporten/graphql",
prod: "https://platform.altinn.no/dialogporten/api/v1/graphql"
},
}
};

Expand All @@ -42,4 +50,6 @@ if (!baseUrls[__ENV.API_VERSION]["serviceowner"][__ENV.API_ENVIRONMENT]) {
export const baseUrlEndUser = baseUrls[__ENV.API_VERSION]["enduser"][__ENV.API_ENVIRONMENT];
export const baseUrlServiceOwner = baseUrls[__ENV.API_VERSION]["serviceowner"][__ENV.API_ENVIRONMENT];

export const baseUrlGraphql = baseUrls[__ENV.API_VERSION]["graphql"][__ENV.API_ENVIRONMENT];

dagfinno marked this conversation as resolved.
Show resolved Hide resolved
export const sentinelValue = "dialogporten-e2e-sentinel";
8 changes: 7 additions & 1 deletion tests/k6/common/request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { default as http } from 'k6/http';
import { baseUrlEndUser, baseUrlServiceOwner } from './config.js'
import { baseUrlEndUser, baseUrlGraphql, baseUrlServiceOwner } from './config.js'
import { getServiceOwnerTokenFromGenerator, getEnduserTokenFromGenerator } from './token.js'
import { extend } from './extend.js'

Expand Down Expand Up @@ -125,3 +125,9 @@ export function patchEU(url, body, params = null, tokenOptions = null) {
export function deleteEU(url, params = null, tokenOptions = null) {
return http.request('DELETE', baseUrlEndUser + url, getEnduserRequestParams(params, tokenOptions));
}

export function postGQ(body, params = null) {
body = JSON.stringify({ query: body })
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }});
return http.post(baseUrlGraphql, body, params);
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion tests/k6/common/testimports.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export {
putSO,
patchSO,
deleteSO,
purgeSO
purgeSO,
postGQ
} from './request.js';
export {
setTitle,
Expand Down
59 changes: 59 additions & 0 deletions tests/k6/tests/enduser/performance/graphql-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { postGQ, expect, expectStatusFor, describe } from "../../../common/testimports.js";
import { SharedArray } from 'k6/data';
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { getGraphqlParty } from '../../performancetest_data/graphql-search.js';


const filenameEndusers = '../../performancetest_data/.endusers-with-tokens.csv';

const endUsers = new SharedArray('endUsers', function () {
try {
const csvData = papaparse.parse(open(filenameEndusers), { header: true, skipEmptyLines: true }).data;
if (!csvData.length) {
throw new Error('No data found in CSV file');
}
csvData.forEach((user, index) => {
if (!user.token || !user.ssn) {
throw new Error(`Missing required fields at row ${index + 1}`);
}
});
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
return csvData;
} catch (error) {
throw new Error(`Failed to load end users: ${error.message}`);
}
});

export let options = {
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: {
http_req_failed: ['rate<0.01'],
'http_req_duration{name:graph search}': [],
'http_reqs{name:graph search}': [],
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
},
};

export default function() {
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
graphqlSearch(endUsers[0]);
}
else {
graphqlSearch(randomItem(endUsers));
}
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved

export function graphqlSearch(enduser) {
let paramsWithToken = {
headers: {
Authorization: "Bearer " + enduser.token,
},
tags: { name: 'graphql search' }
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
describe('Perform graphql dialog list', () => {
//let r = ('dialogs' + defaultFilter, paramsWithToken);
let r = postGQ(getGraphqlParty(enduser.ssn), paramsWithToken);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
});
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved

74 changes: 74 additions & 0 deletions tests/k6/tests/enduser/performance/simple-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ const endUsers = new SharedArray('endUsers', function () {
export let options = {
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: {
http_req_failed: ['rate<0.01'],
'http_req_duration{name:simple search}': [],
'http_reqs{name:simple search}': [],
'http_req_duration{name:get dialog}': [],
'http_reqs{name:get dialog}': [],
'http_req_duration{name:get dialog activities}': [],
'http_reqs{name:get dialog activities}': [],
'http_req_duration{name:get dialog activity}': [],
'http_reqs{name:get dialog activity}': [],
'http_req_duration{name:get seenlogs}': [],
'http_reqs{name:get seenlogs}': [],
'http_req_duration{name:get seenlog}': [],
'http_reqs{name:get seenlog}': [],
'http_req_duration{name:get transmissions}': [],
'http_reqs{name:get transmissions}': [],
'http_req_duration{name:get transmission}': [],
'http_reqs{name:get transmission}': [],
'http_req_duration{name:get labellog}': [],
'http_reqs{name:get labellog}': [],
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
},
};

Expand All @@ -52,6 +69,63 @@ export function simpleSearch(enduser) {
let r = getEU('dialogs' + defaultFilter, paramsWithToken);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
if (r.json().items && r.json().items.length > 0) {
let dialogId = r.json().items[0].id;
if (dialogId) {
getDialog(dialogId, paramsWithToken);
getDialogActivities(dialogId, paramsWithToken);
getSeenLog(dialogId, paramsWithToken);
getLabelLog(dialogId, paramsWithToken);
getDialogTransmissions(dialogId, paramsWithToken);
}
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
});
}

export function getDialog(dialogId, paramsWithToken) {
paramsWithToken.tags.name = 'get dialog'
getUrl('dialogs/' + dialogId, paramsWithToken);
}

export function getDialogActivities(dialogId, paramsWithToken) {
paramsWithToken.tags.name = 'get dialog activities'
let d = getUrl('dialogs/' + dialogId + '/activities', paramsWithToken);
let dialog_activites = d.json();
if (dialog_activites.length > 0) {
paramsWithToken.tags.name = 'get dialog activity'
getUrl('dialogs/' + dialogId + '/activities/' + randomItem(dialog_activites).id, paramsWithToken);
}
}

export function getSeenLog(dialogId, paramsWithToken) {
paramsWithToken.tags.name = 'get seenlogs'
let s = getEU('dialogs/' + dialogId + '/seenlog', paramsWithToken);
let seen_logs = s.json();
if (seen_logs.length > 0) {
paramsWithToken.tags.name = 'get seenlog'
getUrl('dialogs/' + dialogId + '/seenlog/' + randomItem(seen_logs).id, paramsWithToken);
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
}

export function getLabelLog(dialogId, paramsWithToken) {
paramsWithToken.tags.name = 'get labellog'
getEU('dialogs/' + dialogId + '/labellog', paramsWithToken);
}

export function getDialogTransmissions(dialogId, paramsWithToken) {
paramsWithToken.tags.name = 'get transmissions'
let d = getUrl('dialogs/' + dialogId + '/transmissions', paramsWithToken);
let dialog_transmissions = d.json();
if (dialog_transmissions.length > 0) {
paramsWithToken.tags.name = 'get transmission'
getUrl('dialogs/' + dialogId + '/transmissions/' + randomItem(dialog_transmissions).id, paramsWithToken);
}
dagfinno marked this conversation as resolved.
Show resolved Hide resolved
}

export function getUrl(url, paramsWithToken) {
let r = getEU(url, paramsWithToken);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
return r;
}

dagfinno marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading