diff --git a/infra/monitoring.ts b/infra/monitoring.ts index 26ba573a07..908078ba19 100644 --- a/infra/monitoring.ts +++ b/infra/monitoring.ts @@ -169,3 +169,38 @@ new honeycomb.Trigger("IncreasedProviderHttpErrorsZen", { }, ], }) + +new honeycomb.Trigger("IncreasedFreeTierRequests", { + disabled: true, + name: "Increased Free Tier Requests", + description, + queryJson: honeycomb.getQuerySpecificationOutput({ + calculations: [ + { + op: "COUNT", + name: "REQUESTS", + filterCombination: "AND", + filters: [ + { column: "event_type", op: "=", value: "completions" }, + { column: "user_agent", op: "contains", value: "opencode" }, + { column: "isFreeTier", op: "=", value: "true" }, + ], + }, + ], + timeRange: 14400, + }).json, + alertType: "on_change", + frequency: 3600, + thresholds: [{ op: ">=", value: 50, exceededLimit: 2 }], + baselineDetails: [{ type: "percentage", offsetMinutes: 1440 }], + recipients: [ + { + id: webhookRecipient.id, + notificationDetails: [ + { + variables: [{ name: "type", value: "custom" }], + }, + ], + }, + ], +}) diff --git a/packages/console/app/src/routes/honeycomb/webhook.ts b/packages/console/app/src/routes/honeycomb/webhook.ts index b4d5e4bf7e..367a93aeb0 100644 --- a/packages/console/app/src/routes/honeycomb/webhook.ts +++ b/packages/console/app/src/routes/honeycomb/webhook.ts @@ -23,15 +23,19 @@ const honeycombWebhookPayload = z.discriminatedUnion("type", [ type: z.literal("provider_http_errors"), groups, }), + basePayload.extend({ + type: z.literal("custom"), + }), ]) const postDiscordMessage = async (payload: z.infer) => { - const group = payload.type === "model_http_errors" ? "model" : "provider" - const names = (payload.groups ?? []).flatMap((item) => item.group.map((g) => g.value)) + const group = + payload.type === "model_http_errors" ? "model" : payload.type === "provider_http_errors" ? "provider" : undefined + const names = payload.type === "custom" ? [] : payload.groups.flatMap((item) => item.group.map((g) => g.value)) const content = [ `[**${payload.isTest ? "[TEST] " : ""}${payload.name ?? "Honeycomb alert"}**](${payload.url})`, - names.length > 0 ? `Affected ${group}s:` : undefined, + group && names.length > 0 ? `Affected ${group}s:` : undefined, ...names.map((name) => `- ${name}`), "", `<@&${DISCORD_ALERT_ROLE_ID}>`,