Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix metric status
Thiago Araujo da Silva682d5d1d856b
diff --git a/backend/src/lib/telemetry/metrics.ts b/backend/src/lib/telemetry/metrics.tsindex e22f097b04..7a9007b6ac 100644--- a/backend/src/lib/telemetry/metrics.ts+++ b/backend/src/lib/telemetry/metrics.ts@@ -603,8 +603,13 @@ export const recordDynamicSecretOrphanedLeaseMetric = (params: { provider: strin};export enum AlertDispatchOutcome {- // Notifications were dispatched to at least one channel.- Dispatched = "dispatched",+ // Every channel the run touched delivered.+ DeliverySuccess = "delivery_success",+ // Some channels delivered and at least one did not, so a notification was dropped on the failed+ // channels only. Dedup is per (channel, target), so the next run retries just those channels.+ DeliveryPartial = "delivery_partial",+ // No channel delivered: the whole run dropped.+ DeliveryFailed = "delivery_failed",// The alert row is gone by the time the job runs: deleted, or its project soft-deleted.AlertNotFound = "alert_not_found",// The alert still exists but was disabled between being enqueued and the job running.@@ -621,7 +626,7 @@ export enum AlertDispatchOutcome {export const alertDispatchOutcomeCounter = infisicalCoreMeter.createCounter("infisical.alert.dispatch.outcome.count", {description:- "Alert dispatch jobs by alert resource type and outcome. Watch dispatched / total: a persistently low ratio means the cron is enqueueing mostly no-op jobs and should pre-filter instead.",+ "Alert dispatch jobs by alert resource type and outcome. Alarm on delivery_failed + delivery_partial: both mean a channel could not be reached, so a notification was dropped. Watch the delivery_* share of total separately: a persistently low ratio means the cron is enqueueing mostly no-op jobs and should pre-filter instead.",unit: "{job}"});diff --git a/backend/src/services/alert/alert-engine.test.ts b/backend/src/services/alert/alert-engine.test.tsindex 00adfff308..b35d18f1b6 100644--- a/backend/src/services/alert/alert-engine.test.ts+++ b/backend/src/services/alert/alert-engine.test.ts@@ -187,7 +187,7 @@ describe("alert engine", () => {const outcome = await engine.runAlert(makeAlert());- expect(outcome).toBe(AlertDispatchOutcome.Dispatched);+ expect(outcome).toBe(AlertDispatchOutcome.DeliverySuccess);expect(sentMail).toHaveLength(1);expect(sentMail[0].recipients).toEqual(["[email protected]"]);expect(historyWrites).toHaveLength(1);@@ -269,8 +269,10 @@ describe("alert engine", () => {failEmail: true});- await engine.runAlert(makeAlert());+ const outcome = await engine.runAlert(makeAlert());+ // The run must not report success: a dropped notification has to be visible in telemetry.+ expect(outcome).toBe(AlertDispatchOutcome.DeliveryFailed);expect(sentMail).toHaveLength(0);expect(historyWrites).toHaveLength(1);expect(historyWrites[0].status).toBe(AlertRunStatus.FAILED);@@ -279,6 +281,31 @@ describe("alert engine", () => {]);});+ test("reports a partial run distinctly so one broken channel is not masked by a healthy one", async () => {+ const { engine, historyWrites } = buildEngine({+ targets: [{ id: "t1" }],+ channels: [+ { id: "c-email", channelType: "email", encryptedConfig: encConfig({}), enabled: true },+ {+ id: "c-slack",+ channelType: "slack",+ encryptedConfig: encConfig({ webhookUrl: "https://hooks.slack.com/services/x" }),+ enabled: true+ }+ ],+ failEmail: true+ });++ const outcome = await engine.runAlert(makeAlert());++ expect(outcome).toBe(AlertDispatchOutcome.DeliveryPartial);+ expect(historyWrites[0].status).toBe(AlertRunStatus.PARTIAL);+ expect(historyWrites[0].deliveries).toEqual([+ { targetId: "t1", channelId: "c-email", channelType: "email", status: AlertRunStatus.FAILED },+ { targetId: "t1", channelId: "c-slack", channelType: "slack", status: AlertRunStatus.SUCCESS }+ ]);+ });+test("marks a directed channel SUCCESS when at least one recipient delivers, so healthy recipients are not re-spammed", async () => {const { engine, sentMail, historyWrites } = buildEngine({targets: [{ id: "t1" }],@@ -309,8 +336,9 @@ describe("alert engine", () => {recipients: [] // group emptied / user deleted at runtime});- await engine.runAlert(makeAlert());+ const outcome = await engine.runAlert(makeAlert());+ expect(outcome).toBe(AlertDispatchOutcome.DeliveryFailed);// No send is attempted with an undefined recipient.expect(sentMail).toHaveLength(0);expect(historyWrites).toHaveLength(1);diff --git a/backend/src/services/alert/alert-engine.ts b/backend/src/services/alert/alert-engine.tsindex db54b11281..d0215c0176 100644--- a/backend/src/services/alert/alert-engine.ts+++ b/backend/src/services/alert/alert-engine.ts@@ -213,7 +213,10 @@ export const alertEngineFactory = ({await alertHistoryDAL.createWithTargets(alert.id, { status }, deliveries);- return AlertDispatchOutcome.Dispatched;+ if (status === AlertRunStatus.SUCCESS) return AlertDispatchOutcome.DeliverySuccess;+ return status === AlertRunStatus.PARTIAL+ ? AlertDispatchOutcome.DeliveryPartial+ : AlertDispatchOutcome.DeliveryFailed;};return { runAlert };