k6-perf-test-website
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesek6-perf-test-website
k6-perf-test-websitek6-perf-test-website
k6-perf-test-websiteAn end-to-end, opinionated workflow for performance-testing any
public website with k6. The skill produces:
- A scaffolded project with one folder per user-described workflow.
- Functional protocol + browser tests (must pass before load testing).
- Hybrid load tests (protocol scenario + 1 browser VU) per test type (smoke / average / stress / spike / soak / breakpoint).
- SLO-backed thresholds with per-endpoint tagging and Web Vitals.
- A cross-platform load-generator monitor sidecar.
- Optional Grafana-side investigation when the user owns the backend.
- A structured Markdown report at the end.
This skill enforces a few opinions you should not silently override:
- Always elicit workflows first. Don't guess.
- Functional tests must be green before load tests run.
- Always monitor the load generator — server-looks-slow is often laptop-looks-slow.
- Local for validation, cloud for scale — but ask the user where to run each test type; don't hardcode.
- No shared . Iteration-body duplication is preferred; each script reads cleanly on its own during incident review.
tests/lib/
一种使用k6对任意公共网站进行端到端性能测试的标准化工作流。此技能可生成:
- 一个脚手架项目,每个用户描述的工作流对应一个文件夹。
- 功能性协议+浏览器测试(负载测试前必须通过)。
- 针对每种测试类型(冒烟/常规/压力/尖峰/持续/断点)的混合负载测试(协议场景+1个浏览器VU)。
- 带有端点标记和Web Vitals的基于SLO的阈值。
- 跨平台负载生成器监控侧车。
- 当用户拥有后端时,可选的Grafana端调查流程。
- 最终生成结构化Markdown报告。
此技能有一些固定规则,请勿擅自修改:
- 始终先明确工作流,不要猜测。
- 功能性测试必须全部通过后才能运行负载测试。
- 始终监控负载生成器——服务器看起来慢往往是本地设备性能不足导致的。
- 本地用于验证,云端用于大规模测试——但要询问用户每种测试类型的运行环境,不要硬编码。
- 不共享目录。宁愿重复代码,也要保证每个脚本在事件复盘时能独立清晰阅读。
tests/lib/
Prerequisites
前置条件
- k6 ≥ v2.0.0 () — required for stable
k6 version,k6/browser, async/await iteration functions, and per-requestexpect().tags - Node.js ≥ 20 + npm.
- Playwright with the Chromium download
().
npx playwright install chromium - (
har-to-k6).npm i -D har-to-k6 - Network access from the load-generator host to the target site.
Tools the skill prefers when installed:
- — script creation, Playwright→k6/browser migration, API lookup. Prefer over hand-writing k6 boilerplate.
mcp-k6 - — in-session Prometheus/Loki/Tempo/Pyroscope queries during §9 backend investigation.
mcp-grafana - — Grafana Cloud CLI for shell-friendly queries, datasource discovery, and Grafana Cloud k6 cloud-run dispatch.
gcx - binary — local validation runs and breakpoint hunting.
k6 - (xk6-docs) — look up k6 API surface when writing or editing scripts without
k6 x docsavailable.mcp-k6
If these tools are not configured the skill falls back to plain CLI
tools (, , ) and hand-written scripts. The skill does
not own toolchain setup; defer to the user's existing setup process.
k6npxcurlExplicit non-goals:
- Protocol-only suites (out of scope for this skill).
- API-only / non-browser apps.
- Mobile-native testing.
- Capacity planning beyond finding and tagging a breakpoint.
- k6 ≥ v2.0.0(执行查看)——需要稳定的
k6 version、k6/browser、async/await迭代函数和每个请求的expect()功能。tags - Node.js ≥ 20 + npm。
- Playwright并下载Chromium(执行)。
npx playwright install chromium - (执行
har-to-k6安装)。npm i -D har-to-k6 - 负载生成器主机能够访问目标网站。
技能优先使用以下已安装工具:
- ——脚本创建、Playwright→k6/browser迁移、API查询。优先使用它而非手动编写k6模板代码。
mcp-k6 - ——在第9节的后端调查环节中,实时查询Prometheus/Loki/Tempo/Pyroscope数据。
mcp-grafana - ——Grafana Cloud CLI,用于便捷的命令行查询、数据源发现和Grafana Cloud k6云端任务调度。
gcx - 二进制文件——本地验证运行和断点测试。
k6 - (xk6-docs)——在没有
k6 x docs时,编写或编辑脚本时查询k6 API。mcp-k6
如果未配置这些工具,技能会退回到纯CLI工具(、、)和手动编写脚本。技能不负责工具链的安装配置,请遵循用户现有的安装流程。
k6npxcurl明确不支持的场景:
- 仅协议测试套件(超出此技能范围)。
- 仅API/非浏览器应用。
- 原生移动应用测试。
- 除查找和标记断点之外的容量规划。
Workflow overview
工作流概述
Tick these off in order. Each step has a section below.
- Elicit workflows from the user. §1
- Scaffold the project from . §2
assets/ - Record each workflow with Playwright. §3
- Build functional protocol + browser tests; run until green. §4
tests/run-all.sh - Design SLO-backed thresholds and per-endpoint tags. §5
- Build hybrid load tests, one file per test type. §6
- Run validation locally with the LG sidecar. §7
- Push to Grafana Cloud k6 for the test types the user chose for cloud. §8
- Investigate the backend with Grafana (if owned). §9
- Report back to the user. §10
1. Elicit workflows
1. 明确工作流
The single most important step. Without explicit workflows, every
later step is guesswork.
Ask the user the questions in
and record answers in a alongside the scaffolded project.
references/workflow-elicitation.mdrunbook.mdYou must capture: 2-4 named workflows, credentials, read vs write,
destructive actions to avoid during soak, worry list, existing SLOs,
backend ownership and Grafana access, and per test type whether
each runs locally or in Grafana Cloud k6.
If the user can't name at least one workflow, stop and clarify;
do not proceed.
这是最重要的一步。没有明确的工作流,后续所有步骤都是猜测。
询问用户中的问题,并将答案记录在脚手架项目旁的中。
references/workflow-elicitation.mdrunbook.md必须收集的信息:2-4个命名工作流、凭据、读/写操作、持续测试中需避免的破坏性操作、关注点列表、现有SLO、后端所有权和Grafana访问权限,以及每种测试类型的运行环境(本地或Grafana Cloud k6)。
如果用户无法说出至少一个工作流,请停止并澄清,不要继续。
2. Scaffold the project
2. 生成项目脚手架
Copy the tree from this skill into the user's chosen
directory. The skill's directory is at ,
where is the absolute path to this skill's directory —
your harness exposes this (e.g. opencode prefixes skill metadata with
a line). If you can't determine
from context, ask the user.
assets/assets/<SKILL_DIR>/assets/<SKILL_DIR>Base directory for this skill:<SKILL_DIR>bash
cp -R "<SKILL_DIR>/assets/." "<target-dir>/"If is blocked by sandbox permissions, copy files individually
via your agent's file-write tool.
cp -RThe scaffolded layout:
<target-dir>/
├── package.json
├── .gitignore
├── README.md
├── runbook.md # you create from §1 answers
├── recordings/
│ ├── README.md
│ └── scripts/
│ └── recorder.template.js # copy per workflow → wN-<short-name>.js, …
├── tests/
│ ├── run-all.sh
│ └── workflow.template/ # copy per workflow → wN-<short-name>/, …
│ ├── from-har.js
│ ├── protocol.js
│ ├── browser.js
│ ├── smoke.js
│ ├── average.js
│ ├── stress.js
│ ├── spike.js
│ ├── soak.js
│ └── breakpoint.js
└── tools/
├── lg-monitor.sh
└── run-with-monitor.shFor each workflow: copy → ,
copy → , and
replace markers with the workflow's short name.
recorder.template.jsrecordings/scripts/wN-<short-name>.jstests/workflow.template/tests/wN-<short-name>/<WORKFLOW_PLACEHOLDER>Then install:
bash
cd <target-dir> && npm install && npx playwright install chromium将此技能的目录结构复制到用户指定的目录中。技能的目录位于,其中是此技能目录的绝对路径——你的运行环境会提供此路径(例如opencode会在技能元数据前添加“Base directory for this skill:”行)。如果无法从上下文确定,请询问用户。
assets/assets/<SKILL_DIR>/assets/<SKILL_DIR><SKILL_DIR>bash
cp -R "<SKILL_DIR>/assets/." "<target-dir>/"如果沙箱权限阻止了命令,请通过你的代理文件写入工具逐个复制文件。
cp -R生成的目录结构:
<target-dir>/
├── package.json
├── .gitignore
├── README.md
├── runbook.md # 从第1节的答案创建
├── recordings/
│ ├── README.md
│ └── scripts/
│ └── recorder.template.js # 每个工作流复制一份→wN-<short-name>.js,…
├── tests/
│ ├── run-all.sh
│ └── workflow.template/ # 每个工作流复制一份→wN-<short-name>/,…
│ ├── from-har.js
│ ├── protocol.js
│ ├── browser.js
│ ├── smoke.js
│ ├── average.js
│ ├── stress.js
│ ├── spike.js
│ ├── soak.js
│ └── breakpoint.js
└── tools/
├── lg-monitor.sh
└── run-with-monitor.sh针对每个工作流:复制→,复制→,并将标记替换为工作流的简称。
recorder.template.jsrecordings/scripts/wN-<short-name>.jstests/workflow.template/tests/wN-<short-name>/<WORKFLOW_PLACEHOLDER>然后执行安装:
bash
cd <target-dir> && npm install && npx playwright install chromium3. Record each workflow
3. 录制每个工作流
Per workflow:
- Fill in : user-action sequence,
recordings/scripts/wN-<short-name>.jsregex (allow-list the target host; block third-party RUM/ads — seerecordHar.urlFilter), and a real Chromereferences/recording-with-playwright.md(the defaultuserAgentUA triggers bot-blocking on many sites).HeadlessChrome - Run: → writes
node recordings/scripts/wN-<short-name>.jsrecordings/har/wN-<short-name>.har - Convert:
npx har-to-k6 recordings/har/wN-<short-name>.har -o tests/wN-<short-name>/from-har.js - Commit both HAR and (audit trail for bundle-path changes).
from-har.js
If the recorder fails or produces an unusable HAR (bot-blocking,
missing hydration, third-party noise), see the Recording section of
and .
references/gotchas.mdreferences/recording-with-playwright.mdPrefer recording and migration tools if available.
mcp-k6针对每个工作流:
- 填写:用户操作序列、
recordings/scripts/wN-<short-name>.js正则表达式(允许目标主机,阻止第三方RUM/广告——参考recordHar.urlFilter),以及真实的Chromereferences/recording-with-playwright.md(默认的userAgentUA会触发很多网站的机器人拦截)。HeadlessChrome - 运行:→生成
node recordings/scripts/wN-<short-name>.jsrecordings/har/wN-<short-name>.har - 转换:
npx har-to-k6 recordings/har/wN-<short-name>.har -o tests/wN-<short-name>/from-har.js - 提交HAR文件和(用于跟踪资源路径变化的审计线索)。
from-har.js
如果录制失败或生成无法使用的HAR文件(机器人拦截、缺失内容渲染、第三方干扰),请参考和中的录制部分。
references/gotchas.mdreferences/recording-with-playwright.md如果可用,优先使用的录制和迁移工具。
mcp-k64. Build functional tests
4. 构建功能性测试
Per workflow:
- Hand-clean into
from-har.js— drop per-request UA headers, rename groups, parameteriseprotocol.js, replace session tokens, dropBASE_URL, addsleep(1)on every load-bearing response. Full procedure inexpect().references/functional-tests.md - Hand-write from the Playwright recorder using the 5-step procedure in
browser.js.references/functional-tests.md - Run . Do not proceed to §5 until it exits 0.
./tests/run-all.sh
Prefer migration tools for Playwright→k6/browser conversion.
mcp-k6针对每个工作流:
- 手动清理并转换为
from-har.js——删除每个请求的UA头、重命名分组、参数化protocol.js、替换会话令牌、删除BASE_URL、为每个关键响应添加sleep(1)。完整流程参考expect()。references/functional-tests.md - 根据Playwright录制内容,按照中的5步流程手动编写
references/functional-tests.md。browser.js - 运行。直到脚本返回0才能进入第5步。
./tests/run-all.sh
如果可用,优先使用的Playwright→k6/browser迁移工具。
mcp-k65. Design SLOs and thresholds
5. 设计SLO与阈值
Adjust the opinionated defaults in
to the user's stated SLOs from §1. Four layers:
assets/tests/workflow.template/- Global SLOs — overall error rate + aggregate latency.
- Per-endpoint thresholds — tag every protocol request, threshold per tag.
- Per-iteration thresholds — workflow time + iteration completion rate.
- Web Vitals — LCP/INP/CLS only (no FCP).
Default globals:
js
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(95)<500'],
checks: ['rate>0.99'],Per-endpoint tagging:
js
http.get(`${BASE_URL}/api/things`, { tags: { name: 'GetThings' } });
'http_req_duration{name:GetThings}': ['p(95)<400', 'p(99)<800'],Web Vitals:
js
browser_web_vital_lcp: ['p(95)<2500'],
browser_web_vital_inp: ['p(95)<200'],
browser_web_vital_cls: ['p(95)<0.1'],See for per-iteration tuning, the
custom-Trend pattern, Rate,
breakpoint abort-on-fail thresholds, and loosening rules.
references/slo-design.mdperformance.markiteration_completed根据第1节中用户说明的SLO,调整中的默认配置。分为四层:
assets/tests/workflow.template/- 全局SLO——整体错误率+聚合延迟。
- 端点阈值——为每个协议请求添加标记,针对每个标记设置阈值。
- 迭代阈值——工作流时长+迭代完成率。
- Web Vitals——仅包含LCP/INP/CLS(不包含FCP)。
默认全局配置:
js
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(95)<500'],
checks: ['rate>0.99'],端点标记示例:
js
http.get(`${BASE_URL}/api/things`, { tags: { name: 'GetThings' } });
'http_req_duration{name:GetThings}': ['p(95)<400', 'p(99)<800'],Web Vitals配置:
js
browser_web_vital_lcp: ['p(95)<2500'],
browser_web_vital_inp: ['p(95)<200'],
browser_web_vital_cls: ['p(95)<0.1'],参考了解迭代调优、自定义趋势模式、比率、断点测试的失败即终止阈值,以及宽松规则。
references/slo-design.mdperformance.markiteration_completed6. Build hybrid load tests
6. 构建混合负载测试
Per workflow, one file per test type. Each file has a protocol scenario
(drives load) plus a single browser VU (measures Web Vitals under load).
Breakpoint is protocol-only — a browser VU adds noise to the signal.
| Type | Executor | Defaults |
|---|---|---|
| smoke | constant-vus | 3 VUs × 1m |
| average | ramping-vus | 0→20→0 over 14m |
| stress | ramping-vus | 0→50→0 over 20m |
| spike | ramping-vus | 0→100→0 over 2m |
| soak | ramping-vus | 0→10→0 over 70m |
| breakpoint | ramping-arrival-rate | 5/s→500/s over 20m, abortOnFail |
Tune per workflow once you've seen smoke results. See
for rationale and
for why one file per type and why duplication between files is acceptable.
references/test-types.mdreferences/hybrid-load-design.md针对每个工作流,每种测试类型对应一个文件。每个文件包含一个协议场景(生成负载)和一个浏览器VU(在负载下测量Web Vitals)。断点测试仅使用协议——浏览器VU会干扰信号。
| 测试类型 | 执行器 | 默认配置 |
|---|---|---|
| 冒烟测试 | constant-vus | 3个VU × 1分钟 |
| 常规测试 | ramping-vus | 0→20→0,持续14分钟 |
| 压力测试 | ramping-vus | 0→50→0,持续20分钟 |
| 尖峰测试 | ramping-vus | 0→100→0,持续2分钟 |
| 持续测试 | ramping-vus | 0→10→0,持续70分钟 |
| 断点测试 | ramping-arrival-rate | 5次/秒→500次/秒,持续20分钟,失败即终止 |
查看冒烟测试结果后,针对每个工作流调整配置。参考了解设计理由,参考了解为何每种类型对应一个文件,以及为何允许文件间代码重复。
references/test-types.mdreferences/hybrid-load-design.md7. Run locally with LG sidecar
7. 配合LG侧车本地运行
bash
./tools/run-with-monitor.sh tests/wN-<short-name>/smoke.jsStarts in the background, runs k6, then prints a
summary verdict: OK (≥30% idle), NOTE (10–30%), or WARNING
(<10%). If WARNING, the laptop is the bottleneck — reduce VUs, switch
to cloud, or split across multiple LGs. See .
lg-monitor.shreferences/lg-monitoring.mdbash
./tools/run-with-monitor.sh tests/wN-<short-name>/smoke.js在后台启动,运行k6,然后输出总结结论:OK(空闲率≥30%)、NOTE(空闲率10–30%)或WARNING(空闲率<10%)。如果是WARNING,说明本地设备是瓶颈——减少VU数量、切换到云端,或使用多个负载生成器。参考。
lg-monitor.shreferences/lg-monitoring.md8. Push to Grafana Cloud k6
8. 推送到Grafana Cloud k6
For each test type assigned to cloud in the §1 runbook:
- Confirm works (the skill does not own auth setup).
k6 cloud login - Run smoke locally first to validate the script.
k6 cloud run tests/wN-<short-name>/<type>.js- Capture the run URL for the §10 report.
Cost reminder: browser VU-hours are billed 10× protocol VU-hours.
Soak and breakpoint are the most expensive. Check limits before long runs.
See .
references/local-vs-cloud.md针对第1节运行手册中指定为云端运行的每种测试类型:
- 确认可用(技能不负责认证配置)。
k6 cloud login - 先在本地运行冒烟测试验证脚本。
- 执行
k6 cloud run tests/wN-<short-name>/<type>.js - 记录运行URL,用于第10节的报告。
成本提醒:浏览器VU小时的计费是协议VU小时的10倍。持续测试和断点测试成本最高。长时间运行前请检查限制。参考。
references/local-vs-cloud.md9. Investigate the backend
9. 调查后端
Only if the user owns the backend and has Grafana access.
- Discover datasources via or
mcp-grafana.gcx datasources list - Ask the user for service label keys — do not guess.
- Correlate the k6 run window with RED metrics, error logs, traces,
and profiles (Pyroscope — use explicit /
fromfor the run window).to - Hand back specific evidence: timestamps, query strings, panel links.
See for the full flow including
how to verify absence before reporting it.
references/grafana-investigation.md仅当用户拥有后端且具备Grafana访问权限时执行此步骤。
- 通过或
mcp-grafana发现数据源。gcx datasources list - 向用户询问服务标签键——不要猜测。
- 将k6运行时间窗口与RED指标、错误日志、链路追踪和性能分析(Pyroscope——使用明确的/
from指定运行窗口)关联。to - 返回具体证据:时间戳、查询字符串、面板链接。
参考了解完整流程,包括如何在报告前验证问题是否存在。
references/grafana-investigation.md10. Report back
10. 提交报告
Fill in the report template from :
references/reporting.md- Summary — workflows, test types, dates
- SLOs — pass/fail per threshold
- Findings — one paragraph per finding, ordered by severity, with specific evidence
- Evidence — k6 output paths, LG monitor CSVs, cloud run URLs, Grafana links
- Suggested next steps
Always be specific. "Latency is high" is not a finding. "GetPizza
p(95) hit 1.4s at iteration ~200; correlated with sustained 100% CPU
on the recommender service per Grafana panel link" is.
填写中的报告模板:
references/reporting.md- 摘要——工作流、测试类型、日期
- SLO情况——每个阈值的通过/失败状态
- 发现——每个发现对应一段内容,按严重程度排序,附带具体证据
- 证据——k6输出路径、LG监控CSV文件、云端运行URL、Grafana链接
- 建议下一步操作
务必具体。“延迟高”不是有效发现。“GetPizza接口的p(95)延迟在第200次迭代时达到1.4秒;与推荐服务CPU持续100%相关,参考Grafana面板链接”才是有效发现。
Reference index
参考索引
- — verbatim question script for §1.
references/workflow-elicitation.md - — HAR capture, third-party filter regex, hydration signals.
references/recording-with-playwright.md - — 5-step Playwright→k6/browser conversion procedure.
references/functional-tests.md - — protocol + 1 browser VU rationale, duplication argument.
references/hybrid-load-design.md - — full threshold rationale, async vs sync metric capture.
references/slo-design.md - — definitions and defaults for all six test types.
references/test-types.md - — why the sidecar exists, how to read its output.
references/lg-monitoring.md - — framing, cost model, per-test-type tradeoffs.
references/local-vs-cloud.md - — generic backend investigation flow.
references/grafana-investigation.md - — generic pitfalls.
references/gotchas.md - — final report template.
references/reporting.md
- — 第1节使用的逐字提问脚本。
references/workflow-elicitation.md - — HAR捕获、第三方过滤正则、内容渲染信号。
references/recording-with-playwright.md - — Playwright→k6/browser转换的5步流程。
references/functional-tests.md - — 协议+1个浏览器VU的设计理由、代码重复的合理性。
references/hybrid-load-design.md - — 阈值设计的完整理由、异步与同步指标捕获。
references/slo-design.md - — 所有六种测试类型的定义和默认配置。
references/test-types.md - — 侧车存在的原因、如何解读其输出。
references/lg-monitoring.md - — 场景对比、成本模型、每种测试类型的权衡。
references/local-vs-cloud.md - — 通用后端调查流程。
references/grafana-investigation.md - — 常见陷阱。
references/gotchas.md - — 最终报告模板。
references/reporting.md