k6-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrafana k6 Documentation Access
Grafana k6 文档访问
Overview
概述
This skill enables access to the latest official Grafana k6 documentation for writing and debugging load testing scripts. k6 is a modern load testing tool built for performance testing APIs, microservices, and websites.
此技能可帮助您访问最新的官方Grafana k6文档,用于编写和调试负载测试脚本。k6是一款现代化的负载测试工具,专为API、微服务和网站的性能测试而设计。
When to Use This Skill
适用场景
Use this skill when:
- Writing new k6 load testing scripts
- Debugging existing k6 test code
- Looking up k6 API methods and their parameters
- Understanding k6 test lifecycle hooks
- Learning about k6 metrics and thresholds
- Implementing k6 checks and custom metrics
- Using k6 extensions or modules
- Troubleshooting k6 test execution issues
在以下场景中使用此技能:
- 编写新的k6负载测试脚本
- 调试现有的k6测试代码
- 查询k6 API方法及其参数
- 了解k6测试生命周期钩子
- 学习k6指标与阈值相关知识
- 实现k6检查与自定义指标
- 使用k6扩展或模块
- 排查k6测试执行问题
Core Capabilities
核心能力
1. Documentation Access
1. 文档访问
Access the latest k6 documentation using the WebFetch tool:
Primary documentation URLs:
- Main documentation: https://grafana.com/docs/k6/latest/
- JavaScript API: https://grafana.com/docs/k6/latest/javascript-api/
- Examples: https://grafana.com/docs/k6/latest/examples/
- Using k6: https://grafana.com/docs/k6/latest/using-k6/
Common API reference URLs:
- HTTP requests: https://grafana.com/docs/k6/latest/javascript-api/k6-http/
- Checks: https://grafana.com/docs/k6/latest/javascript-api/k6/check/
- Metrics: https://grafana.com/docs/k6/latest/javascript-api/k6-metrics/
- Thresholds: https://grafana.com/docs/k6/latest/using-k6/thresholds/
- Options: https://grafana.com/docs/k6/latest/using-k6/k6-options/
- Execution contexts: https://grafana.com/docs/k6/latest/using-k6/test-lifecycle/
Usage pattern:
Use WebFetch with the appropriate documentation URL and a focused prompt like:
- "Show me the API reference for http.post method"
- "Explain how to use checks in k6"
- "Show examples of custom metrics"通过WebFetch工具访问最新的k6文档:
主要文档URL:
- 主文档:https://grafana.com/docs/k6/latest/
- JavaScript API:https://grafana.com/docs/k6/latest/javascript-api/
- 示例:https://grafana.com/docs/k6/latest/examples/
- 使用指南:https://grafana.com/docs/k6/latest/using-k6/
常用API参考URL:
- HTTP请求:https://grafana.com/docs/k6/latest/javascript-api/k6-http/
- 检查:https://grafana.com/docs/k6/latest/javascript-api/k6/check/
- 指标:https://grafana.com/docs/k6/latest/javascript-api/k6-metrics/
- 阈值:https://grafana.com/docs/k6/latest/using-k6/thresholds/
- 配置选项:https://grafana.com/docs/k6/latest/using-k6/k6-options/
- 执行上下文:https://grafana.com/docs/k6/latest/using-k6/test-lifecycle/
使用模式:
结合合适的文档URL和针对性提示使用WebFetch:
- "展示http.post方法的API参考"
- "解释如何在k6中使用检查功能"
- "展示自定义指标的示例"2. Common k6 Patterns
2. 常见k6代码模式
Basic HTTP GET test:
javascript
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}HTTP POST with JSON:
javascript
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const url = 'https://httpbin.test.k6.io/post';
const payload = JSON.stringify({
name: 'test',
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
const res = http.post(url, payload, params);
check(res, {
'status is 200': (r) => r.status === 200,
});
}基础HTTP GET测试:
javascript
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}带JSON的HTTP POST请求:
javascript
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const url = 'https://httpbin.test.k6.io/post';
const payload = JSON.stringify({
name: 'test',
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
const res = http.post(url, payload, params);
check(res, {
'status is 200': (r) => r.status === 200,
});
}3. Documentation Search Strategy
3. 文档搜索策略
When searching for specific k6 functionality:
-
Start broad: Use WebSearch to find relevant documentation pages
- Example: "k6 load testing custom metrics documentation"
-
Then go specific: Use WebFetch on the most relevant documentation URL
- Example: WebFetch https://grafana.com/docs/k6/latest/javascript-api/k6-metrics/
-
For API methods: Navigate to the JavaScript API section
- Base URL: https://grafana.com/docs/k6/latest/javascript-api/
- Module-specific: https://grafana.com/docs/k6/latest/javascript-api/k6-http/
-
For how-to guides: Check the "Using k6" section
搜索特定k6功能时:
-
先宽泛搜索:使用WebSearch查找相关文档页面
- 示例:"k6负载测试自定义指标文档"
-
再精准获取:对最相关的文档URL使用WebFetch
-
API方法查询:进入JavaScript API板块
-
操作指南查询:查看"Using k6"板块
4. Key k6 Concepts
4. k6核心概念
Test lifecycle:
- context: Load-time code (imports, options)
init - : Runs once before tests
setup() - : VU code, runs repeatedly
default function() - : Runs once after tests
teardown()
Load options:
- : Number of virtual users
vus - : Test duration
duration - : Total iterations across all VUs
iterations - : Ramping pattern
stages - : Pass/fail criteria
thresholds
HTTP methods:
- ,
http.get(),http.post(),http.put()http.delete() - for parallel requests
http.batch()
Checks vs Thresholds:
- : Validates conditions, doesn't stop test
check() - : Define pass/fail criteria, can abort test
thresholds
测试生命周期:
- 上下文:加载阶段代码(导入、配置选项)
init - :测试开始前运行一次
setup() - :VU代码,重复运行
default function() - :测试结束后运行一次
teardown()
负载配置选项:
- :虚拟用户数量
vus - :测试时长
duration - :所有VU的总迭代次数
iterations - :负载渐变模式
stages - :测试通过/失败的判定标准
thresholds
HTTP方法:
- ,
http.get(),http.post(),http.put()http.delete() - 用于并行请求
http.batch()
检查与阈值的区别:
- :验证条件,不会终止测试
check() - :定义通过/失败标准,可终止测试
thresholds
Workflow
工作流程
- Identify the need: Determine what k6 functionality is required
- Search documentation: Use WebSearch or directly access known doc URLs
- Fetch specific pages: Use WebFetch to get detailed information
- Implement code: Write k6 test code based on documentation
- Validate: Check against examples and best practices in docs
- 明确需求:确定所需的k6功能
- 搜索文档:使用WebSearch或直接访问已知文档URL
- 获取具体页面:使用WebFetch获取详细信息
- 编写代码:根据文档编写k6测试代码
- 验证:对照文档中的示例和最佳实践进行检查
Best Practices
最佳实践
- Always check the latest documentation URL structure (grafana.com/docs/k6/latest/)
- For complex scenarios, look for examples in the Examples section
- When troubleshooting, check both the API reference and the Using k6 guides
- Use WebSearch first if unsure which documentation page to fetch
- Reference multiple documentation pages if implementing complex features
- 始终检查最新的文档URL结构(grafana.com/docs/k6/latest/)
- 复杂场景下,查看示例板块中的相关案例
- 排查问题时,同时参考API参考和使用指南
- 若不确定要获取哪个文档页面,先使用WebSearch
- 实现复杂功能时,参考多个文档页面
Common Documentation Sections
常见文档板块
Notes
注意事项
- This skill does not bundle k6 documentation locally; it fetches the latest version online
- Always verify that fetched documentation is current by checking the URL includes
/latest/ - For version-specific documentation, replace with the specific version number
/latest/ - k6 documentation is comprehensive and well-organized; use the table of contents for navigation
- 此技能未本地存储k6文档,而是在线获取最新版本
- 始终验证获取的文档是否为最新版本,检查URL中是否包含
/latest/ - 如需特定版本的文档,将替换为具体版本号
/latest/ - k6文档全面且结构清晰,可通过目录进行导航