k6-docs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Grafana 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:
Common API reference URLs:
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:
常用API参考URL:
使用模式:
结合合适的文档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:
  1. Start broad: Use WebSearch to find relevant documentation pages
    • Example: "k6 load testing custom metrics documentation"
  2. Then go specific: Use WebFetch on the most relevant documentation URL
  3. For API methods: Navigate to the JavaScript API section
  4. For how-to guides: Check the "Using k6" section
搜索特定k6功能时:
  1. 先宽泛搜索:使用WebSearch查找相关文档页面
    • 示例:"k6负载测试自定义指标文档"
  2. 再精准获取:对最相关的文档URL使用WebFetch
  3. API方法查询:进入JavaScript API板块
  4. 操作指南查询:查看"Using k6"板块

4. Key k6 Concepts

4. k6核心概念

Test lifecycle:
  • init
    context: Load-time code (imports, options)
  • setup()
    : Runs once before tests
  • default function()
    : VU code, runs repeatedly
  • teardown()
    : Runs once after tests
Load options:
  • vus
    : Number of virtual users
  • duration
    : Test duration
  • iterations
    : Total iterations across all VUs
  • stages
    : Ramping pattern
  • thresholds
    : Pass/fail criteria
HTTP methods:
  • http.get()
    ,
    http.post()
    ,
    http.put()
    ,
    http.delete()
  • http.batch()
    for parallel requests
Checks vs Thresholds:
  • check()
    : Validates conditions, doesn't stop test
  • thresholds
    : Define pass/fail criteria, can abort test
测试生命周期:
  • init
    上下文:加载阶段代码(导入、配置选项)
  • setup()
    :测试开始前运行一次
  • default function()
    :VU代码,重复运行
  • teardown()
    :测试结束后运行一次
负载配置选项:
  • vus
    :虚拟用户数量
  • duration
    :测试时长
  • iterations
    :所有VU的总迭代次数
  • stages
    :负载渐变模式
  • thresholds
    :测试通过/失败的判定标准
HTTP方法:
  • http.get()
    ,
    http.post()
    ,
    http.put()
    ,
    http.delete()
  • http.batch()
    用于并行请求
检查与阈值的区别:
  • check()
    :验证条件,不会终止测试
  • thresholds
    :定义通过/失败标准,可终止测试

Workflow

工作流程

  1. Identify the need: Determine what k6 functionality is required
  2. Search documentation: Use WebSearch or directly access known doc URLs
  3. Fetch specific pages: Use WebFetch to get detailed information
  4. Implement code: Write k6 test code based on documentation
  5. Validate: Check against examples and best practices in docs
  1. 明确需求:确定所需的k6功能
  2. 搜索文档:使用WebSearch或直接访问已知文档URL
  3. 获取具体页面:使用WebFetch获取详细信息
  4. 编写代码:根据文档编写k6测试代码
  5. 验证:对照文档中的示例和最佳实践进行检查

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
    /latest/
    with the specific version number
  • k6 documentation is comprehensive and well-organized; use the table of contents for navigation
  • 此技能未本地存储k6文档,而是在线获取最新版本
  • 始终验证获取的文档是否为最新版本,检查URL中是否包含
    /latest/
  • 如需特定版本的文档,将
    /latest/
    替换为具体版本号
  • k6文档全面且结构清晰,可通过目录进行导航