Skip to content

Commit

Permalink
Runs in k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
dagfinno committed Jan 22, 2025
1 parent 8f5ce91 commit f59a45b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dispatch-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,4 +63,5 @@ jobs:
testSuitePath: ${{ inputs.testSuitePath }}
vus: ${{ fromJson(inputs.vus) }}
duration: ${{ inputs.duration }}
parallelism: ${{ fromJson(inputs.parallelism) }}

35 changes: 32 additions & 3 deletions .github/workflows/workflow-run-k6-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
duration:
required: true
type: string
parallelism:
required: true
type: number
secrets:
TOKEN_GENERATOR_USERNAME:
required: true
Expand All @@ -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 }}
Expand Down
6 changes: 3 additions & 3 deletions tests/k6/common/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 8 additions & 5 deletions tests/k6/tests/scripts/run-test-in-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -130,6 +130,9 @@ spec:
metadata:
labels:
k6-test: $name
resources:
requests:
memory: "200Mi"
EOF
# Apply the config.yml configuration
Expand All @@ -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
Expand All @@ -159,4 +162,4 @@ cleanup() {

exit $exit_code
}
trap cleanup EXIT
#trap cleanup EXIT

0 comments on commit f59a45b

Please sign in to comment.