Skip to content

Commit

Permalink
feat(performance): Performance/create serviceowner search (#1413)
Browse files Browse the repository at this point in the history
Add a simple serviceowner search on enduser(ssn) and service resource

## 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

- **New Features**
- Introduced a new performance testing script for service owner
searches.
- Added functionality to perform searches specifically for service
owners.
- **Improvements**
	- Enhanced existing search functionality for end users.
- Updated performance metrics tracking to reflect the new focus on end
user searches.
- **Bug Fixes**
- Improved URL construction in the token generation script for better
handling of special characters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
dagfinno authored Nov 7, 2024
1 parent ca18a99 commit f1096a4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dispatch-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ on:
options:
- 'tests/k6/tests/serviceowner/performance/create-dialog.js'
- 'tests/k6/tests/serviceowner/performance/create-remove-dialog.js'
- 'tests/k6/tests/serviceowner/performance/serviceowner-search.js'
- 'tests/k6/tests/enduser/performance/enduser-search.js'
- 'tests/k6/tests/graphql/performance/graphql-search.js'

Expand Down
28 changes: 26 additions & 2 deletions tests/k6/tests/performancetest_common/simpleSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { randomItem, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
import { expect, expectStatusFor } from "../../common/testimports.js";
import { describe } from '../../common/describe.js';
import { getEU, postGQ } from '../../common/request.js';
import { getEU, postGQ, getSO } from '../../common/request.js';
import { getGraphqlParty } from '../performancetest_data/graphql-search.js';


Expand All @@ -31,7 +31,7 @@ function retrieveDialogContent(response, paramsWithToken) {
}

/**
* Performs a simple search.
* Performs a enduser search.
* @param {Object} enduser - The end user.
* @returns {void}
*/
Expand Down Expand Up @@ -127,3 +127,27 @@ export function graphqlSearch(enduser) {
expect(r, 'response').to.have.validJsonBody();
});
}

/**
* Performs a serviceowner search.
* @param {P} serviceowner
* @param {*} enduser
*/
export function serviceownerSearch(serviceowner, enduser, tag_name) {
let paramsWithToken = {
headers: {
Authorization: "Bearer " + serviceowner.token,
traceparent: uuidv4()
},
tags: { name: tag_name }
}

let enduserid = encodeURIComponent(`urn:altinn:person:identifier-no:${enduser.ssn}`);
let serviceResource = encodeURIComponent(`urn:altinn:resource:${serviceowner.resource}`);
let defaultFilter = `?enduserid=${enduserid}&serviceResource=${serviceResource}`;
describe('Perform serviceowner dialog list', () => {
let r = getSO('dialogs' + defaultFilter, paramsWithToken);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
});
}
2 changes: 1 addition & 1 deletion tests/k6/tests/performancetest_data/serviceowners-yt01.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org,orgno,scopes,resource
digdir,991825827,digdir:dialogporten.serviceprovider,super-simple-service
digdir,991825827,digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search,ttd-dialogporten-performance-test-01
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const options = {
},
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[
'simple search',
'enduser search',
'create dialog',
'get dialog',
'get dialog activities',
Expand Down
4 changes: 2 additions & 2 deletions tests/k6/tests/scripts/generate_tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if [ "$tokens" = "both" ] || [ "$tokens" = "enterprise" ]; then
echo "org,orgno,scopes,resource,token" > $serviceowner_tokenfile
while IFS=, read -r org orgno scopes resource
do
url="https://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?org=$org&env=$env&scopes=$scopes&orgno=$orgno&ttl=3600"
token=$(curl -s -f $url -u "$tokengenuser:$tokengenpasswd" )
url="https://altinn-testtools-token-generator.azurewebsites.net/api/GetEnterpriseToken?org=$org&env=$env&orgno=$orgno&ttl=3600"
token=$(curl -s -f --get --data-urlencode "scopes=$scopes" $url -u "$tokengenuser:$tokengenpasswd" )
if [ $? -ne 0 ]; then
echo "Error: Failed to generate enterprise token for: $env, $org, $orgno, $scopes "
continue
Expand Down
34 changes: 34 additions & 0 deletions tests/k6/tests/serviceowner/performance/serviceowner-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
import { serviceownerSearch } from '../../performancetest_common/simpleSearch.js'
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { serviceOwners ,endUsersWithTokens } from '../../performancetest_common/readTestdata.js';

const tag_name = 'serviceowner search';

export let options = {
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: getDefaultThresholds(['http_req_duration', 'http_reqs'],[tag_name])
};

/**
* Perform a service owner search.
* In single user mode, the first service owner and end user with token is used. Only one iteration is performed.
* In multi user mode, a random service owner and end user with token is used.
*/
export default function() {
if (!endUsersWithTokens || endUsersWithTokens.length === 0) {
throw new Error('No end users loaded for testing');
}
if (!serviceOwners || serviceOwners.length === 0) {
throw new Error('No service owners loaded for testing');
}

const isSingleUserMode = (options.vus ?? 1) === 1 && (options.iterations ?? 1) === 1 && (options.duration ?? 0) === 0;
if (isSingleUserMode) {
serviceownerSearch(serviceOwners[0], endUsersWithTokens[0], tag_name);
}
else {
serviceownerSearch(randomItem(serviceOwners), randomItem(endUsersWithTokens), tag_name);
}
}

0 comments on commit f1096a4

Please sign in to comment.