Skip to content

Commit

Permalink
Merge branch 'main' into fix/gql-add-missing-search-parameters-for-pa…
Browse files Browse the repository at this point in the history
…gination-orderby-limit
  • Loading branch information
oskogstad authored Jan 14, 2025
2 parents cedf70c + 8f5ce91 commit 04c4cbb
Show file tree
Hide file tree
Showing 20 changed files with 400 additions and 244 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci-cd-yt01.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}

strategy:
max-parallel: 1
matrix:
Expand All @@ -150,8 +147,6 @@ jobs:
apiVersion: v1
vus: 1
duration: 30s
tokens: both
numberOfTokens: 100
testSuitePath: ${{ matrix.files }}
permissions:
checks: write
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/dispatch-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ on:
- test
- staging
- yt01
tokens:
description: 'Tokens to generate; for create dialog, search, none, or both'
required: true
default: 'both'
type: choice
options:
- both
- enterprise
- personal
- none
tag:
description: 'tag the performance test'
required: true
Expand All @@ -52,6 +42,7 @@ on:
- 'tests/k6/tests/serviceowner/performance/serviceowner-search.js'
- 'tests/k6/tests/enduser/performance/enduser-search.js'
- 'tests/k6/tests/graphql/performance/graphql-search.js'
- 'tests/k6/tests/serviceowner/performance/create-transmissions.js'

run-name: ${{ inputs.tag }} vus ${{ inputs.vus }} duration ${{ inputs.duration }}
jobs:
Expand All @@ -61,13 +52,10 @@ jobs:
secrets:
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
environment: ${{ inputs.environment }}
apiVersion: ${{ inputs.apiVersion }}
testSuitePath: ${{ inputs.testSuitePath }}
vus: ${{ fromJson(inputs.vus) }}
duration: ${{ inputs.duration }}
tokens: ${{ inputs.tokens }}

19 changes: 0 additions & 19 deletions .github/workflows/workflow-run-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,11 @@ on:
duration:
required: true
type: string
tokens:
required: true
type: string
numberOfTokens:
required: false
type: number
default: 0
ttl:
required: false
type: number
default: 3600
secrets:
TOKEN_GENERATOR_USERNAME:
required: true
TOKEN_GENERATOR_PASSWORD:
required: true
K6_CLOUD_TOKEN:
required: true
K6_CLOUD_PROJECT_ID:
required: true

jobs:
k6-test:
runs-on: ubuntu-latest
Expand All @@ -53,7 +37,6 @@ jobs:
uses: grafana/setup-k6-action@v1
- name: Run K6 tests (${{ inputs.testSuitePath }})
run: |
./tests/k6/tests/scripts/generate_tokens.sh ./tests/k6/tests/performancetest_data ${{ inputs.tokens }} ${{ inputs.numberOfTokens }} ${{ inputs.ttl }}
echo "Running k6 test suite ${{ inputs.testSuitePath }} with ${{ inputs.vus }} VUs for ${{ inputs.duration }}"
k6 run ${{ inputs.testSuitePath }} --quiet --log-output=stdout --include-system-env-vars \
--vus=${{ inputs.vus }} --duration=${{ inputs.duration }} --out csv=./results.csv
Expand All @@ -63,5 +46,3 @@ jobs:
API_VERSION: ${{ inputs.apiVersion }}
TOKEN_GENERATOR_USERNAME: ${{ secrets.TOKEN_GENERATOR_USERNAME }}
TOKEN_GENERATOR_PASSWORD: ${{ secrets.TOKEN_GENERATOR_PASSWORD }}
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dotnet ef migrations add TestMigration

Besides ordinary unit and integration tests, there are test suites for both functional and non-functional end-to-end tests implemented with [K6](https://k6.io/).

See `tests/k6/README.md` for more information.
See [tests/k6/README.md](tests/k6/README.md) for more information.

## Health Checks

Expand Down
8 changes: 8 additions & 0 deletions tests/k6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Run `Get-Help .\run.ps1` or `./run.sh --help` for usage information.

The scripts will use locally installed `k6` if available. Failing that, it will attempt to use Docker with [grafana/k6](https://hub.docker.com/r/grafana/k6)

## Performance tests

For information about the performance tests, see the following README files:

- [ServiceOwner](./tests/serviceowner/performance/README.md)
- [GraphQL](./tests/graphql/performance/README.md)
- [EndUser](./tests/enduser/performance/README.md)

## Test suites

Various test suites are defined withing the `suites` directory. A suite consists of
Expand Down
2 changes: 1 addition & 1 deletion tests/k6/common/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getCacheKey(tokenType, tokenOptions) {
return `${tokenType}|${tokenOptions.scopes}|${tokenOptions.orgName}|${tokenOptions.orgNo}|${tokenOptions.ssn}`;
}

function fetchToken(url, tokenOptions, type) {
export function fetchToken(url, tokenOptions, type) {
const currentTime = Math.floor(Date.now() / 1000);
const cacheKey = getCacheKey(type, tokenOptions);

Expand Down
29 changes: 7 additions & 22 deletions tests/k6/tests/enduser/performance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The test file associated with this performance test is
- `enduser-search.js`

## Test description
The test has a list of enduser (ssn) with pre-generated tokens, and the following endpoints are visited in
The test has a list of enduser (ssn), and the following endpoints are visited in
sequence for each enduser:
- api/v1/enduser/dialogs?Party=urn:altinn:person:identifier-no:`<ssn>`
- api/v1/enduser/dialogs/`<dialogId>`
Expand All @@ -28,19 +28,14 @@ sequence for each enduser:
```shell
cd tests/k6/tests/enduser/performance
```
2. Generate tokens using the script below. Make sure to replace `<username>`, `<passwd>` and `<test|staging|yt01>` with your desired values:
```shell
TOKEN_GENERATOR_USERNAME=<username> \
TOKEN_GENERATOR_PASSWORD=<passwd> API_ENVIRONMENT=<test|staging|yt01> \
../../scripts/generate_tokens.sh ../../performancetest_data personal
```
3. Run the test using the following command. Replace `<test|staging|yt01>`, `<vus>`, and `<duration>` with the desired values:
2. Run the test using the following command. Replace `<test|staging|yt01>`, `<vus>`, and `<duration>` with the desired values:
```shell
TOKEN_GENERATOR_USERNAME=<username> TOKEN_GENERATOR_PASSWORD=<passwd> \
k6 run enduser-search.js -e API_VERSION=v1 \
-e API_ENVIRONMENT=<test|staging|yt01> \
--vus=<vus> --duration=<duration>
```
4. Refer to the k6 documentation for more information on usage.
3. Refer to the k6 documentation for more information on usage.

### From GitHub Actions
To run the performance test using GitHub Actions, follow these steps:
Expand All @@ -56,26 +51,16 @@ To run the performance test locally using GitHub Actions and act, perform the fo
```file
TOKEN_GENERATOR_USERNAME:<username>
TOKEN_GENERATOR_PASSWORD:<passwd>
K6_CLOUD_PROJECT_ID=**
K6_CLOUD_TOKEN=**
K6_PROMETHEUS_RW_USERNAME=**
K6_PROMETHEUS_RW_PASSWORD=**
K6_PROMETHEUS_RW_SERVER_URL=**
```
Replace `<username>` and `<passwd>`, same as for generating tokens above. Fill in the K6_* values if available,
used for reporting to Grafana cloud
Replace `<username>` and `<passwd>`, same as for generating tokens above.
##### IMPORTANT: Ensure this file is added to .gitignore to prevent accidental commits of sensitive information. Never commit actual credentials to version control.
4. Run `act` using the command below. Replace `<vus>` and `<duration>` with the desired values:
```shell
act workflow_dispatch -j k6-performance -s GITHUB_TOKEN=`gh auth token` \
--container-architecture linux/amd64 --artifact-server-path $HOME/.act \
--input vus=<vus> --input duration=<duration> \
--input testSuitePath=tests/k6/tests/enduser/performance/enduser-search.js \
--input tokens=personal
--input testSuitePath=tests/k6/tests/enduser/performance/enduser-search.js
```

## Test Results
Test results can be found in GitHub action run log and in App Insights. We are prepared for exporting results to grafana, but so far results are exported to a private grafana instance only, as can be seen from the `.secrets`listed earlier

## TODO
Fix reporting
Test results can be found in GitHub action run log, grafana and in App Insights.
10 changes: 5 additions & 5 deletions tests/k6/tests/enduser/performance/enduser-search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { enduserSearch } from '../../performancetest_common/simpleSearch.js'
import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { endUsersWithTokens } from '../../performancetest_common/readTestdata.js';
import { endUsers } from '../../performancetest_common/readTestdata.js';

const isSingleUserMode = (__ENV.isSingleUserMode ?? 'false') === 'true';
const traceCalls = (__ENV.traceCalls ?? 'false') === 'true';
Expand All @@ -20,16 +20,16 @@ export let options = {
};

export default function() {
if (!endUsersWithTokens || endUsersWithTokens.length === 0) {
if (!endUsers || endUsers.length === 0) {
throw new Error('No end users loaded for testing');
}

if (isSingleUserMode) {
enduserSearch(endUsersWithTokens[0], traceCalls);
enduserSearch(endUsers[0], traceCalls);
}
else {
for (let i = 0; i < endUsersWithTokens.length; i++) {
enduserSearch(endUsersWithTokens[i], traceCalls);
for (let i = 0; i < endUsers.length; i++) {
enduserSearch(endUsers[i], traceCalls);
}
}
}
Expand Down
27 changes: 6 additions & 21 deletions tests/k6/tests/graphql/performance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ The test file associated with this performance test is
```shell
cd tests/k6/tests/graphql/performance
```
2. Generate tokens using the script below. Make sure to replace `<username>`, `<passwd>` and `(<test|staging|yt01>)` with your desired values:
```shell
TOKEN_GENERATOR_USERNAME=<username> \
TOKEN_GENERATOR_PASSWORD=<passwd> API_ENVIRONMENT=<(test|staging|yt01)> \
../../scripts/generate_tokens.sh ../../performancetest_data personal
```
3. Run the test using the following command. Replace `<(test|staging|yt01)>`, `<vus>`, and `<duration>` with the desired values:
2. Run the test using the following command. Replace `<(test|staging|yt01)>`, `<vus>`, and `<duration>` with the desired values:
```shell
TOKEN_GENERATOR_USERNAME=<username> TOKEN_GENERATOR_PASSWORD=<passwd> \
k6 run graphql-search.js -e API_VERSION=v1 \
-e API_ENVIRONMENT=<(test|staging|yt01)> \
--vus=<vus> --duration=<duration>
```
4. Refer to the k6 documentation for more information on usage.
3. Refer to the k6 documentation for more information on usage.
### From GitHub Actions
To run the performance test using GitHub Actions, follow these steps:
1. Go to the [GitHub Actions](https://github.com/altinn/dialogporten/actions/workflows/dispatch-k6-performance.yml) page.
Expand All @@ -42,26 +37,16 @@ To run the performance test locally using GitHub Actions and act, perform the fo
```file
TOKEN_GENERATOR_USERNAME:<username>
TOKEN_GENERATOR_PASSWORD:<passwd>
K6_CLOUD_PROJECT_ID=**
K6_CLOUD_TOKEN=**
K6_PROMETHEUS_RW_USERNAME=**
K6_PROMETHEUS_RW_PASSWORD=**
K6_PROMETHEUS_RW_SERVER_URL=**
```
Replace `<username>` and `<passwd>`, same as for generating tokens above. Fill in the K6_* values if available,
used for reporting to Grafana cloud
Replace `<username>` and `<passwd>`, same as for generating tokens above.
##### IMPORTANT: Ensure this file is added to .gitignore to prevent accidental commits of sensitive information. Never commit actual credentials to version control.
4. Run `act` using the command below. Replace `<vus>` and `<duration>` with the desired values:
```shell
act workflow_dispatch -j k6-performance -s GITHUB_TOKEN=`gh auth token` \
--container-architecture linux/amd64 --artifact-server-path $HOME/.act \
--input vus=<vus> --input duration=<duration> \
--input testSuitePath=tests/k6/tests/graphql/performance/graphql-search.js \
--input tokens=personal
--input testSuitePath=tests/k6/tests/graphql/performance/graphql-search.js
```

## Test Results
Test results can be found in GitHub action run log and in App Insights. We are prepared for exporting results to grafana, but so far results are exported to a private grafana instance only, as can be seen from the `.secrets`listed earlier

## TODO
Fix reporting
Test results can be found in GitHub action run log, grafana and in App Insights.
4 changes: 2 additions & 2 deletions tests/k6/tests/graphql/performance/graphql-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { getDefaultThresholds } from '../../performancetest_common/getDefaultThresholds.js';
import { endUsersWithTokens as endUsers } from '../../performancetest_common/readTestdata.js';
import { endUsers } from '../../performancetest_common/readTestdata.js';
import { graphqlSearch } from "../../performancetest_common/simpleSearch.js";

const isSingleUserMode = (__ENV.isSingleUserMode ?? 'false') === 'true';
Expand All @@ -17,7 +17,7 @@ const traceCalls = (__ENV.traceCalls ?? 'false') === 'true';
* @property {string[]} summaryTrendStats - The summary trend statistics to include in the test results.
* @property {object} thresholds - The thresholds for the test metrics.
*/
export let options = {
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'],['graphql search'])
};
Expand Down
Loading

0 comments on commit 04c4cbb

Please sign in to comment.