Skip to content

Commit

Permalink
Performance/t3search (#95)
Browse files Browse the repository at this point in the history
* Added test for search and refactored a bit

* fixed smoketest for search

* added action to run search loadterst ondemand

* Fixed typo in yml-file

* updated readmes
  • Loading branch information
dagfinno authored Oct 2, 2024
1 parent d5a1c81 commit f8fedbc
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 9 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/t3search-loadtest-ondemand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: t3search loadtest ondemand

on:
workflow_dispatch:
inputs:
vus:
description: 'Number of VUS'
required: true
default: 10
type: number
duration:
description: 'Duration of test, ie 30s, 1m, 10m'
required: true
default: 1m
type: string
limit:
description: 'Limit the number of tokens to generate, 0 or less means create for every partyId/userId'
required: true
default: 10
type: number
select-runner:
description: 'Select runner to run the test'
required: true
type: choice
default: "'ubuntu-latest'"
options:
- "'ubuntu-latest'"
- "['self-hosted', 'macOS', 'X64']"

jobs:
run-test:
runs-on: ${{ fromJSON(inputs.select-runner) }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Install xk6
run: go install go.k6.io/xk6/cmd/xk6@latest

- name: Build xk6-counter binary
working-directory: ./performance-tests/t3search/src
run: xk6 build --with github.com/avitalique/xk6-file@latest

- name: Run k6 to generate tokens
working-directory: ./performance-tests/t3search/src
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
tokengenuserpwd: ${{ secrets.TOKENGENPWD }}
limit: ${{ inputs.limit }}

- name: Setup K6
uses: grafana/setup-k6-action@v1

- name: Run local k6 test
uses: grafana/run-k6-action@v1
with:
path: performance-tests/t3search/src/t3search.js
flags: --vus=${{ inputs.vus }} --duration=${{ inputs.duration }}
env:
K6_WEB_DASHBOARD: true
K6_WEB_DASHBOARD_EXPORT: html-report.html
subscription_key: ${{ secrets.SUBSCRIPTION_KEY }}

- name: Upload summary html report
uses: actions/upload-artifact@v4
if: always()
with:
name: summary-html
path: summary.html
- name: Upload extended html report
uses: actions/upload-artifact@v4
if: always()
with:
name: extended-html
path: html-report.html

- name: Upload summary text report
uses: actions/upload-artifact@v4
if: always()
with:
name: summary-txt
path: stdout.txt

- name: Upload HTML report to Azure
if: always()
shell: bash
run: |
REPORT_DIR='t3search_ondemand-${{ github.run_number }}-${{ github.run_attempt }}'
azcopy cp --recursive "*.html" "https://altinnloadtests.blob.core.windows.net/\$web/$REPORT_DIR"
echo "::Link to test results summary: title=HTML report url::https://altinnloadtests.z1.web.core.windows.net/$REPORT_DIR/summary.html"
echo "::Link to test results extended: title=HTML report url::https://altinnloadtests.z1.web.core.windows.net/$REPORT_DIR/html-report.html"
env:
AZCOPY_AUTO_LOGIN_TYPE: SPN
AZCOPY_SPA_APPLICATION_ID: ${{ secrets.AZCOPY_SPA_APPLICATION_ID }}
AZCOPY_SPA_CLIENT_SECRET: ${{ secrets.AZCOPY_SPA_CLIENT_SECRET }}
AZCOPY_TENANT_ID: ${{ secrets.AZCOPY_TENANT_ID }}

50 changes: 50 additions & 0 deletions .github/workflows/t3search-loadtest-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: t3search loadtest smoketest

on:
push:
branches:
- '**'
paths:
- performance-tests/t3search/**
- .github/workflows/t3search-loadtest-push.yml

jobs:
run-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Install xk6
run: go install go.k6.io/xk6/cmd/xk6@latest

- name: Build xk6-counter binary
working-directory: ./performance-tests/t3search/src
run: xk6 build --with github.com/avitalique/xk6-file@latest

- name: Run k6 to generate tokens
working-directory: ./performance-tests/t3search/src
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
tokengenuserpwd: ${{ secrets.TOKENGENPWD }}
limit: 1

- name: Setup K6
uses: grafana/setup-k6-action@v1

- name: Run local k6 test
uses: grafana/run-k6-action@v1
with:
path: performance-tests/t3search/src/t3search.js
flags: --vus=1 --iterations=1
env:
subscription_key: ${{ secrets.SUBSCRIPTION_KEY }}


2 changes: 1 addition & 1 deletion .github/workflows/taxreport-loadtest-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/taxreport-loadtest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand All @@ -45,8 +45,6 @@ jobs:
path: performance-tests/tax-report/src/tax-report.js
flags: --vus=1 --iterations=1
env:
K6_WEB_DASHBOARD: true
K6_WEB_DASHBOARD_EXPORT: html-report.html
serviceowner: ${{ secrets.OWNER }}


2 changes: 1 addition & 1 deletion .github/workflows/taxreport-loadtest-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Run k6 to generate tokens
working-directory: ./performance-tests/tax-report/src
run: ./k6 run generate-tokens.js
run: ./k6 run ../../generate-tokens/src/generate-tokens.js
env:
env: ${{ secrets.YTENVIRONMENT }}
tokengenuser: ${{ secrets.TOKENGENUSER }}
Expand Down
3 changes: 2 additions & 1 deletion performance-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
- [Install k6](https://grafana.com/docs/k6/latest/set-up/install-k6/)
- [Install k6 extentions](https://github.com/grafana/xk6/)
### Test cases:
- [tax report](tax-report/README.md)
- [tax report](tax-report/README.md)
- [t3search](t3search/README.md)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const environment = __ENV.env.toLowerCase();
const tokenGeneratorUserName = __ENV.tokengenuser;
const tokenGeneratorUserPwd = __ENV.tokengenuserpwd;
const limit = (__ENV.limit === undefined ? 0 : __ENV.limit);
const ttl = (__ENV.ttl === undefined ? 3600 : __ENV.ttl)

const filepath = 'data-with-tokens.csv';
const idKeys = new SharedArray('idKeys', function () {
Expand All @@ -18,7 +19,7 @@ export const options = {
vus: 1,
};

export default function(data) {
export default function() {
file.writeString(filepath, 'userId,partyId,ssn,token');
var count = 0
for (const idKey of idKeys) {
Expand All @@ -27,7 +28,7 @@ export default function(data) {
userId: idKey.userid,
partyId: idKey.partyid,
pid: idKey.ssn,
ttl: 3600*24*10,
ttl: ttl
};
var token = generateToken(tokenGeneratorUserName, tokenGeneratorUserPwd, tokenGenParams);
file.appendString(filepath, `\n${idKey.userid},${idKey.partyid},${idKey.ssn},${token}`);
Expand Down
31 changes: 31 additions & 0 deletions performance-tests/t3search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Load test for t3search
Load test for t3search, does the following, divided in two separate steps

## Steps
1. create tokens
2. Do a simple search:

## Run locally
1. Clone this repo
2. Go to src directory
3. build k6 with fileextention
4. run k6 extention to create tokens
4. run test
```
git clone <this repo>
cd altinn-test/performance-tests/t3search/src
xk6 build v0.46.0 --with github.com/avitalique/xk6-file@latest
./k6 run -e env=<> -e tokengenuser=<> -e tokengenuserpwd=<> ../../generate-tokens/src/generate-tokens.js
k6 run -e subscription_key=<Ocp-Apim-Subscription-Key> t3search.js
```
## Github actions
### On push
Runs a test for every push to the performance-loadtest/t3search directory
- one vu
- one minute
### Ondemand
Runs when requested
- selectable number of vus
- selectable duration
- selectable runner

81 changes: 81 additions & 0 deletions performance-tests/t3search/src/t3search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import http from 'k6/http';
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 { SharedArray } from 'k6/data';
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";

const idKeys = new SharedArray('idKeys', function () {
return papaparse.parse(open('data-with-tokens.csv'), { header: true }).data;
});

const subscription_key = __ENV.subscription_key;

export const options = {
discardResponseBodies: true,
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'p(99.5)', 'p(99.9)', 'count'],
thresholds: {
http_req_failed: ['rate<0.01'],
},

};

export function setup() {
var data = {
searchUrlYt: `https://platform.yt01.altinn.cloud/storage/api/v1/sbl/instances/search`,
idKeys: []
};

for (const idKey of idKeys) {
data.idKeys.push({
partyId: idKey.partyId,
userId: idKey.userId,
ssn: idKey.ssn,
token: idKey.token
});
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
break;
}
};
return data;
}

export default function(data) {
if ((options.vus === undefined || options.vus === 1) && (options.iterations === undefined || options.iterations === 1)) {
search(data, data.idKeys[0]);
}
else {
while (true) { search(data, randomItem(data.idKeys)); }
}
}

export function search(data, id) {
var query =
{
Language: 'nb',
InstanceOwnerPartyIdList: [ id.partyId ],
FromCreated: new Date(2018, 12, 12),
ToCreated: new Date(2099, 1, 1),
IncludeActive: false,
IncludeArchived: true
};

var params = {
headers: {
Authorization: 'Bearer ' + id.token,
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscription_key
},
}

var request_body = JSON.stringify(query)
http.post(data.searchUrlYt, request_body, params);
}

export function handleSummary(data) {
return {
'stdout': textSummary(data, { indent: ' ', enableColors: true }),
'stdout.txt': textSummary(data, { indent: ' ', enableColors: true }),
"summary.html": htmlReport(data),
};
}
2 changes: 1 addition & 1 deletion performance-tests/tax-report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Load test for tax report, does the following, divided in two separate steps
git clone <this repo>
cd altinn-test/performance-tests/tax-report/src
xk6 build v0.46.0 --with github.com/avitalique/xk6-file@latest
./k6 run -e env=<> -e tokengenuser=<> -e tokengenuserpwd=<> generate-tokens.js
./k6 run -e env=<> -e tokengenuser=<> -e tokengenuserpwd=<> ../../generate-tokens/src/generate-tokens.js
k6 run -e serviceowner=<> tax-report.js
```
## Github actions
Expand Down

0 comments on commit f8fedbc

Please sign in to comment.