关于 testing
Grafana Cloud Testing 技能面向测试和可观测性团队,涵盖 Synthetic Monitoring 外部探测、k6 Cloud 负载测试和 Faro 前端监控。
主要功能
- 01创建和验证 Synthetic HTTP 检查
- 02运行 k6 Cloud 负载测试
- 03使用 Faro 采集前端事件
- 04查看检查指标和告警规则
- 05排查探测、测试和事件问题
适用场景
- 01验证网站端点的可用性
- 02在云端运行负载测试
- 03检查前端会话、事件与链路
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ grafana/ skills --skill testing安装后在 Claude Code 中输入/testing确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/k6-and-faro.mdk6-cloud.mdsynthetic-monitoring.mdsynthetic.md详细介绍
Grafana Cloud 测试
三大支柱:外部探测(Synthetic Monitoring)、负载测试(k6 Cloud)和真实用户监控(Faro)。
前提条件
- Grafana Cloud 堆栈
- Synthetic Monitoring:SM 访问令牌(
sm:write) - k6 Cloud:Grafana Cloud k6 令牌 + projectID
- Faro:Faro 应用 + 写入令牌,位于 Frontend Observability → Apps
常见工作流
1. 创建并验证 Synthetic HTTP 检查
# 1. Create the check (full payload in references/synthetic.md)
curl -X POST https://synthetic-monitoring-api.grafana.net/sm/checks \
-H "Authorization: Bearer <sm-token>" -H "Content-Type: application/json" \
-d '{"job":"website","target":"https://example.com","frequency":60000,"timeout":15000,
"enabled":true,"probes":[1,5,10],
"settings":{"http":{"method":"GET","validStatusCodes":[200]}}}'
# 2. List checks — confirm it exists and is enabled
curl -s https://synthetic-monitoring-api.grafana.net/sm/checks \
-H "Authorization: Bearer <sm-token>" | jq '.[] | select(.job=="website")'
# 3. Verify probe_success arrived (wait ~60s for the first run)
# In Grafana Explore on the synthetic metrics datasource:
# probe_success{job="website"}
# Expect 1 from each probe in `probes:[1,5,10]`.
#
# Rollback: DELETE /sm/checks/<id> or set `"enabled": false`.
所有检查类型、PromQL 查询和告警规则,请参阅 references/synthetic.md。
2. 运行 k6 云端负载测试
# 1. Authenticate once
k6 cloud login --token <grafana-cloud-k6-token>
# 2. Validate the script locally first (smoke run, no cloud cost)
k6 run --vus 1 --duration 30s script.js
# 3. Launch in cloud
k6 cloud script.js
# → URL of the run; thresholds (p95<500ms, error<1%) decide pass/fail.
# 4. Verify in CI — exit code 0 = thresholds passed, 99 = threshold failed.
echo $?
完整脚本 + 场景 + CI YAML:references/k6-and-faro.md。
3. 使用 Faro 为前端添加监测
# 1. Install
npm install @grafana/faro-web-sdk @grafana/faro-web-tracing
// 2. initializeFaro({ url, apiKey, app, instrumentations }) — see references/k6-and-faro.md
// 3. Push a test event so we have something to look for:
faro.api.pushEvent('faro_smoketest', { ts: Date.now().toString() });
# 4. Verify the collector accepted it (browser DevTools → Network)
# POST to /collect should return 202. If 401 — apiKey mismatch.
# 5. Verify in Grafana
# - Frontend Observability → your app → Sessions: should show your session
# - Explore on Loki: `{kind="event"} |= "faro_smoketest"`
# - For traces: filter by `service.name="my-frontend"` in Tempo
故障排查
- Synthetic 检查卡在
probe_success=0→ 检查失败阶段对应的probe_*_duration_seconds;探测区域标签会指出出错的探测器 - k6 云端运行显示“ABORTED_THRESHOLD” → 某个阈值已触发;检查运行页面以查看触发的是哪个阈值
- Faro 事件未送达 → 检查浏览器向
/collect发出的网络请求是否返回 202;常见原因是apiKey或url不正确(必须与 FE Observability 应用匹配)
参考资料
- 如需深入了解 Synthetic Monitoring 脚本(k6)和浏览器检查的编写——包括执行模型、断言、机密信息以及 API/Terraform 负载——请参阅
synthetic-monitoring-checks技能 references/synthetic.md— Synthetic Monitoring 基础知识:检查类型、关键 PromQL 指标和告警规则references/synthetic-monitoring.md— 深入介绍:检查 CRUD 的完整 API、探测器选择、脚本(k6)检查和多步骤浏览器检查references/k6-and-faro.md— 用于端到端测试的 k6 云端脚本 + Faro Web SDK 初始化代码片段references/k6-cloud.md— 深入介绍:k6 云端配置(项目 + 负载区域 + 阈值)、CI 集成和运行分析
资源
评论
支持 Markdown