| |
| |
|
|
| import http from 'k6/http'; |
| import { check, sleep } from 'k6'; |
| import { login, executeAgent, getAgents, getCanvas, presentCanvas, BASE_URL } from './k6_setup.js'; |
|
|
| |
| export const options = { |
| stages: [ |
| { duration: '10m', target: 100 }, |
| { duration: '15m', target: 100 }, |
| { duration: '3m', target: 0 }, |
| ], |
| thresholds: { |
| http_req_duration: ['p(95)<1200', 'p(99)<2000'], |
| http_req_failed: ['rate<0.15'], |
| checks: ['rate>0.85'], |
| }, |
| }; |
|
|
| export default function () { |
| |
| const token = login(); |
|
|
| if (!token) { |
| sleep(1); |
| return; |
| } |
|
|
| |
| const scenario = Math.random(); |
|
|
| |
| if (scenario < 0.4) { |
| sleep(1); |
|
|
| |
| if (Math.random() < 0.4) { |
| executeAgent(token, `high-agent-${Math.floor(Math.random() * 200)}`); |
| } |
| } |
|
|
| |
| else if (scenario < 0.75) { |
| |
| getAgents(token); |
| sleep(1); |
|
|
| |
| const numExecutions = Math.floor(Math.random() * 3) + 1; |
| for (let i = 0; i < numExecutions; i++) { |
| const agentId = `high-agent-${Math.floor(Math.random() * 200)}`; |
| executeAgent(token, agentId); |
| sleep(1); |
| } |
|
|
| |
| getAgents(token); |
| } |
|
|
| |
| else if (scenario < 0.9) { |
| const canvasId = `canvas-${Math.floor(Math.random() * 100)}`; |
|
|
| |
| getCanvas(token, canvasId); |
| sleep(1); |
|
|
| |
| presentCanvas(token, canvasId); |
| sleep(2); |
|
|
| |
| const canvasId2 = `canvas-${Math.floor(Math.random() * 100)}`; |
| getCanvas(token, canvasId2); |
| } |
|
|
| |
| else { |
| |
| const workflowId = `workflow-${Math.floor(Math.random() * 50)}`; |
| const payload = JSON.stringify({ |
| workflow_id: workflowId, |
| input_data: { test: 'data' }, |
| }); |
|
|
| const params = { |
| headers: { |
| 'Content-Type': 'application/json', |
| 'Authorization': `Bearer ${token}`, |
| }, |
| }; |
|
|
| const response = http.post(`${BASE_URL}/api/v1/workflows/${workflowId}/execute`, payload, params); |
|
|
| check(response, { |
| 'workflow execution started': (r) => r.status === 200 || r.status === 202, |
| }); |
|
|
| sleep(3); |
| } |
|
|
| |
| 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}High Load Test Summary (100 Users)\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; |
| } |
|
|