Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(ci): send nightly benchmark alerts to Box instead of Betterstack (#16865)

Amr Elmohamady07243df7507e
diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml
index 2d354b193bd..c0836ba0254 100644
--- a/.github/workflows/benchmark.yml
+++ b/.github/workflows/benchmark.yml
@@ -173,7 +173,8 @@ jobs:
CH_HOST: ${{ secrets.CLICKHOUSE_CI_HOST }}
CH_USER: ${{ secrets.CLICKHOUSE_CI_USER }}
CH_PASS: ${{ secrets.CLICKHOUSE_CI_PASSWORD }}
- BETTERSTACK_WEBHOOK_URL: ${{ secrets.BETTERSTACK_WEBHOOK_URL }}
+ SIGNALS_URL: ${{ secrets.SIGNALS_URL }}
+ SIGNALS_TOKEN: ${{ secrets.SIGNALS_TOKEN }}
run: |
node benchmark/detect-regression.mjs \
--current /tmp/result.json \
@@ -236,21 +237,19 @@ jobs:
if: always()
run: docker compose -f benchmark/docker-compose.yml -f benchmark/docker-compose.ci.yml down -v
- - name: Report pipeline health to Betterstack (scheduled runs only)
- if: '!cancelled() && github.event_name == ''schedule'''
+ - name: Send pipeline failure to Box (scheduled runs only)
+ if: failure() && github.event_name == 'schedule'
env:
- BETTERSTACK_WEBHOOK_URL: ${{ secrets.BETTERSTACK_WEBHOOK_URL }}
- JOB_STATUS: ${{ job.status }}
+ SIGNALS_URL: ${{ secrets.SIGNALS_URL }}
+ SIGNALS_TOKEN: ${{ secrets.SIGNALS_TOKEN }}
LABEL: ${{ matrix.label }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
- if [ "$JOB_STATUS" = "success" ]; then STATE=ok; else STATE=alert; fi
- jq -n --arg cell "$LABEL" --arg state "$STATE" --arg status "$JOB_STATUS" --arg url "$RUN_URL" '{
- name: "Nightly bench pipeline failed: \($cell)",
- cause: "Nightly benchmark job `\($cell)` finished with status `\($status)`.\n\n[Run details →](\($url))",
- alertId: "bench-pipeline-\($cell)",
- state: $state
- }' | curl -sS --fail-with-body -H 'Content-Type: application/json; charset=utf-8' --data-binary @- "$BETTERSTACK_WEBHOOK_URL"
+ jq -n --arg cell "$LABEL" --arg url "$RUN_URL" '{
+ service: "nightly-benchmark",
+ fingerprint: "bench-pipeline-\($cell)",
+ message: "Nightly benchmark job `\($cell)` failed before producing a trustworthy result: \($url)\n\nRead the failed step logs with `gh run view --log-failed`, find whether the cause is infrastructure (secrets, ClickHouse auth, runner, docker) or a code change on main that broke the bench flow in benchmark/setup.ts, and fix it if the fix is small. Linear: team SRE, project Stability."
+ }' | curl -sS --fail-with-body -H 'Content-Type: application/json; charset=utf-8' -H "Authorization: Bearer $SIGNALS_TOKEN" --data-binary @- "$SIGNALS_URL"
summary:
runs-on: ubuntu-latest
diff --git a/benchmark/detect-regression.mjs b/benchmark/detect-regression.mjs
index 678c6983e8a..987f7aa8cbe 100644
--- a/benchmark/detect-regression.mjs
+++ b/benchmark/detect-regression.mjs
@@ -23,7 +23,8 @@ if (!/^[a-z0-9-]+$/i.test(args.label)) {
const THRESHOLD_PCT = Number(args.threshold ?? 5)
const CONSECUTIVE = Number(args.consecutive ?? 2)
-const WEBHOOK_URL = process.env.BETTERSTACK_WEBHOOK_URL
+const SIGNALS_URL = process.env.SIGNALS_URL
+const SIGNALS_TOKEN = process.env.SIGNALS_TOKEN
const CH_HOST = process.env.CH_HOST
const CH_USER = process.env.CH_USER
const CH_PASS = process.env.CH_PASS
@@ -86,50 +87,50 @@ if (history.length < MIN_HISTORY) {
process.exit(0)
}
-const ALERT_ID = `bench-regression-${args.label}`
-
if (breaches.length === 0) {
console.error(`No regressions on ${args.label}.`)
- if (!WEBHOOK_URL) process.exit(0)
- await postToBetterstack({
- name: `Bench regression: ${args.label}`,
- cause: `No regressions on \`${args.label}\` (${results.length} dimensions all within ${THRESHOLD_PCT}% of trailing-14 median).\n\n[Run details →](${args.runUrl})`,
- alertId: ALERT_ID,
- state: 'ok',
- })
process.exit(0)
}
-if (!WEBHOOK_URL) {
- console.error(`BREACH on ${args.label} but BETTERSTACK_WEBHOOK_URL unset — skipping alert.`)
+if (!SIGNALS_URL || !SIGNALS_TOKEN) {
+ console.error(`BREACH on ${args.label} but SIGNALS_URL / SIGNALS_TOKEN unset — skipping signal.`)
process.exit(0)
}
-const lines = breaches.map((b) => `- **${b.name}**: ${b.currentValue.toFixed(2)} ${b.unit} (baseline ${b.baseline.toFixed(2)}, +${b.pct.toFixed(1)}%)`)
-const cause = `Benchmark regression on \`${args.label}\` — ${breaches.length} dimension(s) above ${THRESHOLD_PCT}% for ${CONSECUTIVE} consecutive runs:\n\n${lines.join('\n')}\n\n[Run details →](${args.runUrl})\n\nSHA: \`${current.meta.sha}\``
-
-await postToBetterstack({
- name: `Bench regression: ${args.label}`,
- cause,
- alertId: ALERT_ID,
- state: 'alert',
+const lines = breaches.map((b) => `- ${b.name}: ${b.currentValue.toFixed(2)} ${b.unit} (baseline ${b.baseline.toFixed(2)}, +${b.pct.toFixed(1)}%)`)
+const historyRows = history.map((h) => `${h.meta.ts} ${h.meta.sha} ${DIMENSIONS.map((d) => `${d.name}=${d.get(h)}`).join(' ')}`)
+
+await sendBoxSignal({
+ service: 'nightly-benchmark',
+ fingerprint: `bench-regression-${args.label}`,
+ message: [
+ `Nightly benchmark regression on the \`${args.label}\` worker shape: ${breaches.length} metric(s) more than ${THRESHOLD_PCT}% worse than the trailing-14 median for ${CONSECUTIVE} runs in a row.`,
+ '',
+ ...lines,
+ '',
+ `Current SHA: ${current.meta.sha}`,
+ `Run: ${args.runUrl}`,
+ '',
+ 'Find the commit that caused this. The stack field lists the trailing runs oldest first with their SHA; the first run where the breached metrics step up brackets the culprit between its SHA and the previous one. Run `git log <prev>..<first-bad>` and read the diffs that touch packages/server, packages/core or benchmark/. The bench flow is built in benchmark/setup.ts (webhook trigger, math steps, a CODE step); check whether a commit changed how one of those executes. In the report give the culprit commit, why it costs this much, and whether it looks intended. Open a PR only if the regression is clearly unintended and the fix is small; this is a performance regression, so no failing test is expected and the next nightly run is the check. Linear: team SRE, project Stability, even when the culprit commit belongs to another team; the benchmark is SRE-owned and SRE decides whether to hand it off.',
+ ].join('\n'),
+ stack: historyRows.join('\n'),
})
-console.error(`Alerted Betterstack on ${breaches.length} dimension(s).`)
+console.error(`Sent Box signal for ${breaches.length} dimension(s).`)
-async function postToBetterstack(payload) {
- const res = await fetch(WEBHOOK_URL, {
+async function sendBoxSignal(payload) {
+ const res = await fetch(SIGNALS_URL, {
method: 'POST',
- headers: { 'Content-Type': 'application/json; charset=utf-8' },
+ headers: { 'Content-Type': 'application/json; charset=utf-8', Authorization: `Bearer ${SIGNALS_TOKEN}` },
body: JSON.stringify(payload),
})
if (!res.ok) {
- console.error(`Betterstack webhook responded ${res.status}: ${await res.text().catch(() => '')}`)
+ console.error(`Box signals API responded ${res.status}: ${await res.text().catch(() => '')}`)
process.exit(1)
}
}
async function fetchHistory({ label }) {
- const sql = `SELECT p50_ms, p90_ms, p99_ms, mean_ms, req_sec, queue_p90_ms, service_p90_ms, provision_p50_ms, boot_p50_ms, app_cpu_p95, app_mem_max_mb, worker_cpu_p95, worker_mem_max_mb FROM bench.results WHERE label = '${label}' ORDER BY ts DESC LIMIT 14 FORMAT JSONEachRow`
+ const sql = `SELECT toString(ts) AS ts, sha, p50_ms, p90_ms, p99_ms, mean_ms, req_sec, queue_p90_ms, service_p90_ms, provision_p50_ms, boot_p50_ms, app_cpu_p95, app_mem_max_mb, worker_cpu_p95, worker_mem_max_mb FROM bench.results WHERE label = '${label}' ORDER BY ts DESC LIMIT 14 FORMAT JSONEachRow`
const url = `https://${CH_HOST}:8443/?query=${encodeURIComponent(sql)}`
const auth = Buffer.from(`${CH_USER}:${CH_PASS}`).toString('base64')
const res = await fetch(url, { headers: { Authorization: `Basic ${auth}` } })
@@ -144,6 +145,7 @@ async function fetchHistory({ label }) {
function toResultShape(row) {
return {
+ meta: { ts: row.ts, sha: row.sha },
latency: { p50Ms: row.p50_ms, p90Ms: row.p90_ms, p99Ms: row.p99_ms, meanMs: row.mean_ms },
throughput: { reqSec: row.req_sec },
timeline: {
diff --git a/docs/handbook/engineering/playbooks/alerts.mdx b/docs/handbook/engineering/playbooks/alerts.mdx
index 78cc54cded7..32fd3908133 100644
--- a/docs/handbook/engineering/playbooks/alerts.mdx
+++ b/docs/handbook/engineering/playbooks/alerts.mdx
@@ -20,9 +20,10 @@ Runs that run out of memory end with status `MEMORY_LIMIT_EXCEEDED`. They are no
The `Benchmark` GitHub Actions workflow (`.github/workflows/benchmark.yml`) runs every night at 03:00 UTC, once per worker shape (`shared` and `dedicated`).
- **Results:** each scheduled run stores one row per shape in ClickHouse. The **Nightly Benchmark** dashboard in HyperDX charts throughput, latency, queue wait and worker resources over time.
-- **Regression alert:** `benchmark/detect-regression.mjs` compares the run with the median of the last 14 runs and alerts Betterstack when a metric is more than 5% worse on 2 runs in a row. It stays silent until a shape has 3 runs of history.
-- **Pipeline alert:** on scheduled runs only, the job's last step opens a `bench-pipeline-<shape>` alert in Betterstack when anything in the job failed, and resolves it on the next green scheduled run.
+- **Regression alert:** `benchmark/detect-regression.mjs` compares the run with the median of the last 14 runs and, when a metric is more than 5% worse on 2 runs in a row, sends a signal to Box's Errors API, which starts a Claude agent to find the culprit commit. The signal carries its own investigation prompt and the trailing runs with their SHAs. It stays silent until a shape has 3 runs of history.
+- **Pipeline alert:** on scheduled runs only, when anything in the job fails, its last step sends a `bench-pipeline-<shape>` signal to Box so an agent reads the failed logs.
+- **Dedup:** Box groups signals by fingerprint (`bench-regression-<shape>`, `bench-pipeline-<shape>`), so a regression that persists starts one agent, not one per night. Resolve the Box issue once the fix has shipped. An accepted regression stays open until the 14-run baseline absorbs it (about 7 nights), then gets resolved; resolving earlier reopens it and starts a new agent. Never ignore a bench issue: ignored issues never start an agent, so that shape would go silent for good.
<Warning>
-Manual runs (`workflow_dispatch`) skip the ClickHouse writes and both Betterstack alert steps. A green manual run does not prove these steps work or resolve an existing pipeline alert. Check the next scheduled run after changing them or their secrets.
+Manual runs (`workflow_dispatch`) skip the ClickHouse writes and both Box signal steps. A green manual run does not prove these steps work. Check the next scheduled run after changing them or their secrets.
</Warning>