From f59a45b9aa20941003882f3efbbe5e9c924b2a78 Mon Sep 17 00:00:00 2001 From: Dagfinn Olsen Date: Wed, 22 Jan 2025 07:25:50 +0100 Subject: [PATCH] Runs in k8s --- .github/workflows/dispatch-k6-performance.yml | 6 ++++ .../workflows/workflow-run-k6-performance.yml | 35 +++++++++++++++++-- tests/k6/common/token.js | 6 ++-- tests/k6/tests/scripts/run-test-in-k8s.sh | 13 ++++--- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/.github/workflows/dispatch-k6-performance.yml b/.github/workflows/dispatch-k6-performance.yml index 020d1299a..3aa248870 100644 --- a/.github/workflows/dispatch-k6-performance.yml +++ b/.github/workflows/dispatch-k6-performance.yml @@ -31,6 +31,11 @@ on: required: true default: 1m type: string + parallelism: + description: 'Number of parallel test runs' + required: true + default: 1 + type: number testSuitePath: description: 'Path to test suite to run' required: true @@ -58,4 +63,5 @@ jobs: testSuitePath: ${{ inputs.testSuitePath }} vus: ${{ fromJson(inputs.vus) }} duration: ${{ inputs.duration }} + parallelism: ${{ fromJson(inputs.parallelism) }} diff --git a/.github/workflows/workflow-run-k6-performance.yml b/.github/workflows/workflow-run-k6-performance.yml index 23a320adc..936f19701 100644 --- a/.github/workflows/workflow-run-k6-performance.yml +++ b/.github/workflows/workflow-run-k6-performance.yml @@ -18,6 +18,9 @@ on: duration: required: true type: string + parallelism: + required: true + type: number secrets: TOKEN_GENERATOR_USERNAME: required: true @@ -33,14 +36,40 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: OIDC Login to Azure Public Cloud + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: Populate kubeconfig with k6 context + id: populate_kubeconfig_with_k6_context + shell: bash + run: | + if ! az aks install-cli; then + echo "Failed to install kubectl CLI" + exit 1 + fi + + if ! az aks get-credentials --resource-group k6tests-rg --name k6tests-cluster; then + echo "Failed to populate kubeconfig" + exit 1 + fi + + if ! kubelogin convert-kubeconfig -l azurecli; then + echo "Failed to convert kubeconfig" + exit 1 + fi - name: Setup k6 uses: grafana/setup-k6-action@v1 - name: Run K6 tests (${{ inputs.testSuitePath }}) run: | 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 - grep http_req_duration ./results.csv | sort --field-separator=',' --key=3 -nr | head -10 + # k6 run ${{ inputs.testSuitePath }} --quiet --log-output=stdout --include-system-env-vars \ + # --vus=${{ inputs.vus }} --duration=${{ inputs.duration }} --out csv=./results.csv + + ./tests/k6/tests/scripts/run-test-in-k8s.sh -f ${{ inputs.testSuitePath }} -c k6-enduser-search -n k6-enduser-search -v ${{ inputs.vus }} -d ${{ inputs.duration }} -p ${{ inputs.parallelism }} + #grep http_req_duration ./results.csv | sort --field-separator=',' --key=3 -nr | head -10 env: API_ENVIRONMENT: ${{ inputs.environment }} API_VERSION: ${{ inputs.apiVersion }} diff --git a/tests/k6/common/token.js b/tests/k6/common/token.js index 2700f284f..d037dd03d 100644 --- a/tests/k6/common/token.js +++ b/tests/k6/common/token.js @@ -39,9 +39,9 @@ export function fetchToken(url, tokenOptions, type) { if (__VU == 0) { console.info(`Fetching ${type} token from token generator during setup stage`); } - else { - console.info(`Fetching ${type} token from token generator during VU stage for VU #${__VU}`); - } + // else { + // console.info(`Fetching ${type} token from token generator during VU stage for VU #${__VU}`); + // } let response = http.get(url, tokenRequestOptions); diff --git a/tests/k6/tests/scripts/run-test-in-k8s.sh b/tests/k6/tests/scripts/run-test-in-k8s.sh index 0873f5a4d..8769080f6 100755 --- a/tests/k6/tests/scripts/run-test-in-k8s.sh +++ b/tests/k6/tests/scripts/run-test-in-k8s.sh @@ -115,7 +115,7 @@ kind: TestRun metadata: name: $name spec: - arguments: --out experimental-prometheus-rw --vus=$vus --duration=$duration + arguments: --out experimental-prometheus-rw --vus=$vus --duration=$duration --tag testid=$testid parallelism: $parallelism script: configMap: @@ -130,6 +130,9 @@ spec: metadata: labels: k6-test: $name + resources: + requests: + memory: "200Mi" EOF # Apply the config.yml configuration @@ -138,14 +141,14 @@ kubectl apply -f config.yml # Wait for the job to finish wait_timeout="${duration}100s" kubectl --context k6tests-cluster wait --for=jsonpath='{.status.stage}'=finished testrun/$name --timeout=$wait_timeout - +sleep 60 # Print the logs of the pods print_logs cleanup() { local exit_code=$? - echo "Cleaning up resources..." - + echo "Sleeping for 15s and then cleaning up resources..." + sleep 15 if [ -f "config.yml" ]; then kubectl delete -f config.yml --ignore-not-found || true rm -f config.yml @@ -159,4 +162,4 @@ cleanup() { exit $exit_code } -trap cleanup EXIT \ No newline at end of file +#trap cleanup EXIT \ No newline at end of file