Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 227 additions & 0 deletions .github/workflows/load.tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
name: Load Tests

on:
pull_request:
branches: [main, development]

jobs:
test-base:
runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

timescaledb:
image: timescale/timescaledb-ha:pg16
env:
POSTGRES_USER: timescaledb
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

mongodb:
image: mongo:latest
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Copy config
run: npm run copy-env

- name: Build
run: npm run build

- name: Start Node.js API
run: GH_ACTIONS=true node ./dist/main.js

- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6

- name: Wait for API to be ready
run: |
until curl --output /dev/null --silent --max-time 60 http://localhost:3005/graphql; do
echo 'Waiting for API...'
sleep 5
done

- name: Preload cache
run: k6 run ./k6/preload.js

- name: Run k6 Load Test
run: k6 run ./k6/script.js

- name: Upload result file for base branch
uses: actions/upload-artifact@v4
with:
name: base-results
path: k6/output/summary.json

test-head:
runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

timescaledb:
image: timescale/timescaledb-ha:pg16
env:
POSTGRES_USER: timescaledb
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

mongodb:
image: mongo:latest
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Copy config
run: npm run copy-env

- name: Build
run: npm run build

- name: Start Node.js API
run: GH_ACTIONS=true node ./dist/main.js &

- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6

- name: Wait for API to be ready
run: |
until curl --output /dev/null --silent --max-time 60 http://localhost:3005/graphql; do
echo 'Waiting for API...'
sleep 5
done

- name: Preload cache
run: k6 run ./k6/preload.js

- name: Run k6 Load Test
run: k6 run ./k6/script.js

- name: Upload result file for head branch
uses: actions/upload-artifact@v4
with:
name: head-results
path: k6/output/summary.json

compare-results:
runs-on: ubuntu-latest
needs: [test-base, test-head]

steps:
- uses: actions/checkout@v2

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Compare test results
run: |
node ./k6/compare-results.js ${{ github.event.pull_request.base.sha }} artifacts/base-results/summary.json ${{ github.event.pull_request.head.sha }} artifacts/head-results/summary.json report.md

- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: k6 load testing comparison

- name: Display Report Contents
run: |
echo "=== Load Test Comparison Report ==="
cat report.md
echo "================================"

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-file: report.md
edit-mode: replace
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ workspace-dex-service.code-workspace

# Env
.env

# k6 output
k6/output/
73 changes: 73 additions & 0 deletions k6/compare-results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const fs = require('fs');

function readResults(filePath) {
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
return {
http_req_duration: {
avg: data.metrics.http_req_duration.values.avg,
p95: data.metrics.http_req_duration.values['p(95)'],
},
http_reqs: data.metrics.http_reqs.values.count,
http_req_failed: data.metrics.http_req_failed.values.rate,
checks_passed: data.metrics.checks.values.passes,
checks_failed: data.metrics.checks.values.fails,
};
}

function calculateDiff(base, head) {
return {
http_req_duration: {
avg: ((head.http_req_duration.avg - base.http_req_duration.avg) / base.http_req_duration.avg * 100).toFixed(2),
p95: ((head.http_req_duration.p95 - base.http_req_duration.p95) / base.http_req_duration.p95 * 100).toFixed(2),
},
http_reqs: ((head.http_reqs - base.http_reqs) / base.http_reqs * 100).toFixed(2),
http_req_failed: (head.http_req_failed - base.http_req_failed).toFixed(4),
checks_passed: ((head.checks_passed - base.checks_passed) / base.checks_passed * 100).toFixed(2),
checks_failed: head.checks_failed - base.checks_failed,
};
}

function generateReport(baseSha, baseResults, headSha, headResults, diff) {
return `# k6 load testing comparison
## Base Branch (${baseSha})
- Average Response Time: ${baseResults.http_req_duration.avg.toFixed(2)}ms
- P95 Response Time: ${baseResults.http_req_duration.p95.toFixed(2)}ms
- Total Requests: ${baseResults.http_reqs}
- Failed Requests Rate: ${(baseResults.http_req_failed * 100).toFixed(2)}%
- Checks Passed: ${baseResults.checks_passed}
- Checks Failed: ${baseResults.checks_failed}

## Head Branch (${headSha})
- Average Response Time: ${headResults.http_req_duration.avg.toFixed(2)}ms
- P95 Response Time: ${headResults.http_req_duration.p95.toFixed(2)}ms
- Total Requests: ${headResults.http_reqs}
- Failed Requests Rate: ${(headResults.http_req_failed * 100).toFixed(2)}%
- Checks Passed: ${headResults.checks_passed}
- Checks Failed: ${headResults.checks_failed}

## Changes
- Average Response Time: ${diff.http_req_duration.avg}% ${diff.http_req_duration.avg > 20 ? '⚠️' : '✅'}
- P95 Response Time: ${diff.http_req_duration.p95}% ${diff.http_req_duration.p95 > 20 ? '⚠️' : '✅'}
- Total Requests: ${diff.http_reqs}%
- Failed Requests Rate Change: ${diff.http_req_failed}% ${diff.http_req_failed > 0 ? '⚠️' : '✅'}
- Checks Passed: ${diff.checks_passed}%
- Checks Failed Change: ${diff.checks_failed} ${diff.checks_failed > 0 ? '⚠️' : '✅'}
${
diff.http_req_duration.avg > 20 ||
diff.http_req_duration.p95 > 20 ||
diff.http_req_failed > 0.01 ||
diff.checks_failed > 0
? '⚠️ **Performance regression detected!** Please review the changes.'
: '✅ **No significant performance regression detected.**'
}`;
}

// Main execution
const [baseSha, baseFile, headSha, headFile, outputFile] = process.argv.slice(2);

const baseResults = readResults(baseFile);
const headResults = readResults(headFile);
const diff = calculateDiff(baseResults, headResults);

const report = generateReport(baseSha, baseResults, headSha, headResults, diff);
fs.writeFileSync(outputFile, report);
Loading
Loading