后端与接口
向 Dynatrace Grail…
当需要把外部合成测试、CI 监控或第三方检查结果发送到 Dynatrace Grail 时,用平台事件摄取 API 发送 external_test_run / external_test_step 事件。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 59/100 ×0.15
适用场景
向 Dynatrace Grail 摄取特定
解决思路
- 使用平台事件摄取 API:POST /platform/ingest/custom/events/{endpoint},事件进入 Grail 后由 OpenPipeline 处理(提取 external.test.availability、external.test.duration 指标,注册 EXT_TEST Smartscape 节点,并为 step 事件添加 result.status.category)。
- 事件分为两类:external_test_run(一次测试执行的整体通过/失败结果)和 external_test_step(该次运行中的单个步骤,可选,用于步骤级指标)。
- 认证使用两种 token 之一:Classic Api-Token 需要 openpipeline.events.custom 作用域;Platform Token / OAuth 需要 openpipeline:events.custom:ingest 作用域。注意 events.ingest 不可用。
- 发送前需先在 OpenPipeline 中创建摄取端点;external.tests 端点由默认的 Dynatrace 3rd-party monitors Monaco bundle 自动提供。
- 用 curl 发送最小测试结果:POST 到 https://{env-id}.live.dynatrace.com/platform/ingest/custom/events/external.tests,带 Authorization: Api-Token {token} 和 Content-Type: application/json,body 为包含 event.kind、event.type、test.id、test.run.id、test.name、test.type、test.run.status、test.run.availability、test.run.duration_ms、test.run.location、dt.security_context、timestamp 的 JSON 数组。预期返回 HTTP 200(空 body)。
- 发送后用 DQL 验证:fetch events, from:now()-1h | filter event.type == "external_test_run" | fields timestamp, test.id, test.name, test.run.status, test.run.duration_ms, test.run.location | sort timestamp desc | limit 20。
- body 必须是 JSON 数组([{...}]),不能是对象包装({"events":[...]})。
- 单个请求可以在同一数组中混合 run 事件和 step 事件。
- timestamp 必须是 ISO 8601 UTC 格式(如 "2024-01-15T10:30:00Z")。
- test.run.availability 必须是整数 1 或 0,不能是字符串。
- 一次运行中的所有 step 事件必须与父 run 事件共享相同的 test.run.id 和 test.id。
- step 事件除 test.run.id 外还必须包含 test.step.id(在本次运行内唯一)。
- 必须包含 event.kind: "EXTERNAL_TEST_EVENT"(Grail 用于事件分类);路由到正确 pipeline 由 event.type 决定,而非 event.kind。
- 不要发送 dt.smartscape.ext_test 或 result.status.category——这些由 pipeline 在摄取后写入,若包含会被覆盖。
- 建议在每个事件上设置 dt.security_context,以启用按团队的数据访问控制和多团队租户中的成本归因。
- 多位置测试:从多个位置发送相同的 test.id,每个位置使用不同的 test.run.location 值;OpenPipeline 为每个 test.id 创建一个 EXT_TEST 节点,并为每个 (test.id, location) 对创建一个可用性指标时间序列。
- 多位置测试可实现两级告警:本地故障(单个位置可用性下降,按位置时间序列)和全局故障(所有位置的平均值低于阈值)。例如 3 位置测试:1 个失败 → 平均 0.67(0.5 阈值下不告警);2 个失败 → 平均 0.33(触发);3 个全失败 → 平均约 0(立即触发)。
- 在所有位置保持 test.id 稳定# 更改它会创建新的 Smartscape 节点并破坏指标历史。
适用边界 · 注意事项
- 不适用于 Dynatrace 原生的 Synthetic Monitoring 浏览器/HTTP 检查或 RUM(应使用 dt-obs-frontends)。
- 若要从已弃用的 POST /api/v1/synthetic/ext/tests API 迁移,应加载 dt-upgrade。
- 未在 OpenPipeline 中创建摄取端点前无法发送事件。