| |
| |
|
|
| import http from 'k6/http'; |
| import { check, sleep, Trend } from 'k6'; |
| import { login, executeAgent, getAgents, BASE_URL } from './k6_setup.js'; |
|
|
| |
| export const options = { |
| stages: [ |
| { duration: '2m', target: 10 }, |
| { duration: '3m', target: 10 }, |
| { duration: '1m', target: 0 }, |
| ], |
| thresholds: { |
| http_req_duration: ['p(95)<500', 'p(99)<1000'], |
| http_req_failed: ['rate<0.05'], |
| checks: ['rate>0.95'], |
| }, |
| }; |
|
|
|
|
| export default function () { |
| |
| if (Math.random() < 0.6) { |
| |
| const token = login(); |
|
|
| |
| sleep(1); |
|
|
| |
| if (token && Math.random() < 0.5) { |
| executeAgent(token, 'baseline-test-agent'); |
| } |
| } |
|
|
| |
| else { |
| |
| const token = login(); |
|
|
| if (token) { |
| |
| executeAgent(token, 'baseline-test-agent'); |
|
|
| |
| sleep(2); |
|
|
| |
| getAgents(token); |
| } |
| } |
|
|
| |
| sleep(1); |
| } |
|
|
| |
| export function handleSummary(data) { |
| return { |
| 'stdout': textSummary(data, { indent: ' ', enableColors: true }), |
| }; |
| } |
|
|
| |
| function textSummary(data, options = {}) { |
| const { indent = '', enableColors = false } = options; |
|
|
| let summary = `${indent}Baseline Load Test Summary\n`; |
| summary += `${indent}========================\n\n`; |
|
|
| |
| const httpReqs = data.metrics.http_reqs; |
| const httpFailed = data.metrics.http_req_failed; |
| const httpDuration = data.metrics.http_req_duration; |
| const checks = data.metrics.checks; |
|
|
| if (httpReqs && httpReqs.values) { |
| summary += `${indent}Total Requests: ${httpReqs.values.count || 0}\n`; |
| } |
|
|
| if (httpFailed && httpFailed.values) { |
| summary += `${indent}Failed Requests: ${httpFailed.values.fails || 0}\n`; |
| summary += `${indent}Failure Rate: ${((httpFailed.values.rate || 0) * 100).toFixed(2)}%\n\n`; |
| } |
|
|
| |
| if (httpDuration && httpDuration.values) { |
| summary += `${indent}Response Times:\n`; |
| summary += `${indent} P50: ${(httpDuration.values['p(50)'] || 0).toFixed(0)}ms\n`; |
| summary += `${indent} P95: ${(httpDuration.values['p(95)'] || 0).toFixed(0)}ms\n`; |
| summary += `${indent} P99: ${(httpDuration.values['p(99)'] || 0).toFixed(0)}ms\n\n`; |
| } |
|
|
| |
| if (checks && checks.values) { |
| summary += `${indent}Checks:\n`; |
| summary += `${indent} Passed: ${checks.values.passes || 0}\n`; |
| summary += `${indent} Failed: ${checks.values.fails || 0}\n`; |
| const passRate = checks.values.count > 0 |
| ? ((checks.values.passes / checks.values.count) * 100).toFixed(2) |
| : '0.00'; |
| summary += `${indent} Pass Rate: ${passRate}%\n`; |
| } |
|
|
| return summary; |
| } |
|
|