-
Notifications
You must be signed in to change notification settings - Fork 106
376 lines (316 loc) · 11.8 KB
/
performance.yml
File metadata and controls
376 lines (316 loc) · 11.8 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
name: Performance Tests
on:
pull_request:
branches: [main, develop]
push:
branches: [main]
schedule:
# Run nightly at 2 AM UTC
- cron: "0 2 * * *"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
backend-performance:
name: Backend Performance Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: predictiq_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Cache Rust dependencies
uses: actions/cache@v5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build API service
working-directory: services/api
run: cargo build --release
- name: Run database migrations
working-directory: services/api
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/predictiq_test
run: |
cargo install sqlx-cli --no-default-features --features postgres
sqlx migrate run
- name: Start API server
working-directory: services/api
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/predictiq_test
REDIS_URL: redis://localhost:6379
RUST_LOG: info
run: |
cargo run --release &
echo $! > api.pid
sleep 10
- name: Wait for API to be ready
run: |
timeout 30 bash -c 'until curl -f http://localhost:8080/health; do sleep 1; done'
- 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 smoke tests
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/smoke-test-raw.json backend/k6/smoke-test.js
- name: Run load tests
if: github.event_name != 'pull_request'
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/load-test-raw.json backend/k6/load-test.js
- name: Run cache tests
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/cache-test-raw.json backend/k6/cache-test.js
- name: Run blockchain data endpoints load test
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/blockchain-load-test-raw.json backend/k6/blockchain-load-test.js
- name: Run rate limit tests
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/rate-limit-test-raw.json backend/k6/rate-limit-test.js
- name: Run stress tests (nightly only)
if: github.event_name == 'schedule'
working-directory: performance
env:
API_URL: http://localhost:8080
run: k6 run --out json=backend/reports/stress-test-raw.json backend/k6/stress-test.js
- name: Generate performance report
if: always()
working-directory: performance
run: |
npm install
node scripts/generate-report.js
- name: Upload performance reports
if: always()
uses: actions/upload-artifact@v7
with:
name: performance-reports
path: performance/backend/reports/
retention-days: 30
- name: Check performance thresholds
if: always()
working-directory: performance
run: |
if [ -f backend/reports/load-test-summary.json ]; then
node -e "
const data = require('./backend/reports/load-test-summary.json');
const p95 = data.metrics.http_req_duration.values['p(95)'];
const errorRate = data.metrics.http_req_failed.values.rate;
console.log('Performance Metrics:');
console.log('P95 Response Time:', p95.toFixed(2), 'ms');
console.log('Error Rate:', (errorRate * 100).toFixed(2), '%');
if (p95 > 200) {
console.error('❌ P95 response time exceeds 200ms threshold');
process.exit(1);
}
if (errorRate > 0.001) {
console.error('❌ Error rate exceeds 0.1% threshold');
process.exit(1);
}
console.log('✅ All performance thresholds met');
"
fi
- name: Comment PR with results
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const path = 'performance/backend/reports/smoke-test-summary.json';
if (fs.existsSync(path)) {
const data = JSON.parse(fs.readFileSync(path, 'utf8'));
const metrics = data.metrics;
const comment = `## 🚀 Performance Test Results
**Smoke Test Summary:**
- Total Requests: ${metrics.http_reqs.values.count}
- Avg Response Time: ${metrics.http_req_duration.values.avg.toFixed(2)}ms
- P95 Response Time: ${metrics.http_req_duration.values['p(95)'].toFixed(2)}ms
- Error Rate: ${(metrics.http_req_failed.values.rate * 100).toFixed(2)}%
**Status:** ${metrics.http_req_duration.values['p(95)'] < 200 && metrics.http_req_failed.values.rate < 0.001 ? '✅ PASS' : '❌ FAIL'}
[View detailed report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Stop API server
if: always()
run: |
if [ -f services/api/api.pid ]; then
kill $(cat services/api/api.pid) || true
fi
contract-benchmarks:
name: Smart Contract Benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Cache Rust dependencies
uses: actions/cache@v5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --version 20.0.0
- name: Run contract benchmarks
working-directory: contracts/predict-iq
run: |
cargo bench --bench gas_benchmark -- --save-baseline main
- name: Upload benchmark results
uses: actions/upload-artifact@v7
with:
name: contract-benchmarks
path: contracts/predict-iq/target/criterion/
retention-days: 30
- name: Compare with baseline
if: github.event_name == 'pull_request'
working-directory: contracts/predict-iq
run: |
if [ -d "target/criterion/baseline" ]; then
cargo bench --bench gas_benchmark -- --baseline main
fi
performance-regression:
name: Performance Regression Detection
runs-on: ubuntu-latest
needs: [backend-performance]
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download current results
uses: actions/download-artifact@v3
with:
name: performance-reports
path: performance/backend/reports/
- name: Checkout baseline branch
continue-on-error: true
run: |
git fetch origin main:main
git show main:.performance-baselines/ > /dev/null 2>&1 && \
git show main:.performance-baselines/ | tar -xz -C . || \
echo "No baselines found on main branch"
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "18"
- name: Compare results against baseline
working-directory: performance
run: |
node scripts/compare-results.js --branch main --threshold 10
- name: Upload regression report
if: always()
uses: actions/upload-artifact@v7
with:
name: regression-report
path: performance/backend/reports/regression-report.md
retention-days: 30
- name: Comment PR with regression report
if: always()
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const path = 'performance/backend/reports/regression-report.md';
if (fs.existsSync(path)) {
const report = fs.readFileSync(path, 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
});
}
- name: Fail if regression detected
if: failure()
run: |
echo "❌ Performance regression detected. Check the PR comment for details."
exit 1
save-performance-baseline:
name: Save Performance Baseline
runs-on: ubuntu-latest
needs: [backend-performance]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download performance results
uses: actions/download-artifact@v3
with:
name: performance-reports
path: performance/backend/reports/
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "18"
- name: Save baseline for main branch
working-directory: performance
run: |
node scripts/compare-results.js --save-baseline --branch main
- name: Commit and push baselines
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [ -n "$(git status --porcelain .performance-baselines/)" ]; then
git add .performance-baselines/
git commit -m "chore: update performance baselines for main branch"
git push origin main
else
echo "No baseline changes to commit"
fi