Files
ai-ops/test/perf/dashboard_k6.js
2026-05-12 17:48:22 +08:00

33 lines
908 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import http from 'k6/http';
import { check, sleep } from 'k6';
// AI-Ops 看板首页性能压测脚本
// 目标:验证首页加载 < 2s并发 50 用户
export const options = {
stages: [
{ duration: '1m', target: 50 }, // 逐步加载到 50 并发
{ duration: '3m', target: 50 }, // 稳定压测 3 分钟
{ duration: '1m', target: 0 }, // 逐步卸载
],
thresholds: {
http_req_duration: ['p(95)<2000'], // P95 < 2s
http_req_duration: ['p(99)<3000'], // P99 < 3s
http_req_failed: ['rate<0.01'], // 失败率 < 1%
},
};
export default function () {
const url = 'http://localhost:8080/api/v1/ai-ops/dashboard';
const res = http.get(url, {
headers: { 'Authorization': 'Bearer ${__ENV.AI_OPS_TOKEN}' },
});
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 2s': (r) => r.timings.duration < 2000,
});
sleep(1);
}