-
-
Notifications
You must be signed in to change notification settings - Fork 0
329 lines (288 loc) · 12.7 KB
/
load-test.yml
File metadata and controls
329 lines (288 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Load Testing
permissions:
contents: read
issues: write
pull-requests: write
on:
# Run on pull requests to main
pull_request:
branches: [ main ]
paths:
- 'backend/**'
- 'infrastructure/load-tests/**'
- '.github/workflows/load-test.yml'
# Manual trigger
workflow_dispatch:
inputs:
scenario:
description: 'Load test scenario'
required: true
default: 'all'
type: choice
options:
- all
- evaluation
- metrics
- anomaly
duration:
description: 'Test duration (minutes)'
required: false
default: '5'
# Scheduled run (weekly on Sunday)
schedule:
- cron: '0 2 * * 0'
jobs:
load-test:
runs-on: ubuntu-latest
timeout-minutes: 30
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: flagent
POSTGRES_USER: flagent
POSTGRES_PASSWORD: flagent
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Flagent
run: ./gradlew :backend:build -x test --no-daemon
- name: Start Flagent Server
env:
PORT: 8000
FLAGENT_DB_DBDRIVER: postgresql
FLAGENT_DB_DBCONNECTIONSTR: jdbc:postgresql://localhost:5432/flagent?user=flagent&password=flagent
run: |
./gradlew :backend:run --no-daemon &
echo $! > flagent.pid
# Wait for server to start
for i in {1..30}; do
if curl -s http://localhost:8000/api/v1/health > /dev/null; then
echo "Flagent started successfully"
break
fi
echo "Waiting for Flagent to start... ($i/30)"
sleep 2
done
# Verify server is running
curl -f http://localhost:8000/api/v1/health || exit 1
- name: Setup test data
run: |
# Create test flags (OSS: no X-API-Key; if backend requires tenant, create one and add -H "X-API-Key: $API_KEY" to curl and pass API_KEY to k6 via -e)
for i in {1..5}; do
curl -X POST http://localhost:8000/api/v1/flags \
-H "Content-Type: application/json" \
-d "{\"key\":\"test_flag_$i\",\"description\":\"Load test flag $i\",\"enabled\":true}"
done
echo "Test data created"
- 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: Run Evaluation Load Test
if: ${{ github.event.inputs.scenario == 'evaluation' || github.event.inputs.scenario == 'all' || github.event.inputs.scenario == '' }}
run: |
k6 run infrastructure/load-tests/evaluation-load-test.js \
-e EVAL_VUS=200 -e EVAL_DURATION=30s \
-e BASE_URL=http://localhost:8000 \
--out json=evaluation-results.json \
--summary-export=evaluation-summary.json \
|| echo "Evaluation load test completed with warnings"
- name: Run Metrics Load Test
if: ${{ github.event.inputs.scenario == 'metrics' || github.event.inputs.scenario == 'all' || github.event.inputs.scenario == '' }}
run: |
k6 run infrastructure/load-tests/metrics-load-test.js \
--out json=metrics-results.json \
--summary-export=metrics-summary.json \
|| echo "Load test completed with warnings"
- name: Run Anomaly Detection Load Test
if: ${{ github.event.inputs.scenario == 'anomaly' || github.event.inputs.scenario == 'all' || github.event.inputs.scenario == '' }}
run: |
k6 run infrastructure/load-tests/anomaly-detection-load-test.js \
--out json=anomaly-results.json \
--summary-export=anomaly-summary.json \
|| echo "Load test completed with warnings"
- name: Parse Results
id: parse_results
run: |
# Parse evaluation summary
if [ -f evaluation-summary.json ]; then
EVAL_P95=$(jq -r '.metrics.http_req_duration.values["p(95)"] // empty' evaluation-summary.json)
EVAL_P99=$(jq -r '.metrics.http_req_duration.values["p(99)"] // empty' evaluation-summary.json)
EVAL_RATE=$(jq -r '.metrics.http_reqs.values.rate // empty' evaluation-summary.json)
EVAL_ERROR=$(jq -r '.metrics.http_req_failed.values.rate // empty' evaluation-summary.json)
{
echo "eval_p95=${EVAL_P95:-}"
echo "eval_p99=${EVAL_P99:-}"
echo "eval_rate=${EVAL_RATE:-}"
echo "eval_error_rate=${EVAL_ERROR:-}"
} >> "$GITHUB_OUTPUT"
fi
# Parse metrics summary
if [ -f metrics-summary.json ]; then
METRICS_P95=$(jq -r '.metrics.http_req_duration.values.["p(95)"]' metrics-summary.json)
METRICS_P99=$(jq -r '.metrics.http_req_duration.values.["p(99)"]' metrics-summary.json)
METRICS_ERROR_RATE=$(jq -r '.metrics.http_req_failed.values.rate' metrics-summary.json)
{
echo "metrics_p95=${METRICS_P95}"
echo "metrics_p99=${METRICS_P99}"
echo "metrics_error_rate=${METRICS_ERROR_RATE}"
} >> "$GITHUB_OUTPUT"
fi
# Parse anomaly summary
if [ -f anomaly-summary.json ]; then
ANOMALY_P95=$(jq -r '.metrics.http_req_duration.values.["p(95)"]' anomaly-summary.json)
ANOMALY_P99=$(jq -r '.metrics.http_req_duration.values.["p(99)"]' anomaly-summary.json)
ANOMALY_ERROR_RATE=$(jq -r '.metrics.http_req_failed.values.rate' anomaly-summary.json)
{
echo "anomaly_p95=${ANOMALY_P95}"
echo "anomaly_p99=${ANOMALY_P99}"
echo "anomaly_error_rate=${ANOMALY_ERROR_RATE}"
} >> "$GITHUB_OUTPUT"
fi
- name: Check Performance Thresholds
run: |
FAILED=0
# Evaluation API thresholds
if [ -n "${{ steps.parse_results.outputs.eval_p95 }}" ] && [ "${{ steps.parse_results.outputs.eval_p95 }}" != "null" ]; then
if (( $(echo "${{ steps.parse_results.outputs.eval_p95 }} > 50" | bc -l 2>/dev/null || echo 0) )); then
echo "❌ Evaluation API p95 (${{ steps.parse_results.outputs.eval_p95 }}ms) exceeds threshold (50ms)"
FAILED=1
else
echo "✅ Evaluation API p95 (${{ steps.parse_results.outputs.eval_p95 }}ms) within threshold"
fi
if (( $(echo "${{ steps.parse_results.outputs.eval_error_rate }} > 0.01" | bc -l 2>/dev/null || echo 0) )); then
echo "❌ Evaluation API error rate (${{ steps.parse_results.outputs.eval_error_rate }}) exceeds threshold (1%)"
FAILED=1
else
echo "✅ Evaluation API error rate (${{ steps.parse_results.outputs.eval_error_rate }}) within threshold"
fi
fi
# Metrics API thresholds
if [ -n "${{ steps.parse_results.outputs.metrics_p95 }}" ]; then
if (( $(echo "${{ steps.parse_results.outputs.metrics_p95 }} > 500" | bc -l) )); then
echo "❌ Metrics API p95 (${{ steps.parse_results.outputs.metrics_p95 }}ms) exceeds threshold (500ms)"
FAILED=1
else
echo "✅ Metrics API p95 (${{ steps.parse_results.outputs.metrics_p95 }}ms) within threshold"
fi
if (( $(echo "${{ steps.parse_results.outputs.metrics_error_rate }} > 0.05" | bc -l) )); then
echo "❌ Metrics API error rate (${{ steps.parse_results.outputs.metrics_error_rate }}) exceeds threshold (5%)"
FAILED=1
else
echo "✅ Metrics API error rate (${{ steps.parse_results.outputs.metrics_error_rate }}) within threshold"
fi
fi
# Anomaly Detection thresholds
if [ -n "${{ steps.parse_results.outputs.anomaly_p95 }}" ]; then
if (( $(echo "${{ steps.parse_results.outputs.anomaly_p95 }} > 2000" | bc -l) )); then
echo "❌ Anomaly Detection p95 (${{ steps.parse_results.outputs.anomaly_p95 }}ms) exceeds threshold (2000ms)"
FAILED=1
else
echo "✅ Anomaly Detection p95 (${{ steps.parse_results.outputs.anomaly_p95 }}ms) within threshold"
fi
fi
if [ $FAILED -eq 1 ]; then
echo "::error::Performance thresholds exceeded"
exit 1
fi
- name: Generate Performance Report
if: always()
run: |
cat << EOF > performance-report.md
# Load Test Results
## Evaluation API
- **Throughput:** ${{ steps.parse_results.outputs.eval_rate }} req/s (threshold: target ~2000)
- **p95 latency:** ${{ steps.parse_results.outputs.eval_p95 }}ms (threshold: < 50ms)
- **p99 latency:** ${{ steps.parse_results.outputs.eval_p99 }}ms (threshold: < 100ms)
- **Error rate:** ${{ steps.parse_results.outputs.eval_error_rate }} (threshold: < 1%)
## Metrics API
- **p95 latency:** ${{ steps.parse_results.outputs.metrics_p95 }}ms (threshold: < 500ms)
- **p99 latency:** ${{ steps.parse_results.outputs.metrics_p99 }}ms (threshold: < 1000ms)
- **Error rate:** ${{ steps.parse_results.outputs.metrics_error_rate }} (threshold: < 5%)
## Anomaly Detection
- **p95 latency:** ${{ steps.parse_results.outputs.anomaly_p95 }}ms (threshold: < 2000ms)
- **p99 latency:** ${{ steps.parse_results.outputs.anomaly_p99 }}ms (threshold: < 5000ms)
- **Error rate:** ${{ steps.parse_results.outputs.anomaly_error_rate }} (threshold: < 10%)
## Test Info
- **Commit:** ${{ github.sha }}
- **Branch:** ${{ github.ref_name }}
- **Workflow:** ${{ github.workflow }}
- **Run ID:** ${{ github.run_id }}
EOF
cat performance-report.md
- name: Comment PR with Results
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('performance-report.md', 'utf8');
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
});
} catch (error) {
core.warning(`Failed to post PR comment with load-test results: ${error.message}`);
}
- name: Upload Results
if: always()
uses: actions/upload-artifact@v4
with:
name: load-test-results
path: |
evaluation-results.json
evaluation-summary.json
metrics-results.json
metrics-summary.json
anomaly-results.json
anomaly-summary.json
performance-report.md
- name: Cleanup
if: always()
run: |
if [ -f flagent.pid ]; then
kill "$(cat flagent.pid)" || true
fi
- name: Notify Slack on Failure
if: failure() && github.ref == 'refs/heads/main'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
if [ -n "$SLACK_WEBHOOK_URL" ]; then
curl -X POST "$SLACK_WEBHOOK_URL" \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"🚨 Load test failed on main branch\",
\"blocks\": [
{
\"type\": \"section\",
\"text\": {
\"type\": \"mrkdwn\",
\"text\": \"*Load Test Failure*\n\nCommit: \`${{ github.sha }}\`\nWorkflow: ${{ github.workflow }}\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>\"
}
}
]
}"
fi