🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(monitors): added additional no-data resolution modes (#14171)
Mark Salpeter3900a904f838
diff --git a/packages/shared/src/features/monitors/processor/applyStateMachine.test.ts b/packages/shared/src/features/monitors/processor/applyStateMachine.test.tsindex 9f92bbaae4..208e516310 100644--- a/packages/shared/src/features/monitors/processor/applyStateMachine.test.ts+++ b/packages/shared/src/features/monitors/processor/applyStateMachine.test.ts@@ -1,11 +1,15 @@import { describe, it, expect } from "vitest";import { applyStateMachine } from "./applyStateMachine";-import type {- Monitor,- MonitorNoData,- MonitorRenotify,- MonitorSeverity,+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+ type Monitor,+ type MonitorNoData,+ type MonitorRenotify,+ type MonitorSeverity,} from "../types";/** StateMachineCase is one applyStateMachine transition-table row. */@@ -32,8 +36,13 @@ const t0 = new Date("2026-05-27T12:00:00.000Z");const tMinus2m = new Date("2026-05-27T11:58:00.000Z");const tMinus10m = new Date("2026-05-27T11:50:00.000Z");const tMinus12m = new Date("2026-05-27T11:48:00.000Z");-const noDataSilent: MonitorNoData = { mode: "SILENT" };-const noDataNotify5: MonitorNoData = { mode: "NOTIFY", intervalMinutes: 5 };+const noDataShowNoData: MonitorNoData = {+ mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA,+};+const noDataNotify5: MonitorNoData = {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 5,+};const renotifyOff: MonitorRenotify = { mode: "OFF" };const renotifyEvery5: MonitorRenotify = { mode: "EVERY", intervalMinutes: 5 };@@ -49,18 +58,18 @@ const baseMonitor: Monitor = {filters: [],metric: { measure: "count", aggregation: "count" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },name: "Test",tags: [],triggerIds: [],- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,nextRunAt: null,lastPublishedAt: null,lastClaimedAt: null,@@ -73,17 +82,17 @@ const cases: StateMachineCase[] = [{name: "UNKNOWN -> OK: silent",input: {- prevSeverity: "UNKNOWN",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.UNKNOWN,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: null,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: t0,nextAlertedAt: null,},@@ -91,17 +100,17 @@ const cases: StateMachineCase[] = [{name: "UNKNOWN -> WARNING: emit",input: {- prevSeverity: "UNKNOWN",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.UNKNOWN,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: null,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -109,17 +118,17 @@ const cases: StateMachineCase[] = [{name: "UNKNOWN -> ALERT: emit",input: {- prevSeverity: "UNKNOWN",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.UNKNOWN,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: null,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "ALERT",+ nextSeverity: MonitorSeveritySchema.enum.ALERT,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -127,8 +136,8 @@ const cases: StateMachineCase[] = [{name: "UNKNOWN -> NO_DATA: silent regardless of noData mode",input: {- prevSeverity: "UNKNOWN",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.UNKNOWN,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: null,prevAlertedAt: null,now: t0,@@ -137,7 +146,7 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: null,},@@ -145,28 +154,28 @@ const cases: StateMachineCase[] = [// === NO_DATA -> OK (recovery) ==={- name: "NO_DATA -> OK with noData SILENT: silent",+ name: "NO_DATA -> OK with noData SHOW_NO_DATA: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: t0,nextAlertedAt: null,},},{- name: "NO_DATA -> OK with noData NOTIFY: emit",+ name: "NO_DATA -> OK with noData NOTIFY_NO_DATA: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,@@ -175,7 +184,7 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -183,19 +192,19 @@ const cases: StateMachineCase[] = [// === NO_DATA -> WARNING / ALERT ==={- name: "NO_DATA -> WARNING with noData SILENT: emit",+ name: "NO_DATA -> WARNING with noData SHOW_NO_DATA: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -203,17 +212,17 @@ const cases: StateMachineCase[] = [{name: "NO_DATA -> ALERT: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "ALERT",+ nextSeverity: MonitorSeveritySchema.enum.ALERT,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -221,28 +230,28 @@ const cases: StateMachineCase[] = [// === OK / WARN / ALERT -> NO_DATA ==={- name: "OK -> NO_DATA with noData SILENT: silent",+ name: "OK -> NO_DATA with noData SHOW_NO_DATA: silent",input: {- prevSeverity: "OK",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: tMinus10m,},},{- name: "OK -> NO_DATA with noData NOTIFY and prevAlertedAt past interval: emit",+ name: "OK -> NO_DATA with noData NOTIFY_NO_DATA and prevAlertedAt past interval: emit",input: {- prevSeverity: "OK",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m, // interval 5m elapsednow: t0,@@ -251,16 +260,16 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: t0,},},{- name: "OK -> NO_DATA with noData NOTIFY and prevAlertedAt within interval: silent (cooldown)",+ name: "OK -> NO_DATA with noData NOTIFY_NO_DATA and prevAlertedAt within interval: silent (cooldown)",input: {- prevSeverity: "OK",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus2m, // interval 5m not elapsednow: t0,@@ -269,16 +278,16 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: tMinus2m,},},{- name: "OK -> NO_DATA with noData NOTIFY and prevAlertedAt NULL: emit",+ name: "OK -> NO_DATA with noData NOTIFY_NO_DATA and prevAlertedAt NULL: emit",input: {- prevSeverity: "OK",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,@@ -287,16 +296,16 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: t0,},},{- name: "WARNING -> NO_DATA with noData NOTIFY past interval: emit",+ name: "WARNING -> NO_DATA with noData NOTIFY_NO_DATA past interval: emit",input: {- prevSeverity: "WARNING",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,@@ -305,25 +314,25 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: t0,},},{- name: "ALERT -> NO_DATA with noData SILENT: silent",+ name: "ALERT -> NO_DATA with noData SHOW_NO_DATA: silent",input: {- prevSeverity: "ALERT",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: t0,nextAlertedAt: tMinus10m,},@@ -333,17 +342,17 @@ const cases: StateMachineCase[] = [{name: "OK -> WARNING: emit",input: {- prevSeverity: "OK",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -351,17 +360,17 @@ const cases: StateMachineCase[] = [{name: "OK -> ALERT: emit",input: {- prevSeverity: "OK",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "ALERT",+ nextSeverity: MonitorSeveritySchema.enum.ALERT,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -371,17 +380,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> ALERT: emit",input: {- prevSeverity: "WARNING",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "ALERT",+ nextSeverity: MonitorSeveritySchema.enum.ALERT,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -389,17 +398,17 @@ const cases: StateMachineCase[] = [{name: "ALERT -> WARNING: emit",input: {- prevSeverity: "ALERT",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -409,17 +418,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> OK: emit",input: {- prevSeverity: "WARNING",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -427,17 +436,17 @@ const cases: StateMachineCase[] = [{name: "ALERT -> OK: emit",input: {- prevSeverity: "ALERT",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: true,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: t0,nextAlertedAt: t0,},@@ -447,17 +456,17 @@ const cases: StateMachineCase[] = [{name: "OK -> OK: silent",input: {- prevSeverity: "OK",- computedSeverity: "OK",+ prevSeverity: MonitorSeveritySchema.enum.OK,+ computedSeverity: MonitorSeveritySchema.enum.OK,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: false,- nextSeverity: "OK",+ nextSeverity: MonitorSeveritySchema.enum.OK,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},@@ -467,17 +476,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> WARNING with renotify OFF: silent",input: {- prevSeverity: "WARNING",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},@@ -485,17 +494,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> WARNING with renotify EVERY past interval: emit",input: {- prevSeverity: "WARNING",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m, // interval 5m elapsednow: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: true,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: tMinus10m,nextAlertedAt: t0,},@@ -503,17 +512,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> WARNING with renotify EVERY within interval: silent",input: {- prevSeverity: "WARNING",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus2m, // interval 5m not elapsednow: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: false,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus2m,},@@ -521,17 +530,17 @@ const cases: StateMachineCase[] = [{name: "ALERT -> ALERT with renotify EVERY past interval: emit",input: {- prevSeverity: "ALERT",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: true,- nextSeverity: "ALERT",+ nextSeverity: MonitorSeveritySchema.enum.ALERT,nextSeverityChangedAt: tMinus10m,nextAlertedAt: t0,},@@ -539,44 +548,44 @@ const cases: StateMachineCase[] = [{name: "NO_DATA -> NO_DATA with renotify OFF: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyOff,},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},},{- name: "NO_DATA -> NO_DATA with noData SILENT and renotify EVERY past interval: silent",+ name: "NO_DATA -> NO_DATA with noData SHOW_NO_DATA and renotify EVERY past interval: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},},{- name: "NO_DATA -> NO_DATA with noData NOTIFY and renotify EVERY past interval: emit",+ name: "NO_DATA -> NO_DATA with noData NOTIFY_NO_DATA and renotify EVERY past interval: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,@@ -585,16 +594,16 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: t0,},},{- name: "NO_DATA -> NO_DATA with noData NOTIFY and renotify EVERY within interval: silent",+ name: "NO_DATA -> NO_DATA with noData NOTIFY_NO_DATA and renotify EVERY within interval: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus2m,now: t0,@@ -603,16 +612,16 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus2m,},},{- name: "NO_DATA -> NO_DATA with noData NOTIFY and renotify OFF: silent",+ name: "NO_DATA -> NO_DATA with noData NOTIFY_NO_DATA and renotify OFF: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,@@ -621,16 +630,16 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},},{- name: "NO_DATA -> NO_DATA, NOTIFY, prior-stretch alert predates NO_DATA stretch, interval elapsed: emit",+ name: "NO_DATA -> NO_DATA, NOTIFY_NO_DATA, prior-stretch alert predates NO_DATA stretch, interval elapsed: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus12m,now: t0,@@ -639,16 +648,16 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: t0,},},{- name: "NO_DATA -> NO_DATA, NOTIFY, no prior alert, interval elapsed: emit",+ name: "NO_DATA -> NO_DATA, NOTIFY_NO_DATA, no prior alert, interval elapsed: emit",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,@@ -657,16 +666,16 @@ const cases: StateMachineCase[] = [},expected: {emit: true,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus10m,nextAlertedAt: t0,},},{- name: "NO_DATA -> NO_DATA, NOTIFY, no prior alert, interval not elapsed: silent",+ name: "NO_DATA -> NO_DATA, NOTIFY_NO_DATA, no prior alert, interval not elapsed: silent",input: {- prevSeverity: "NO_DATA",- computedSeverity: "NO_DATA",+ prevSeverity: MonitorSeveritySchema.enum.NO_DATA,+ computedSeverity: MonitorSeveritySchema.enum.NO_DATA,prevSeverityChangedAt: tMinus2m,prevAlertedAt: null,now: t0,@@ -675,7 +684,7 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "NO_DATA",+ nextSeverity: MonitorSeveritySchema.enum.NO_DATA,nextSeverityChangedAt: tMinus2m,nextAlertedAt: null,},@@ -683,17 +692,17 @@ const cases: StateMachineCase[] = [{name: "WARNING -> WARNING with renotify EVERY and prevAlertedAt NULL: silent",input: {- prevSeverity: "WARNING",- computedSeverity: "WARNING",+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ computedSeverity: MonitorSeveritySchema.enum.WARNING,prevSeverityChangedAt: tMinus10m,prevAlertedAt: null,now: t0,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,},expected: {emit: false,- nextSeverity: "WARNING",+ nextSeverity: MonitorSeveritySchema.enum.WARNING,nextSeverityChangedAt: tMinus10m,nextAlertedAt: null,},@@ -702,8 +711,8 @@ const cases: StateMachineCase[] = [{name: "PAUSED -> anything: no-op, preserve PAUSED + prev stamps",input: {- prevSeverity: "PAUSED",- computedSeverity: "ALERT",+ prevSeverity: MonitorSeveritySchema.enum.PAUSED,+ computedSeverity: MonitorSeveritySchema.enum.ALERT,prevSeverityChangedAt: tMinus10m,prevAlertedAt: tMinus10m,now: t0,@@ -712,7 +721,7 @@ const cases: StateMachineCase[] = [},expected: {emit: false,- nextSeverity: "PAUSED",+ nextSeverity: MonitorSeveritySchema.enum.PAUSED,nextSeverityChangedAt: tMinus10m,nextAlertedAt: tMinus10m,},@@ -744,23 +753,23 @@ describe("applyStateMachine", () => {);});- it("ALERT -> OK -> NO_DATA -> NO_DATA with noData SILENT stays silent on the self-loop", () => {+ it("ALERT -> OK -> NO_DATA -> NO_DATA with noData SHOW_NO_DATA stays silent on the self-loop", () => {const tAlert = new Date("2026-05-27T11:40:00.000Z");const tOk = new Date("2026-05-27T11:50:00.000Z");const tNoData = new Date("2026-05-27T11:55:00.000Z");const tLoop = new Date("2026-05-27T12:05:00.000Z");const monitor: Monitor = {...baseMonitor,- noData: noDataSilent,+ noData: noDataShowNoData,renotify: renotifyEvery5,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tAlert,alertedAt: tAlert,};const recovery = applyStateMachine({prev: monitor,- next: { severity: "OK" },+ next: { severity: MonitorSeveritySchema.enum.OK },now: tOk,publishedAt: tOk,});@@ -769,7 +778,7 @@ describe("applyStateMachine", () => {const enterNoData = applyStateMachine({prev: { ...monitor, ...recovery.completion },- next: { severity: "NO_DATA" },+ next: { severity: MonitorSeveritySchema.enum.NO_DATA },now: tNoData,publishedAt: tNoData,});@@ -778,7 +787,7 @@ describe("applyStateMachine", () => {const selfLoop = applyStateMachine({prev: { ...monitor, ...enterNoData.completion },- next: { severity: "NO_DATA" },+ next: { severity: MonitorSeveritySchema.enum.NO_DATA },now: tLoop,publishedAt: tLoop,});diff --git a/packages/shared/src/features/monitors/processor/applyStateMachine.ts b/packages/shared/src/features/monitors/processor/applyStateMachine.tsindex 0507df6540..ddc38d7c6c 100644--- a/packages/shared/src/features/monitors/processor/applyStateMachine.ts+++ b/packages/shared/src/features/monitors/processor/applyStateMachine.ts@@ -1,9 +1,11 @@-import type {- MonitorNoData,- MonitorRenotify,- MonitorSeverity,- MonitorStatus,- Monitor,+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ type MonitorNoData,+ type MonitorRenotify,+ type MonitorSeverity,+ type MonitorStatus,+ type Monitor,} from "../types";/** applyStateMachine maps a monitor's prior row and newly computed severity to its lifecycle writeback and whether to emit an alert. */@@ -16,7 +18,7 @@ export function applyStateMachine(args: {const { prev, next, now, publishedAt } = args;// PAUSED is service-written; no-op so the worker doesn't overwrite user intent.- if (prev.severity === "PAUSED") {+ if (prev.severity === MonitorSeveritySchema.enum.PAUSED) {return {emit: false,completion: {@@ -25,7 +27,7 @@ export function applyStateMachine(args: {lastCompletedAt: now,publishedAt,status: prev.status,- severity: "PAUSED",+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: prev.severityChangedAt,alertedAt: prev.alertedAt,},@@ -70,33 +72,51 @@ function shouldEmit(args: {renotify: MonitorRenotify;}): boolean {// Cold-start: UNKNOWN -> anything. Only unhealthy fires.- if (args.prev === "UNKNOWN") {- return args.next === "WARNING" || args.next === "ALERT";+ if (args.prev === MonitorSeveritySchema.enum.UNKNOWN) {+ return (+ args.next === MonitorSeveritySchema.enum.WARNING ||+ args.next === MonitorSeveritySchema.enum.ALERT+ );}// Recovery from NO_DATA.- if (args.prev === "NO_DATA" && args.next === "OK") {- return args.noData.mode === "NOTIFY";+ if (+ args.prev === MonitorSeveritySchema.enum.NO_DATA &&+ args.next === MonitorSeveritySchema.enum.OK+ ) {+ return args.noData.mode === MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA;}// NO_DATA -> WARNING/ALERT always surfaces.- if (args.prev === "NO_DATA" && args.next !== "NO_DATA") {+ if (+ args.prev === MonitorSeveritySchema.enum.NO_DATA &&+ args.next !== MonitorSeveritySchema.enum.NO_DATA+ ) {return true;}- // Escalation into NO_DATA: NOTIFY mode with cooldown elapsed.- if (args.next === "NO_DATA" && args.prev !== "NO_DATA") {+ // Escalation into NO_DATA: NOTIFY_NO_DATA mode with cooldown elapsed.+ if (+ args.next === MonitorSeveritySchema.enum.NO_DATA &&+ args.prev !== MonitorSeveritySchema.enum.NO_DATA+ ) {return (- args.noData.mode === "NOTIFY" &&+ args.noData.mode === MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA &&passedDelay(args.prevAlertedAt, args.noData.intervalMinutes, args.now));}- // NO_DATA persistence: SILENT never re-emits. NOTIFY fires the first alert+ // NO_DATA persistence: only NOTIFY_NO_DATA re-emits, firing the first alert// after intervalMinutes of sustained NO_DATA (anchored on severityChangedAt- // when no prior alert exists), then re-emits on the renotify cadence.- if (args.prev === "NO_DATA" && args.next === "NO_DATA") {- if (args.noData.mode !== "NOTIFY") return false;+ // when no prior alert exists), then re-emitting on the renotify cadence. A+ // monitor frozen at NO_DATA under LAST_SEVERITY neither re-notifies nor emits+ // on silent recovery.+ if (+ args.prev === MonitorSeveritySchema.enum.NO_DATA &&+ args.next === MonitorSeveritySchema.enum.NO_DATA+ ) {+ if (args.noData.mode !== MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA)+ return false;// An alert from a prior severity stretch doesn't count toward the current// NO_DATA stretch; treat it as cold-start.const stretchAlertedAt =@@ -120,7 +140,7 @@ function shouldEmit(args: {// Self-loops. OK -> OK is the only one that ignores renotify entirely.if (args.prev === args.next) {- if (args.next === "OK") return false;+ if (args.next === MonitorSeveritySchema.enum.OK) return false;// Renotify is a *re*-emit, so a NULL prevAlertedAt is silent.if (args.prevAlertedAt === null) return false;return (diff --git a/packages/shared/src/features/monitors/processor/computeSeverity.test.ts b/packages/shared/src/features/monitors/processor/computeSeverity.test.tsindex 498d874083..029acaba6d 100644--- a/packages/shared/src/features/monitors/processor/computeSeverity.test.ts+++ b/packages/shared/src/features/monitors/processor/computeSeverity.test.ts@@ -1,292 +1,374 @@import { describe, it, expect } from "vitest";import { computeSeverity } from "./computeSeverity";-import type { MonitorThresholdOperator } from "../types";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorThresholdOperatorSchema,+ type MonitorNoData,+ type MonitorSeverity,+ type MonitorThresholdOperator,+} from "../types";/** ComputeSeverityCase is one computeSeverity table row: inputs and the expected severity. */type ComputeSeverityCase = {name: string;input: {- value: number | null;+ value: number;operator: MonitorThresholdOperator;alertThreshold: number;warningThreshold: number | null;};- expected: "NO_DATA" | "OK" | "WARNING" | "ALERT";+ expected: "OK" | "WARNING" | "ALERT";};-/** cases covers the NO_DATA branch plus each operator's alert/warning/OK bands. */-const cases: ComputeSeverityCase[] = [- {- name: "null value -> NO_DATA (with warning)",- input: {- value: null,- operator: "GT",- alertThreshold: 100,- warningThreshold: 50,- },- expected: "NO_DATA",- },- {- name: "null value -> NO_DATA (no warning)",- input: {- value: null,- operator: "LT",- alertThreshold: 100,- warningThreshold: null,- },- expected: "NO_DATA",- },+/** NoDataCase is one no-data computeSeverity table row: a null value resolved per noData mode. */+type NoDataCase = {+ name: string;+ noData: MonitorNoData;+ prevSeverity: MonitorSeverity;+ expected: MonitorSeverity;+};+/** cases covers each operator's alert/warning/OK bands. */+const cases: ComputeSeverityCase[] = [{name: "GT: value > alert -> ALERT",input: {value: 120,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 50,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "GT: value == alert, no warning -> OK (strict >)",input: {value: 100,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "GT: value > warning, value <= alert -> WARNING",input: {value: 80,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 50,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "GT: value == warning -> OK (strict >)",input: {value: 50,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 50,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "GT: value < warning -> OK",input: {value: 40,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 50,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "GT: value > alert, no warning -> ALERT",input: {value: 120,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "GT: value < alert, no warning -> OK",input: {value: 80,- operator: "GT",+ operator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "GTE: value == alert -> ALERT",input: {value: 100,- operator: "GTE",+ operator: MonitorThresholdOperatorSchema.enum.GTE,alertThreshold: 100,warningThreshold: 50,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "GTE: value > alert -> ALERT",input: {value: 101,- operator: "GTE",+ operator: MonitorThresholdOperatorSchema.enum.GTE,alertThreshold: 100,warningThreshold: 50,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "GTE: value == warning -> WARNING",input: {value: 50,- operator: "GTE",+ operator: MonitorThresholdOperatorSchema.enum.GTE,alertThreshold: 100,warningThreshold: 50,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "GTE: value < warning -> OK",input: {value: 49,- operator: "GTE",+ operator: MonitorThresholdOperatorSchema.enum.GTE,alertThreshold: 100,warningThreshold: 50,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "LT: value < alert -> ALERT",input: {value: 80,- operator: "LT",+ operator: MonitorThresholdOperatorSchema.enum.LT,alertThreshold: 100,warningThreshold: 150,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "LT: value == alert, no warning -> OK (strict <)",input: {value: 100,- operator: "LT",+ operator: MonitorThresholdOperatorSchema.enum.LT,alertThreshold: 100,warningThreshold: null,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "LT: value < warning, value >= alert -> WARNING",input: {value: 120,- operator: "LT",+ operator: MonitorThresholdOperatorSchema.enum.LT,alertThreshold: 100,warningThreshold: 150,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "LT: value > warning -> OK",input: {value: 200,- operator: "LT",+ operator: MonitorThresholdOperatorSchema.enum.LT,alertThreshold: 100,warningThreshold: 150,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "LTE: value == alert -> ALERT",input: {value: 100,- operator: "LTE",+ operator: MonitorThresholdOperatorSchema.enum.LTE,alertThreshold: 100,warningThreshold: 150,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "LTE: value == warning -> WARNING",input: {value: 150,- operator: "LTE",+ operator: MonitorThresholdOperatorSchema.enum.LTE,alertThreshold: 100,warningThreshold: 150,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "LTE: value > warning -> OK",input: {value: 151,- operator: "LTE",+ operator: MonitorThresholdOperatorSchema.enum.LTE,alertThreshold: 100,warningThreshold: 150,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "EQ: value == alert -> ALERT",input: {value: 100,- operator: "EQ",+ operator: MonitorThresholdOperatorSchema.enum.EQ,alertThreshold: 100,warningThreshold: 50,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "EQ: value == warning -> WARNING",input: {value: 50,- operator: "EQ",+ operator: MonitorThresholdOperatorSchema.enum.EQ,alertThreshold: 100,warningThreshold: 50,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "EQ: value matches neither -> OK",input: {value: 75,- operator: "EQ",+ operator: MonitorThresholdOperatorSchema.enum.EQ,alertThreshold: 100,warningThreshold: 50,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,},{name: "NEQ: value != alert -> ALERT (alert checked first)",input: {value: 99,- operator: "NEQ",+ operator: MonitorThresholdOperatorSchema.enum.NEQ,alertThreshold: 100,warningThreshold: 50,},- expected: "ALERT",+ expected: MonitorSeveritySchema.enum.ALERT,},{name: "NEQ: value == alert, value != warning -> WARNING",input: {value: 100,- operator: "NEQ",+ operator: MonitorThresholdOperatorSchema.enum.NEQ,alertThreshold: 100,warningThreshold: 50,},- expected: "WARNING",+ expected: MonitorSeveritySchema.enum.WARNING,},{name: "NEQ: value == alert == warning -> OK",input: {value: 100,- operator: "NEQ",+ operator: MonitorThresholdOperatorSchema.enum.NEQ,alertThreshold: 100,warningThreshold: 100,},- expected: "OK",+ expected: MonitorSeveritySchema.enum.OK,+ },+];++const noDataDefaults = {+ noData: { mode: MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO },+ prevSeverity: MonitorSeveritySchema.enum.OK,+};++const noDataThresholds = {+ operator: MonitorThresholdOperatorSchema.enum.GT,+ alertThreshold: 100,+ warningThreshold: 50,+};++const noDataCases: NoDataCase[] = [+ {+ name: "SUBSTITUTE_ZERO -> 0 through thresholds -> OK",+ noData: { mode: MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO },+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ expected: MonitorSeveritySchema.enum.OK,+ },+ {+ name: "LAST_SEVERITY -> prev severity (ALERT)",+ noData: { mode: MonitorNoDataModeSchema.enum.LAST_SEVERITY },+ prevSeverity: MonitorSeveritySchema.enum.ALERT,+ expected: MonitorSeveritySchema.enum.ALERT,+ },+ {+ name: "LAST_SEVERITY -> prev severity (WARNING)",+ noData: { mode: MonitorNoDataModeSchema.enum.LAST_SEVERITY },+ prevSeverity: MonitorSeveritySchema.enum.WARNING,+ expected: MonitorSeveritySchema.enum.WARNING,+ },+ {+ name: "SHOW_NO_DATA -> NO_DATA",+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },+ prevSeverity: MonitorSeveritySchema.enum.OK,+ expected: MonitorSeveritySchema.enum.NO_DATA,+ },+ {+ name: "NOTIFY_NO_DATA -> NO_DATA",+ noData: {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 60,+ },+ prevSeverity: MonitorSeveritySchema.enum.OK,+ expected: MonitorSeveritySchema.enum.NO_DATA,},];describe("computeSeverity", () => {it.each(cases)("$name", ({ input, expected }) => {- expect(computeSeverity(input)).toBe(expected);+ expect(computeSeverity({ ...input, ...noDataDefaults })).toBe(expected);+ });++ it("non-null value ignores noData mode", () => {+ expect(+ computeSeverity({+ value: 120,+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },+ prevSeverity: MonitorSeveritySchema.enum.OK,+ operator: MonitorThresholdOperatorSchema.enum.GT,+ alertThreshold: 100,+ warningThreshold: 50,+ }),+ ).toBe(MonitorSeveritySchema.enum.ALERT);+ });+});++describe("computeSeverity: no data", () => {+ it.each(noDataCases)("$name", ({ noData, prevSeverity, expected }) => {+ expect(+ computeSeverity({+ value: null,+ noData,+ prevSeverity,+ operator: noDataThresholds.operator,+ alertThreshold: noDataThresholds.alertThreshold,+ warningThreshold: noDataThresholds.warningThreshold,+ }),+ ).toBe(expected);+ });++ it("SUBSTITUTE_ZERO + GTE alert at 0 -> ALERT", () => {+ expect(+ computeSeverity({+ value: null,+ noData: { mode: MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO },+ prevSeverity: MonitorSeveritySchema.enum.OK,+ operator: MonitorThresholdOperatorSchema.enum.GTE,+ alertThreshold: 0,+ warningThreshold: null,+ }),+ ).toBe(MonitorSeveritySchema.enum.ALERT);});});diff --git a/packages/shared/src/features/monitors/processor/computeSeverity.ts b/packages/shared/src/features/monitors/processor/computeSeverity.tsindex 0ee9324061..aa1fe1ca99 100644--- a/packages/shared/src/features/monitors/processor/computeSeverity.ts+++ b/packages/shared/src/features/monitors/processor/computeSeverity.ts@@ -1,20 +1,52 @@import {+ MonitorNoDataModeSchema,MonitorThresholdOperatorSchema,+ type MonitorNoData,type MonitorThresholdOperator,MonitorSeveritySchema,type MonitorSeverity,} from "../types";-/** computeSeverity maps a metric value to a non-lifecycle severity by comparing it against the alert (and optional warning) thresholds. */+/** computeSeverity maps a metric value to a severity, interpreting a null value per the monitor's noData mode and otherwise comparing it against the alert and optional warning thresholds. */export function computeSeverity(args: {value: number | null;+ noData: MonitorNoData;+ prevSeverity: MonitorSeverity;operator: MonitorThresholdOperator;alertThreshold: number;warningThreshold: number | null;}): MonitorSeverity {if (args.value === null) {- return MonitorSeveritySchema.enum.NO_DATA;+ switch (args.noData.mode) {+ case MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO:+ return computeNonNullSeverity({+ value: 0,+ operator: args.operator,+ alertThreshold: args.alertThreshold,+ warningThreshold: args.warningThreshold,+ });+ case MonitorNoDataModeSchema.enum.LAST_SEVERITY:+ return args.prevSeverity;+ case MonitorNoDataModeSchema.enum.SHOW_NO_DATA:+ case MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA:+ return MonitorSeveritySchema.enum.NO_DATA;+ }}+ return computeNonNullSeverity({+ value: args.value,+ operator: args.operator,+ alertThreshold: args.alertThreshold,+ warningThreshold: args.warningThreshold,+ });+}++/** computeNonNullSeverity maps a present metric value to a non-lifecycle severity by comparing it against the alert and optional warning thresholds. */+function computeNonNullSeverity(args: {+ value: number;+ operator: MonitorThresholdOperator;+ alertThreshold: number;+ warningThreshold: number | null;+}): MonitorSeverity {if (matches(args.value, args.operator, args.alertThreshold)) {return MonitorSeveritySchema.enum.ALERT;}diff --git a/packages/shared/src/features/monitors/processor/processor.ts b/packages/shared/src/features/monitors/processor/processor.tsindex eb4a55c4f9..0a3c4d3be9 100644--- a/packages/shared/src/features/monitors/processor/processor.ts+++ b/packages/shared/src/features/monitors/processor/processor.ts@@ -23,7 +23,13 @@ import {type MonitorWebhookInput,} from "../scheduler/types";import { monitorFromPrisma, windowToMs } from "../service/helpers";-import { type MonitorAlert, type MonitorWindow, type Monitor } from "../types";+import {+ MonitorSeveritySchema,+ MonitorStatusSchema,+ type MonitorAlert,+ type MonitorWindow,+ type Monitor,+} from "../types";import { applyStateMachine, type MonitorCompletion } from "./applyStateMachine";import { computeSeverity } from "./computeSeverity";import { renderAlertMessage } from "./renderAlertMessage";@@ -103,7 +109,7 @@ export class MonitorProcessor {where: {id: { in: event.monitors.map((m) => m.monitorId) },projectId: event.projectId,- status: "ACTIVE", // active monitors for the+ status: MonitorStatusSchema.enum.ACTIVE, // active monitors for thelastPublishedAt: { lte: event.publishedAt }, // newest eventAND: [// not already claimed@@ -301,8 +307,8 @@ function processMonitor(args: {lastClaimedAt: now,lastCompletedAt: now,publishedAt,- status: "ERROR_BAD_QUERY",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: now,alertedAt: monitor.alertedAt,},@@ -312,6 +318,8 @@ function processMonitor(args: {const severity = computeSeverity({value,+ noData: monitor.noData,+ prevSeverity: monitor.severity,operator: monitor.thresholdOperator,alertThreshold: monitor.alertThreshold,warningThreshold: monitor.warningThreshold ?? null,diff --git a/packages/shared/src/features/monitors/processor/renderAlertMessage.test.ts b/packages/shared/src/features/monitors/processor/renderAlertMessage.test.tsindex a6a41d35dc..d0e3fc9ca9 100644--- a/packages/shared/src/features/monitors/processor/renderAlertMessage.test.ts+++ b/packages/shared/src/features/monitors/processor/renderAlertMessage.test.ts@@ -1,6 +1,13 @@import { describe, it, expect } from "vitest";-import type { Monitor, MonitorSeverity } from "../types";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+ type Monitor,+ type MonitorSeverity,+} from "../types";import type { MonitorCompletion } from "./applyStateMachine";import { renderAlertMessage } from "./renderAlertMessage";@@ -18,18 +25,18 @@ const baseMonitor: Monitor = {filters: [],metric: { measure: "latency", aggregation: "p95" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 50,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },name: "Latency monitor",tags: [],triggerIds: [],- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: null,alertedAt: null,- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,nextRunAt: null,lastPublishedAt: null,lastClaimedAt: null,@@ -42,7 +49,7 @@ const completion = (severity: MonitorSeverity): MonitorCompletion => ({lastClaimedAt: t0,lastCompletedAt: t0,publishedAt: t0,- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,severity,severityChangedAt: null,alertedAt: null,@@ -63,8 +70,8 @@ const metricRef = "`p95(observations.latency)`";const cases: Case[] = [{name: "NO_DATA: body reports no data over the window",- monitor: { severity: "OK", window: "1h" },- next: "NO_DATA",+ monitor: { severity: MonitorSeveritySchema.enum.OK, window: "1h" },+ next: MonitorSeveritySchema.enum.NO_DATA,expected: {title: "[NO_DATA] Latency monitor",body: `${metricRef} has no data over the last **1h**`,@@ -72,8 +79,8 @@ const cases: Case[] = [},{name: "NO_DATA -> OK: body reports recovery and data again",- monitor: { severity: "NO_DATA" },- next: "OK",+ monitor: { severity: MonitorSeveritySchema.enum.NO_DATA },+ next: MonitorSeveritySchema.enum.OK,expected: {title: "[OK] Latency monitor",body: `${metricRef} recovered and is reporting data again`,@@ -81,8 +88,8 @@ const cases: Case[] = [},{name: "OK from a threshold severity: body reports recovery",- monitor: { severity: "ALERT" },- next: "OK",+ monitor: { severity: MonitorSeveritySchema.enum.ALERT },+ next: MonitorSeveritySchema.enum.OK,expected: {title: "[OK] Latency monitor",body: `${metricRef} recovered`,@@ -90,8 +97,12 @@ const cases: Case[] = [},{name: "ALERT: body uses alert threshold",- monitor: { severity: "OK", thresholdOperator: "GT", alertThreshold: 100 },- next: "ALERT",+ monitor: {+ severity: MonitorSeveritySchema.enum.OK,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,+ alertThreshold: 100,+ },+ next: MonitorSeveritySchema.enum.ALERT,expected: {title: "[ALERT] Latency monitor",body: `${metricRef} is **above** \`100\` over the last **5m**`,@@ -99,8 +110,12 @@ const cases: Case[] = [},{name: "WARNING with warning band: body uses warning threshold",- monitor: { severity: "OK", alertThreshold: 100, warningThreshold: 50 },- next: "WARNING",+ monitor: {+ severity: MonitorSeveritySchema.enum.OK,+ alertThreshold: 100,+ warningThreshold: 50,+ },+ next: MonitorSeveritySchema.enum.WARNING,expected: {title: "[WARNING] Latency monitor",body: `${metricRef} is **above** \`50\` over the last **5m**`,@@ -108,8 +123,12 @@ const cases: Case[] = [},{name: "WARNING with null warning band: falls back to alert threshold",- monitor: { severity: "OK", alertThreshold: 100, warningThreshold: null },- next: "WARNING",+ monitor: {+ severity: MonitorSeveritySchema.enum.OK,+ alertThreshold: 100,+ warningThreshold: null,+ },+ next: MonitorSeveritySchema.enum.WARNING,expected: {title: "[WARNING] Latency monitor",body: `${metricRef} is **above** \`100\` over the last **5m**`,@@ -130,12 +149,12 @@ describe("renderAlertMessage", () => {type OperatorCase = { op: Monitor["thresholdOperator"]; word: string };/** operatorCases covers every operator's rendered word. */const operatorCases: OperatorCase[] = [- { op: "GT", word: "above" },- { op: "GTE", word: "at or above" },- { op: "LT", word: "below" },- { op: "LTE", word: "at or below" },- { op: "EQ", word: "equal to" },- { op: "NEQ", word: "not equal to" },+ { op: MonitorThresholdOperatorSchema.enum.GT, word: "above" },+ { op: MonitorThresholdOperatorSchema.enum.GTE, word: "at or above" },+ { op: MonitorThresholdOperatorSchema.enum.LT, word: "below" },+ { op: MonitorThresholdOperatorSchema.enum.LTE, word: "at or below" },+ { op: MonitorThresholdOperatorSchema.enum.EQ, word: "equal to" },+ { op: MonitorThresholdOperatorSchema.enum.NEQ, word: "not equal to" },];it.each(operatorCases)(@@ -144,11 +163,11 @@ describe("renderAlertMessage", () => {const result = renderAlertMessage({monitor: {...baseMonitor,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,thresholdOperator: op,alertThreshold: 100,},- completion: completion("ALERT"),+ completion: completion(MonitorSeveritySchema.enum.ALERT),});expect(result.body).toBe(`${metricRef} is **${word}** \`100\` over the last **5m**`,diff --git a/packages/shared/src/features/monitors/service/helpers.test.ts b/packages/shared/src/features/monitors/service/helpers.test.tsindex 2700d760e8..f51cdf78e0 100644--- a/packages/shared/src/features/monitors/service/helpers.test.ts+++ b/packages/shared/src/features/monitors/service/helpers.test.ts@@ -4,7 +4,14 @@ import { z } from "zod";import { InvalidRequestError, LangfuseNotFoundError } from "../../../errors";import { singleFilter } from "../../../interfaces/filters";-import { MonitorViewSchema, MonitorWindowSchema } from "../types";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+ MonitorViewSchema,+ MonitorWindowSchema,+} from "../types";import { DAY, HOUR, MINUTE, WEEK } from "../helpers";import {calculateCadence,@@ -141,12 +148,24 @@ describe("toPrismaWhere", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT", "WARNING"],+ value: [+ MonitorSeveritySchema.enum.ALERT,+ MonitorSeveritySchema.enum.WARNING,+ ],},];expect(toPrismaWhere("proj_01", filter)).toEqual({projectId: "proj_01",- AND: [{ severity: { in: ["ALERT", "WARNING"] } }],+ AND: [+ {+ severity: {+ in: [+ MonitorSeveritySchema.enum.ALERT,+ MonitorSeveritySchema.enum.WARNING,+ ],+ },+ },+ ],});});@@ -156,12 +175,12 @@ describe("toPrismaWhere", () => {type: "stringOptions",column: "severity",operator: "none of",- value: ["PAUSED"],+ value: [MonitorSeveritySchema.enum.PAUSED],},];expect(toPrismaWhere("proj_01", filter)).toEqual({projectId: "proj_01",- AND: [{ NOT: { severity: { in: ["PAUSED"] } } }],+ AND: [{ NOT: { severity: { in: [MonitorSeveritySchema.enum.PAUSED] } } }],});});@@ -473,15 +492,15 @@ describe("monitorFromPrisma", () => {windowMs: 5n * 60_000n,cadenceMs: 60_000n,schedulerBatchId: 42n,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: new Prisma.Decimal(100),warningThreshold: null,- noData: { mode: "SILENT" as const },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" as const },- severity: "UNKNOWN" as const,+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,- status: "ACTIVE" as const,+ status: MonitorStatusSchema.enum.ACTIVE,nextRunAt: new Date("2026-05-18T00:01:00.000Z"),lastPublishedAt: null,lastClaimedAt: null,@@ -494,9 +513,11 @@ describe("monitorFromPrisma", () => {it("translates a representative row to the domain shape", () => {const monitor = monitorFromPrisma(prismaRow);expect(monitor.view).toBe("observations");- expect(monitor.status).toBe("ACTIVE");- expect(monitor.severity).toBe("UNKNOWN");- expect(monitor.thresholdOperator).toBe("GT");+ expect(monitor.status).toBe(MonitorStatusSchema.enum.ACTIVE);+ expect(monitor.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);+ expect(monitor.thresholdOperator).toBe(+ MonitorThresholdOperatorSchema.enum.GT,+ );expect(monitor.window).toBe("5m");expect(monitor.alertThreshold).toBe(100);expect(monitor.warningThreshold).toBeNull();@@ -519,21 +540,30 @@ describe("monitorFromPrisma", () => {describe("updateStatusAndSeverity", () => {it("emits PAUSED with a timestamp when status leaves ACTIVE", () => {- const result = updateStatusAndSeverity("ACTIVE", "PAUSED");- expect(result.status).toBe("PAUSED");- expect(result.severity).toBe("PAUSED");+ const result = updateStatusAndSeverity(+ MonitorStatusSchema.enum.ACTIVE,+ MonitorStatusSchema.enum.PAUSED,+ );+ expect(result.status).toBe(MonitorStatusSchema.enum.PAUSED);+ expect(result.severity).toBe(MonitorSeveritySchema.enum.PAUSED);expect(result.severityChangedAt).toBeInstanceOf(Date);});it("emits UNKNOWN with a timestamp when status returns to ACTIVE", () => {- const result = updateStatusAndSeverity("PAUSED", "ACTIVE");- expect(result.status).toBe("ACTIVE");- expect(result.severity).toBe("UNKNOWN");+ const result = updateStatusAndSeverity(+ MonitorStatusSchema.enum.PAUSED,+ MonitorStatusSchema.enum.ACTIVE,+ );+ expect(result.status).toBe(MonitorStatusSchema.enum.ACTIVE);+ expect(result.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);expect(result.severityChangedAt).toBeInstanceOf(Date);});it("resets the publish lifecycle stamps when status returns to ACTIVE", () => {- const result = updateStatusAndSeverity("PAUSED", "ACTIVE");+ const result = updateStatusAndSeverity(+ MonitorStatusSchema.enum.PAUSED,+ MonitorStatusSchema.enum.ACTIVE,+ );expect(result.nextRunAt).toBeNull();expect(result.lastPublishedAt).toBeNull();expect(result.lastCompletedAt).toBeNull();@@ -542,34 +572,60 @@ describe("updateStatusAndSeverity", () => {});it("emits UNKNOWN when recovering from ERROR_BAD_QUERY to ACTIVE", () => {- const result = updateStatusAndSeverity("ERROR_BAD_QUERY", "ACTIVE");- expect(result.status).toBe("ACTIVE");- expect(result.severity).toBe("UNKNOWN");+ const result = updateStatusAndSeverity(+ MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ MonitorStatusSchema.enum.ACTIVE,+ );+ expect(result.status).toBe(MonitorStatusSchema.enum.ACTIVE);+ expect(result.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);expect(result.severityChangedAt).toBeInstanceOf(Date);});it("emits PAUSED when going from ACTIVE to ERROR_BAD_QUERY", () => {- const result = updateStatusAndSeverity("ACTIVE", "ERROR_BAD_QUERY");- expect(result.status).toBe("ERROR_BAD_QUERY");- expect(result.severity).toBe("PAUSED");+ const result = updateStatusAndSeverity(+ MonitorStatusSchema.enum.ACTIVE,+ MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ );+ expect(result.status).toBe(MonitorStatusSchema.enum.ERROR_BAD_QUERY);+ expect(result.severity).toBe(MonitorSeveritySchema.enum.PAUSED);expect(result.severityChangedAt).toBeInstanceOf(Date);});it("writes only status when it does not change", () => {- expect(updateStatusAndSeverity("ACTIVE", "ACTIVE")).toEqual({- status: "ACTIVE",+ expect(+ updateStatusAndSeverity(+ MonitorStatusSchema.enum.ACTIVE,+ MonitorStatusSchema.enum.ACTIVE,+ ),+ ).toEqual({+ status: MonitorStatusSchema.enum.ACTIVE,});- expect(updateStatusAndSeverity("PAUSED", "PAUSED")).toEqual({- status: "PAUSED",+ expect(+ updateStatusAndSeverity(+ MonitorStatusSchema.enum.PAUSED,+ MonitorStatusSchema.enum.PAUSED,+ ),+ ).toEqual({+ status: MonitorStatusSchema.enum.PAUSED,});});it("writes only status when transitioning between two non-ACTIVE states", () => {- expect(updateStatusAndSeverity("PAUSED", "ERROR_BAD_QUERY")).toEqual({- status: "ERROR_BAD_QUERY",+ expect(+ updateStatusAndSeverity(+ MonitorStatusSchema.enum.PAUSED,+ MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ ),+ ).toEqual({+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,});- expect(updateStatusAndSeverity("ERROR_BAD_QUERY", "PAUSED")).toEqual({- status: "PAUSED",+ expect(+ updateStatusAndSeverity(+ MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ MonitorStatusSchema.enum.PAUSED,+ ),+ ).toEqual({+ status: MonitorStatusSchema.enum.PAUSED,});});});diff --git a/packages/shared/src/features/monitors/service/service.test.ts b/packages/shared/src/features/monitors/service/service.test.tsindex a635bbc626..e202a25452 100644--- a/packages/shared/src/features/monitors/service/service.test.ts+++ b/packages/shared/src/features/monitors/service/service.test.ts@@ -14,6 +14,12 @@ vi.mock("../../../db", async () => {});import { prisma } from "../../../db";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "../types";import { calculateSchedulerBatchId } from "./helpers";import { MonitorService } from "./service";import { type SessionContext, type UpdateMonitor } from "./types";@@ -34,12 +40,12 @@ const input: UpdateMonitor = {filters: [],metric: { measure: "count", aggregation: "count" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,name: "High error rate",tags: [],triggerIds: [],@@ -57,14 +63,14 @@ const prismaRow = {metric: { measure: "count", aggregation: "count" },windowMs: 300000n,cadenceMs: 60000n,- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: { toNumber: () => 100 },warningThreshold: null,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,schedulerBatchId: 42n,nextRunAt: null,lastPublishedAt: null,@@ -94,7 +100,7 @@ describe("MonitorService.update", () => {it("resume PAUSED->ACTIVE resets next_run_at and lifecycle stamps", async () => {(prisma.monitor.findFirst as any).mockResolvedValue({...prismaRow,- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,schedulerBatchId: unchangedBatchId,nextRunAt: new Date("2026-05-01T00:00:00.000Z"),lastPublishedAt: new Date("2026-05-01T00:00:00.000Z"),@@ -102,7 +108,10 @@ describe("MonitorService.update", () => {lastClaimedAt: new Date("2026-05-01T00:00:00.000Z"),});- await MonitorService.update(session, { ...input, status: "ACTIVE" });+ await MonitorService.update(session, {+ ...input,+ status: MonitorStatusSchema.enum.ACTIVE,+ });const data = (prisma.monitor.update as any).mock.calls[0][0].data;expect(data.nextRunAt).toBeNull();diff --git a/packages/shared/src/features/monitors/service/types.test.ts b/packages/shared/src/features/monitors/service/types.test.tsindex 66816d8a47..c6401fe4d5 100644--- a/packages/shared/src/features/monitors/service/types.test.ts+++ b/packages/shared/src/features/monitors/service/types.test.ts@@ -11,6 +11,10 @@ import {ErrorAlertThresholdRequired,ErrorAtLeastOneTrigger,ErrorNameRequired,+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,} from "../types";// Minimal valid `CreateMonitorSchema` payload. Tests override one field@@ -23,12 +27,12 @@ const validCreateInput = {metric: { measure: "count", aggregation: "count" as const },window: "5m" as const,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" as const },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" as const },- status: "ACTIVE" as const,+ status: MonitorStatusSchema.enum.ACTIVE,name: "High error rate",tags: [],@@ -48,50 +52,50 @@ describe("CreateMonitorSchema", () => {it("rejects warning >= alert for gt (validateThresholdOrder is wired)", () => {const result = CreateMonitorSchema.safeParse({...validCreateInput,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 100,});expect(result.success).toBe(false);});- it.each(["GT", "GTE"] as const)(- "%s emits a `>` strict-ordering message (not the operator name)",- (op) => {- const result = CreateMonitorSchema.safeParse({- ...validCreateInput,- thresholdOperator: op,- alertThreshold: 100,- warningThreshold: 100,- });- expect(result.success).toBe(false);- if (!result.success) {- const message = result.error.issues[0].message;- expect(message).toContain(">");- // Must NOT interpolate the operator literal — `gte` would otherwise- // produce the misleading "must be gte" (non-strict) phrasing.- expect(message).not.toContain(op);- }- },- );+ it.each([+ MonitorThresholdOperatorSchema.enum.GT,+ MonitorThresholdOperatorSchema.enum.GTE,+ ])("%s emits a `>` strict-ordering message (not the operator name)", (op) => {+ const result = CreateMonitorSchema.safeParse({+ ...validCreateInput,+ thresholdOperator: op,+ alertThreshold: 100,+ warningThreshold: 100,+ });+ expect(result.success).toBe(false);+ if (!result.success) {+ const message = result.error.issues[0].message;+ expect(message).toContain(">");+ // Must NOT interpolate the operator literal — `gte` would otherwise+ // produce the misleading "must be gte" (non-strict) phrasing.+ expect(message).not.toContain(op);+ }+ });- it.each(["LT", "LTE"] as const)(- "%s emits a `<` strict-ordering message (not the operator name)",- (op) => {- const result = CreateMonitorSchema.safeParse({- ...validCreateInput,- thresholdOperator: op,- alertThreshold: 100,- warningThreshold: 100,- });- expect(result.success).toBe(false);- if (!result.success) {- const message = result.error.issues[0].message;- expect(message).toContain("<");- expect(message).not.toContain(op);- }- },- );+ it.each([+ MonitorThresholdOperatorSchema.enum.LT,+ MonitorThresholdOperatorSchema.enum.LTE,+ ])("%s emits a `<` strict-ordering message (not the operator name)", (op) => {+ const result = CreateMonitorSchema.safeParse({+ ...validCreateInput,+ thresholdOperator: op,+ alertThreshold: 100,+ warningThreshold: 100,+ });+ expect(result.success).toBe(false);+ if (!result.success) {+ const message = result.error.issues[0].message;+ expect(message).toContain("<");+ expect(message).not.toContain(op);+ }+ });it("rejects an unknown measure (validateQuery is wired)", () => {const result = CreateMonitorSchema.safeParse({@@ -128,7 +132,7 @@ describe("CreateMonitorSchema", () => {it("rejects status `error-bad-query` on create (scheduler-owned)", () => {const result = CreateMonitorSchema.safeParse({...validCreateInput,- status: "ERROR_BAD_QUERY",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,});expect(result.success).toBe(false);});@@ -181,7 +185,7 @@ describe("UpdateMonitorSchema", () => {it("rejects warning <= alert for lt (validateThresholdOrder is wired)", () => {const result = UpdateMonitorSchema.safeParse({...validUpdateInput,- thresholdOperator: "LT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.LT,alertThreshold: 100,warningThreshold: 100,});@@ -209,7 +213,7 @@ describe("UpdateMonitorSchema", () => {// directly — narrowing the input DTO to active/paused enforces that.const result = UpdateMonitorSchema.safeParse({...validUpdateInput,- status: "ERROR_BAD_QUERY",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,});expect(result.success).toBe(false);});@@ -327,7 +331,7 @@ describe("ListMonitorFilterSchema", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],},{type: "arrayOptions",@@ -345,13 +349,13 @@ describe("ListMonitorFilterSchema", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],},{type: "stringOptions",column: "severity",operator: "none of",- value: ["PAUSED"],+ value: [MonitorSeveritySchema.enum.PAUSED],},]);expect(result.success).toBe(false);diff --git a/packages/shared/src/features/monitors/types.test.ts b/packages/shared/src/features/monitors/types.test.tsindex 7c2dfdc94c..dd4192435d 100644--- a/packages/shared/src/features/monitors/types.test.ts+++ b/packages/shared/src/features/monitors/types.test.ts@@ -2,9 +2,13 @@ import { describe, it, expect } from "vitest";import {MonitorAlertSchema,+ MonitorNoDataModeSchema,MonitorNoDataSchema,MonitorRenotifySchema,MonitorSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,MonitorWindowSchema,} from "./types";@@ -22,17 +26,17 @@ const validMonitorBase = {metric: { measure: "count", aggregation: "count" as const },window: "5m" as const,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- severity: "UNKNOWN" as const,+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,- noData: { mode: "SILENT" as const },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" as const },- status: "ACTIVE" as const,+ status: MonitorStatusSchema.enum.ACTIVE,nextRunAt: new Date("2026-05-18T00:01:00.000Z"),lastPublishedAt: null,lastClaimedAt: null,@@ -101,37 +105,49 @@ describe("MonitorRenotifySchema", () => {});describe("MonitorNoDataSchema", () => {- it("accepts the SILENT variant", () => {- expect(MonitorNoDataSchema.safeParse({ mode: "SILENT" }).success).toBe(- true,- );+ it.each([+ MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO,+ MonitorNoDataModeSchema.enum.LAST_SEVERITY,+ MonitorNoDataModeSchema.enum.SHOW_NO_DATA,+ ])("accepts the %s variant", (mode) => {+ expect(MonitorNoDataSchema.safeParse({ mode }).success).toBe(true);});- it("accepts the NOTIFY variant with a valid interval", () => {+ it("accepts the NOTIFY_NO_DATA variant with a valid interval", () => {const result = MonitorNoDataSchema.safeParse({- mode: "NOTIFY",+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,intervalMinutes: 5,});expect(result.success).toBe(true);});- it("rejects NOTIFY without intervalMinutes", () => {- expect(MonitorNoDataSchema.safeParse({ mode: "NOTIFY" }).success).toBe(+ it("rejects NOTIFY_NO_DATA without intervalMinutes", () => {+ expect(+ MonitorNoDataSchema.safeParse({+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ }).success,+ ).toBe(false);+ });++ it("rejects the legacy SILENT variant", () => {+ expect(MonitorNoDataSchema.safeParse({ mode: "SILENT" }).success).toBe(false,);});it("rejects intervalMinutes below 1", () => {expect(- MonitorNoDataSchema.safeParse({ mode: "NOTIFY", intervalMinutes: 0 })- .success,+ MonitorNoDataSchema.safeParse({+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 0,+ }).success,).toBe(false);});it("rejects intervalMinutes above one day", () => {expect(MonitorNoDataSchema.safeParse({- mode: "NOTIFY",+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,intervalMinutes: 60 * 24 + 1,}).success,).toBe(false);@@ -176,7 +192,7 @@ describe("MonitorAlertSchema", () => {const validAlert = {monitorId: "mon_01",projectId: "proj_01",- severity: "ALERT" as const,+ severity: MonitorSeveritySchema.enum.ALERT,permalink: "https://cloud.langfuse.com/project/proj_01/monitors/mon_01",timestamp: new Date("2026-05-18T12:01:00.000Z"),fromTimestamp: new Date("2026-05-18T11:55:30.000Z"),diff --git a/packages/shared/src/features/monitors/types.ts b/packages/shared/src/features/monitors/types.tsindex 636b0971c5..70023431c4 100644--- a/packages/shared/src/features/monitors/types.ts+++ b/packages/shared/src/features/monitors/types.ts@@ -97,16 +97,22 @@ export const MonitorRenotifySchema = z.discriminatedUnion("mode", []);export type MonitorRenotify = z.infer<typeof MonitorRenotifySchema>;-/**- * MonitorNoDataSchema describes behavior when a Monitor query returns no rows.- * `SILENT` suppresses all NO_DATA notifications (entry, persistence, recovery);- * `NOTIFY` alerts on entry after `intervalMinutes` of sustained NO_DATA,- * re-fires per the renotify cadence, and alerts on recovery.- */+/** MonitorNoDataModeSchema enumerates how a null metric value resolves to a severity. */+export const MonitorNoDataModeSchema = z.enum([+ "SUBSTITUTE_ZERO",+ "LAST_SEVERITY",+ "SHOW_NO_DATA",+ "NOTIFY_NO_DATA",+]);+export type MonitorNoDataMode = z.infer<typeof MonitorNoDataModeSchema>;++/** MonitorNoDataSchema describes how a null metric value resolves to a severity. */export const MonitorNoDataSchema = z.discriminatedUnion("mode", [- z.object({ mode: z.literal("SILENT") }),+ z.object({ mode: z.literal(MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO) }),+ z.object({ mode: z.literal(MonitorNoDataModeSchema.enum.LAST_SEVERITY) }),+ z.object({ mode: z.literal(MonitorNoDataModeSchema.enum.SHOW_NO_DATA) }),z.object({- mode: z.literal("NOTIFY"),+ mode: z.literal(MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA),intervalMinutes: z.number().int()@@ -197,7 +203,9 @@ export const MonitorSchema = z.object({thresholdOperator: MonitorThresholdOperatorSchema,alertThreshold: z.number({ message: ErrorAlertThresholdRequired }),warningThreshold: z.number().nullable(),- noData: MonitorNoDataSchema.default({ mode: "SILENT" }),+ noData: MonitorNoDataSchema.default({+ mode: MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO,+ }),renotify: MonitorRenotifySchema.default({ mode: "OFF" }),// MonitorAlert Configdiff --git a/web/src/__tests__/server/monitorService.servertest.ts b/web/src/__tests__/server/monitorService.servertest.tsindex 2b6e819f78..16c4686bcd 100644--- a/web/src/__tests__/server/monitorService.servertest.ts+++ b/web/src/__tests__/server/monitorService.servertest.ts@@ -4,6 +4,12 @@ import {MonitorService,type SessionContext,} from "@langfuse/shared/monitors/server";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";import { prisma } from "@langfuse/shared/src/db";import { LangfuseNotFoundError } from "@langfuse/shared";@@ -13,14 +19,15 @@ const baseMonitorInput = (projectId: string) => ({filters: [],metric: { measure: "count", aggregation: "count" as const },window: "5m" as const,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" as const },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" as const },- status: "ACTIVE" as const,+ status: MonitorStatusSchema.enum.ACTIVE,name: "High error rate",tags: [],+ triggerIds: [],});describe("MonitorService (integration)", () => {@@ -69,7 +76,7 @@ describe("MonitorService (integration)", () => {expect(row!.cadenceMs).toBe(60_000n);expect(row!.schedulerBatchId).toBeGreaterThan(0n);expect(row!.nextRunAt).toBeNull();- expect(row!.severity).toBe("UNKNOWN");+ expect(row!.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);expect(row!.createdBy).toBe(creator.userId);expect(row!.updatedBy).toBe(creator.userId);});@@ -139,7 +146,7 @@ describe("MonitorService (integration)", () => {await prisma.monitor.update({where: { id: created.id },data: {- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: new Date(),alertedAt: new Date(),lastCompletedAt: new Date(),@@ -153,7 +160,7 @@ describe("MonitorService (integration)", () => {});expect(updated.name).toBe("Renamed");- expect(updated.severity).toBe("ALERT");+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.ALERT);expect(updated.severityChangedAt).not.toBeNull();expect(updated.alertedAt).not.toBeNull();expect(updated.lastCompletedAt).not.toBeNull();@@ -179,32 +186,32 @@ describe("MonitorService (integration)", () => {creator,baseMonitorInput(projectId),);- expect(created.severity).toBe("UNKNOWN");+ expect(created.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);const updated = await MonitorService.update(editor, {...baseMonitorInput(projectId),id: created.id,- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});- expect(updated.severity).toBe("PAUSED");+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.PAUSED);expect(updated.severityChangedAt).not.toBeNull();});it("flips severity to UNKNOWN when status returns to ACTIVE", async () => {const created = await MonitorService.create(creator, {...baseMonitorInput(projectId),- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});- expect(created.severity).toBe("PAUSED");+ expect(created.severity).toBe(MonitorSeveritySchema.enum.PAUSED);const updated = await MonitorService.update(editor, {...baseMonitorInput(projectId),id: created.id,- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,});- expect(updated.severity).toBe("UNKNOWN");+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);expect(updated.severityChangedAt).not.toBeNull();});@@ -215,7 +222,10 @@ describe("MonitorService (integration)", () => {);await prisma.monitor.update({where: { id: created.id },- data: { severity: "ALERT", severityChangedAt: new Date() },+ data: {+ severity: MonitorSeveritySchema.enum.ALERT,+ severityChangedAt: new Date(),+ },});const { status, ...withoutStatus } = baseMonitorInput(projectId);@@ -226,16 +236,16 @@ describe("MonitorService (integration)", () => {});expect(updated.name).toBe("Renamed");- expect(updated.status).toBe("ACTIVE");- expect(updated.severity).toBe("ALERT");+ expect(updated.status).toBe(MonitorStatusSchema.enum.ACTIVE);+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.ALERT);});it("does not resurrect a paused monitor when status is omitted", async () => {const created = await MonitorService.create(creator, {...baseMonitorInput(projectId),- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});- expect(created.severity).toBe("PAUSED");+ expect(created.severity).toBe(MonitorSeveritySchema.enum.PAUSED);const { status, ...withoutStatus } = baseMonitorInput(projectId);const updated = await MonitorService.update(editor, {@@ -244,8 +254,8 @@ describe("MonitorService (integration)", () => {name: "Renamed",});- expect(updated.status).toBe("PAUSED");- expect(updated.severity).toBe("PAUSED");+ expect(updated.status).toBe(MonitorStatusSchema.enum.PAUSED);+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.PAUSED);});it("preserves worker-owned severity when status does not change", async () => {@@ -255,7 +265,10 @@ describe("MonitorService (integration)", () => {);await prisma.monitor.update({where: { id: created.id },- data: { severity: "ALERT", severityChangedAt: new Date() },+ data: {+ severity: MonitorSeveritySchema.enum.ALERT,+ severityChangedAt: new Date(),+ },});const updated = await MonitorService.update(editor, {@@ -264,7 +277,7 @@ describe("MonitorService (integration)", () => {name: "Renamed",});- expect(updated.severity).toBe("ALERT");+ expect(updated.severity).toBe(MonitorSeveritySchema.enum.ALERT);});it("clears worker lifecycle stamps when update changes schedulerBatchId", async () => {diff --git a/web/src/__tests__/server/monitors.servertest.ts b/web/src/__tests__/server/monitors.servertest.tsindex 7070933fad..29d61d90fc 100644--- a/web/src/__tests__/server/monitors.servertest.ts+++ b/web/src/__tests__/server/monitors.servertest.ts@@ -5,6 +5,12 @@ import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";import type { Session } from "next-auth";import { v4 } from "uuid";import { type Role } from "@langfuse/shared/src/db";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";type RoleName = keyof typeof Role;@@ -103,12 +109,12 @@ const validMonitorInput = (projectId: string) => ({filters: [],metric: { measure: "count", aggregation: "count" as const },window: "5m" as const,- thresholdOperator: "GT" as const,+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" as const },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" as const },- status: "ACTIVE" as const,+ status: MonitorStatusSchema.enum.ACTIVE,name: "High error rate",tags: [],triggerIds: ["trig_01"],@@ -172,14 +178,14 @@ describe("monitors trpc", () => {);await prisma.monitor.update({where: { id: created.id },- data: { status: "ERROR_BAD_QUERY" },+ data: { status: MonitorStatusSchema.enum.ERROR_BAD_QUERY },});const fetched = await caller.monitors.get({projectId: project.id,id: created.id,});- expect(fetched.status).toBe("ERROR_BAD_QUERY");+ expect(fetched.status).toBe(MonitorStatusSchema.enum.ERROR_BAD_QUERY);});});@@ -221,7 +227,7 @@ describe("monitors trpc", () => {await expect(caller.monitors.create({...validMonitorInput(project.id),- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: 100,}),@@ -332,7 +338,7 @@ describe("monitors trpc", () => {});await prisma.monitor.update({where: { id: a.id },- data: { severity: "ALERT" },+ data: { severity: MonitorSeveritySchema.enum.ALERT },});const result = await caller.monitors.all({@@ -345,7 +351,7 @@ describe("monitors trpc", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],},],});@@ -368,7 +374,7 @@ describe("monitors trpc", () => {await caller.monitors.update({...validMonitorInput(project.id),id: a.id,- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});const result = await caller.monitors.all({@@ -381,7 +387,7 @@ describe("monitors trpc", () => {type: "stringOptions",column: "severity",operator: "none of",- value: ["PAUSED"],+ value: [MonitorSeveritySchema.enum.PAUSED],},],});@@ -394,32 +400,32 @@ describe("monitors trpc", () => {const created = await caller.monitors.create(validMonitorInput(project.id),);- expect(created.severity).toBe("UNKNOWN");+ expect(created.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);const paused = await caller.monitors.update({...validMonitorInput(project.id),id: created.id,- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});- expect(paused.status).toBe("PAUSED");- expect(paused.severity).toBe("PAUSED");+ expect(paused.status).toBe(MonitorStatusSchema.enum.PAUSED);+ expect(paused.severity).toBe(MonitorSeveritySchema.enum.PAUSED);});it("flipping status PAUSED → ACTIVE via update resets severity to UNKNOWN", async () => {const { project, caller } = await prepare();const created = await caller.monitors.create({...validMonitorInput(project.id),- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});- expect(created.severity).toBe("PAUSED");+ expect(created.severity).toBe(MonitorSeveritySchema.enum.PAUSED);const resumed = await caller.monitors.update({...validMonitorInput(project.id),id: created.id,- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,});- expect(resumed.status).toBe("ACTIVE");- expect(resumed.severity).toBe("UNKNOWN");+ expect(resumed.status).toBe(MonitorStatusSchema.enum.ACTIVE);+ expect(resumed.severity).toBe(MonitorSeveritySchema.enum.UNKNOWN);});it("filters by tags (any of)", async () => {@@ -495,11 +501,11 @@ describe("monitors trpc", () => {});await prisma.monitor.update({where: { id: seeded[0].id },- data: { status: "PAUSED" },+ data: { status: MonitorStatusSchema.enum.PAUSED },});await prisma.monitor.update({where: { id: seeded[1].id },- data: { status: "ERROR_BAD_QUERY" },+ data: { status: MonitorStatusSchema.enum.ERROR_BAD_QUERY },});await expect(diff --git a/web/src/features/monitors/components/MonitorForm.clienttest.ts b/web/src/features/monitors/components/MonitorForm.clienttest.tsindex d85c6bb9d5..d6509ae204 100644--- a/web/src/features/monitors/components/MonitorForm.clienttest.ts+++ b/web/src/features/monitors/components/MonitorForm.clienttest.ts@@ -4,6 +4,10 @@ import {CreateMonitorSchema,ErrorAtLeastOneTrigger,type Monitor,+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,} from "@langfuse/shared/monitors";import { __test } from "./MonitorForm";@@ -94,16 +98,16 @@ describe("monitorToDefaults", () => {filters: [],metric: { measure: "count", aggregation: "count" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 10,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },name: "My Monitor",tags: [],triggerIds: ["t-a", "t-b"],- status: "ACTIVE",- severity: "UNKNOWN",+ status: MonitorStatusSchema.enum.ACTIVE,+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,createdAt: new Date(),diff --git a/web/src/features/monitors/components/MonitorForm.tsx b/web/src/features/monitors/components/MonitorForm.tsxindex 55d9ba43d7..8cc40321b1 100644--- a/web/src/features/monitors/components/MonitorForm.tsx+++ b/web/src/features/monitors/components/MonitorForm.tsx@@ -62,8 +62,12 @@ import {getValidMonitorFilterColumns,type Monitor,type MonitorNoData,+ MonitorNoDataModeSchema,type MonitorRenotify,+ MonitorSeveritySchema,+ MonitorStatusSchema,type MonitorThresholdOperator,+ MonitorThresholdOperatorSchema,type MonitorView,MonitorViewSchema,type MonitorWindow,@@ -78,6 +82,7 @@ import TagManager from "@/src/features/tag/components/TagManager";import { MonitorChartPreview } from "./MonitorChartPreview";import { MonitorAutomationsPanel } from "./MonitorAutomationsPanel";import { MonitorSeverityBadge } from "./MonitorSeverityBadge";+import { Badge } from "@/src/components/ui/badge";/** windowLabels maps each MonitorWindow enum value to a human label. */const windowLabels: Record<MonitorWindow, string> = {@@ -103,16 +108,6 @@ const operatorLabels: Record<MonitorThresholdOperator, string> = {NEQ: "not equal to",};-/** triggerOperatorOptions lists the MonitorThresholdOperators shown in the trigger-condition dropdown. */-const triggerOperatorOptions: ReadonlyArray<MonitorThresholdOperator> = [- "GT",- "LT",- "GTE",- "LTE",- "EQ",- "NEQ",-];-/** operatorSymbol maps each MonitorThresholdOperator to a single math glyph. */const operatorSymbol: Record<MonitorThresholdOperator, string> = {GT: ">",@@ -137,13 +132,13 @@ const createDefaults = (projectId: string): Partial<CreateMonitor> => ({filters: [],metric: { measure: "count", aggregation: "count" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO },renotify: { mode: "OFF" },tags: [],triggerIds: [],- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,});/** monitorToDefaults maps a persisted Monitor into the edit form's defaults. */@@ -387,7 +382,8 @@ export const MonitorForm = ({const view = (watched.view ?? "observations") as MonitorView;const measure = watched.metric?.measure ?? "count";const aggregation = watched.metric?.aggregation ?? "count";- const op = (watched.thresholdOperator ?? "GT") as MonitorThresholdOperator;+ const op = (watched.thresholdOperator ??+ MonitorThresholdOperatorSchema.enum.GT) as MonitorThresholdOperator;const threshold = watched.alertThreshold;const aggLabel = startCase(aggregation);const viewLabel = viewLabels[view];@@ -635,7 +631,9 @@ export const MonitorForm = ({field.onChange(next);// A warning band before a "not equal" alert has no// meaningful ordering, so drop any stale value.- if (next === "NEQ") {+ if (+ next === MonitorThresholdOperatorSchema.enum.NEQ+ ) {form.setValue("warningThreshold", null, {shouldValidate: true,});@@ -649,7 +647,7 @@ export const MonitorForm = ({</SelectTrigger></FormControl><SelectContent>- {triggerOperatorOptions.map((op) => (+ {MonitorThresholdOperatorSchema.options.map((op) => (<SelectItem key={op} value={op}>{operatorLabels[op]}</SelectItem>@@ -665,7 +663,9 @@ export const MonitorForm = ({render={({ field }) => (<FormItem><div className="flex items-center gap-2">- <MonitorSeverityBadge severity="ALERT" />+ <MonitorSeverityBadge+ severity={MonitorSeveritySchema.enum.ALERT}+ /><span className="text-sm whitespace-nowrap">Threshold</span>@@ -673,7 +673,8 @@ export const MonitorForm = ({{operatorSymbol[(watched.thresholdOperator ??- "GT") as keyof typeof operatorSymbol+ MonitorThresholdOperatorSchema.enum+ .GT) as keyof typeof operatorSymbol]}</span>@@ -701,9 +702,16 @@ export const MonitorForm = ({control={form.control}name="warningThreshold"render={({ field }) => (- <FormItem hidden={watched.thresholdOperator === "NEQ"}>+ <FormItem+ hidden={+ watched.thresholdOperator ===+ MonitorThresholdOperatorSchema.enum.NEQ+ }+ ><div className="flex items-center gap-2">- <MonitorSeverityBadge severity="WARNING" />+ <MonitorSeverityBadge+ severity={MonitorSeveritySchema.enum.WARNING}+ /><span className="text-sm whitespace-nowrap">Threshold</span>@@ -711,7 +719,8 @@ export const MonitorForm = ({{operatorSymbol[(watched.thresholdOperator ??- "GT") as keyof typeof operatorSymbol+ MonitorThresholdOperatorSchema.enum+ .GT) as keyof typeof operatorSymbol]}</span>@@ -772,7 +781,7 @@ export const MonitorForm = ({<AccordionTrigger className="justify-start gap-2 py-2 text-sm font-medium [&>svg]:order-first [&>svg]:-rotate-90 [&[data-state=open]>svg]:rotate-0">Advanced Options</AccordionTrigger>- <AccordionContent className="space-y-6 pt-2">+ <AccordionContent className="space-y-6 px-1 pt-2"><FormFieldcontrol={form.control}name="noData"@@ -909,7 +918,8 @@ export const MonitorForm = ({"count") as CreateMonitor["metric"]["aggregation"]}thresholdOperator={- (watched.thresholdOperator ?? "GT") as MonitorThresholdOperator+ watched.thresholdOperator ??+ MonitorThresholdOperatorSchema.enum.GT}alertThreshold={watched.alertThreshold}warningThreshold={watched.warningThreshold ?? null}@@ -974,14 +984,19 @@ const NoDataField = ({disabled?: boolean;}) => (<div className="space-y-2">- <Label>On no data</Label>+ <Label>When there is no data</Label><Selectvalue={value.mode}onValueChange={(mode) =>onChange(- mode === "NOTIFY"- ? { mode: "NOTIFY", intervalMinutes: 60 }- : { mode: "SILENT" },+ mode === MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA+ ? {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 60,+ }+ : {+ mode: mode as Exclude<MonitorNoData["mode"], "NOTIFY_NO_DATA">,+ },)}disabled={disabled}@@ -990,15 +1005,44 @@ const NoDataField = ({<SelectValue /></SelectTrigger><SelectContent>- <SelectItem value="SILENT">Silent</SelectItem>- <SelectItem value="NOTIFY">Notify after sustained no-data</SelectItem>+ <SelectItem value={MonitorNoDataModeSchema.enum.SUBSTITUTE_ZERO}>+ <span className="inline-flex items-center gap-1.5">+ Treat missing data as+ <code className="bg-secondary rounded border px-0.5">0</code>+ </span>+ </SelectItem>+ <SelectItem value={MonitorNoDataModeSchema.enum.LAST_SEVERITY}>+ <span className="inline-flex items-center gap-1.5">+ Keep the previous+ <Badge+ variant="secondary"+ className="w-20 justify-center bg-slate-500 py-1 text-slate-50 hover:bg-slate-500"+ >+ SEVERITY+ </Badge>+ </span>+ </SelectItem>+ <SelectItem value={MonitorNoDataModeSchema.enum.SHOW_NO_DATA}>+ <span className="inline-flex items-center gap-1.5">+ Show severity+ <MonitorSeverityBadge+ severity={MonitorSeveritySchema.enum.NO_DATA}+ />+ </span>+ </SelectItem>+ <SelectItem value={MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA}>+ <span className="inline-flex items-center gap-1.5">+ Notify after sustained+ <MonitorSeverityBadge+ severity={MonitorSeveritySchema.enum.NO_DATA}+ />+ </span>+ </SelectItem></SelectContent></Select>- {value.mode === "NOTIFY" && (+ {value.mode === MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA && (<div className="flex items-center gap-2">- <Label className="text-muted-foreground text-xs">- Notify every (minutes)- </Label>+ <Label className="text-muted-foreground text-xs">Notify after</Label><Inputtype="number"min={1}@@ -1006,13 +1050,14 @@ const NoDataField = ({value={value.intervalMinutes}onChange={(e) =>onChange({- mode: "NOTIFY",+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,intervalMinutes: Math.max(1, Number(e.target.value) || 1),})}disabled={disabled}- className="w-32"+ className="w-24"/>+ <Label className="text-muted-foreground text-xs">minutes</Label></div>)}</div>diff --git a/web/src/features/monitors/components/MonitorsTable.clienttest.ts b/web/src/features/monitors/components/MonitorsTable.clienttest.tsindex 1584f220a2..d9ab283efd 100644--- a/web/src/features/monitors/components/MonitorsTable.clienttest.ts+++ b/web/src/features/monitors/components/MonitorsTable.clienttest.ts@@ -1,7 +1,13 @@import { describe, expect, it } from "vitest";import { type FilterState } from "@langfuse/shared";-import { type Monitor } from "@langfuse/shared/monitors";+import {+ type Monitor,+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";import { __test } from "./MonitorsTable";@@ -15,16 +21,16 @@ const monitorFixture = (status: Monitor["status"]): Monitor => ({filters: [],metric: { measure: "count", aggregation: "count" },window: "5m",- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 10,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },name: "My Monitor",tags: ["prod"],triggerIds: ["t-a"],status,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: null,alertedAt: null,createdAt: new Date(),@@ -44,7 +50,10 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT", "WARNING"],+ value: [+ MonitorSeveritySchema.enum.ALERT,+ MonitorSeveritySchema.enum.WARNING,+ ],},];expect(filterStateToListMonitorFilter(state)).toEqual([@@ -52,7 +61,10 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT", "WARNING"],+ value: [+ MonitorSeveritySchema.enum.ALERT,+ MonitorSeveritySchema.enum.WARNING,+ ],},]);});@@ -63,7 +75,7 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["NO_DATA"],+ value: [MonitorSeveritySchema.enum.NO_DATA],},];expect(filterStateToListMonitorFilter(state)).toEqual([@@ -71,7 +83,10 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["NO_DATA", "UNKNOWN"],+ value: [+ MonitorSeveritySchema.enum.NO_DATA,+ MonitorSeveritySchema.enum.UNKNOWN,+ ],},]);});@@ -82,7 +97,7 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "none of",- value: ["NO_DATA"],+ value: [MonitorSeveritySchema.enum.NO_DATA],},];expect(filterStateToListMonitorFilter(state)).toEqual([@@ -90,7 +105,10 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "none of",- value: ["NO_DATA", "UNKNOWN"],+ value: [+ MonitorSeveritySchema.enum.NO_DATA,+ MonitorSeveritySchema.enum.UNKNOWN,+ ],},]);});@@ -101,7 +119,11 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["NO_DATA", "UNKNOWN", "ALERT"],+ value: [+ MonitorSeveritySchema.enum.NO_DATA,+ MonitorSeveritySchema.enum.UNKNOWN,+ MonitorSeveritySchema.enum.ALERT,+ ],},];expect(filterStateToListMonitorFilter(state)).toEqual([@@ -109,7 +131,11 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["NO_DATA", "UNKNOWN", "ALERT"],+ value: [+ MonitorSeveritySchema.enum.NO_DATA,+ MonitorSeveritySchema.enum.UNKNOWN,+ MonitorSeveritySchema.enum.ALERT,+ ],},]);});@@ -150,13 +176,13 @@ describe("filterStateToListMonitorFilter", () => {type: "stringOptions",column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],},{type: "stringOptions",column: "severity",operator: "none of",- value: ["PAUSED"],+ value: [MonitorSeveritySchema.enum.PAUSED],},];expect(filterStateToListMonitorFilter(state)).toEqual([]);@@ -165,19 +191,21 @@ describe("filterStateToListMonitorFilter", () => {describe("buildStatusToggleUpdate", () => {it("ACTIVE monitor: flips status to PAUSED", () => {- expect(buildStatusToggleUpdate(monitorFixture("ACTIVE")).status).toBe(- "PAUSED",- );+ expect(+ buildStatusToggleUpdate(monitorFixture(MonitorStatusSchema.enum.ACTIVE))+ .status,+ ).toBe(MonitorStatusSchema.enum.PAUSED);});it("PAUSED monitor: flips status to ACTIVE", () => {- expect(buildStatusToggleUpdate(monitorFixture("PAUSED")).status).toBe(- "ACTIVE",- );+ expect(+ buildStatusToggleUpdate(monitorFixture(MonitorStatusSchema.enum.PAUSED))+ .status,+ ).toBe(MonitorStatusSchema.enum.ACTIVE);});it("carries the full config so only status changes", () => {- const monitor = monitorFixture("ACTIVE");+ const monitor = monitorFixture(MonitorStatusSchema.enum.ACTIVE);expect(buildStatusToggleUpdate(monitor)).toEqual({id: monitor.id,projectId: monitor.projectId,@@ -193,7 +221,7 @@ describe("buildStatusToggleUpdate", () => {name: monitor.name,tags: monitor.tags,triggerIds: monitor.triggerIds,- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,});});});diff --git a/worker/src/__tests__/monitorProcessor.test.ts b/worker/src/__tests__/monitorProcessor.test.tsindex 778eaa1bfa..df16bf8d2a 100644--- a/worker/src/__tests__/monitorProcessor.test.ts+++ b/worker/src/__tests__/monitorProcessor.test.ts@@ -11,6 +11,12 @@ import {type MonitorQueueEventInput,type GetTriggerConfigurations,} from "@langfuse/shared/monitors/server";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";import { prisma } from "@langfuse/shared/src/db";import type { Prisma, PrismaClient } from "@prisma/client";@@ -36,7 +42,12 @@ type SeedOverrides = Partial<{alertThreshold: number;warningThreshold: number | null;thresholdOperator: ThresholdOperator;- noData: { mode: "SILENT" } | { mode: "NOTIFY"; intervalMinutes: number };+ noData:+ | { mode: "SHOW_NO_DATA" }+ | {+ mode: "NOTIFY_NO_DATA";+ intervalMinutes: number;+ };renotify: { mode: "OFF" } | { mode: "EVERY"; intervalMinutes: number };severity: MonitorSeverity;severityChangedAt: Date | null;@@ -109,7 +120,11 @@ const matchAnyAlertTrigger: TriggerSeed = {{column: "severity",operator: "any of",- value: ["WARNING", "ALERT", "NO_DATA"],+ value: [+ MonitorSeveritySchema.enum.WARNING,+ MonitorSeveritySchema.enum.ALERT,+ MonitorSeveritySchema.enum.NO_DATA,+ ],type: "stringOptions",},],@@ -132,23 +147,24 @@ async function seedMonitor(projectId: string, seed: MonitorSeed) {}) as unknown as Prisma.InputJsonValue,windowMs: seed.windowMs ?? fiveMinutesMs,cadenceMs: oneMinuteMs,- thresholdOperator: seed.thresholdOperator ?? "GT",+ thresholdOperator:+ seed.thresholdOperator ?? MonitorThresholdOperatorSchema.enum.GT,alertThreshold: seed.alertThreshold ?? 100,warningThreshold: seed.warningThreshold ?? null,noData: (seed.noData ?? {- mode: "SILENT",+ mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA,}) as unknown as Prisma.InputJsonValue,renotify: (seed.renotify ?? {mode: "OFF",}) as unknown as Prisma.InputJsonValue,- status: seed.status ?? "ACTIVE",+ status: seed.status ?? MonitorStatusSchema.enum.ACTIVE,schedulerBatchId: seed.schedulerBatchId ?? 0n,nextRunAt: new Date("2099-01-01T00:00:00.000Z"),lastPublishedAt:seed.lastPublishedAt === undefined ? runAt : seed.lastPublishedAt,lastClaimedAt: seed.lastClaimedAt ?? null,lastCompletedAt: seed.lastCompletedAt ?? null,- severity: seed.severity ?? "UNKNOWN",+ severity: seed.severity ?? MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: seed.severityChangedAt ?? null,alertedAt: seed.alertedAt ?? null,tags: seed.tags ?? [],@@ -272,8 +288,8 @@ function wrapDbPauseBeforeComplete(await target.monitor.updateMany({where: { projectId },data: {- status: "PAUSED",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: at,},});@@ -318,7 +334,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -329,7 +345,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -343,7 +359,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -354,7 +370,7 @@ const cases: ProcessCase[] = [{column: "severity",operator: "any of",- value: ["WARNING"],+ value: [MonitorSeveritySchema.enum.WARNING],type: "stringOptions",},],@@ -365,7 +381,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -379,7 +395,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -396,7 +412,7 @@ const cases: ProcessCase[] = [apiVersion: "v1",payload: {monitorId: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,message: {title: `[ALERT] Test ${monitorAId}`,body: "`count(observations.count)` is **above** `100` over the last **5m**",@@ -409,7 +425,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -423,7 +439,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: tenMinutesAgo,lastPublishedAt: runAt,@@ -437,7 +453,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -451,7 +467,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: tenMinutesAgo,lastPublishedAt: runAt,@@ -465,7 +481,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: tenMinutesAgo,lastClaimedAt: justAfterRunAt,@@ -479,10 +495,13 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,- noData: { mode: "NOTIFY", intervalMinutes: 5 },+ noData: {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 5,+ },},],ch: [{ count_count: 0 }],@@ -492,7 +511,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "NO_DATA",+ severity: MonitorSeveritySchema.enum.NO_DATA,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -506,10 +525,10 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,alertThreshold: 3,- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,},],ch: [{ count_count: 5 }],@@ -520,13 +539,16 @@ const cases: ProcessCase[] = [payload: {type: "monitor-alert",apiVersion: "v1",- payload: { monitorId: monitorAId, severity: "ALERT" },+ payload: {+ monitorId: monitorAId,+ severity: MonitorSeveritySchema.enum.ALERT,+ },},},rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -540,10 +562,13 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,- noData: { mode: "NOTIFY", intervalMinutes: 5 },+ noData: {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 5,+ },},],ch: [{}],@@ -553,7 +578,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "NO_DATA",+ severity: MonitorSeveritySchema.enum.NO_DATA,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -567,10 +592,10 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },},],ch: [{}],@@ -580,7 +605,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "NO_DATA",+ severity: MonitorSeveritySchema.enum.NO_DATA,severityChangedAt: justAfterRunAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -594,7 +619,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -606,7 +631,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: null,@@ -620,7 +645,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -631,8 +656,8 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- status: "ERROR_BAD_QUERY",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: justAfterRunAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -646,7 +671,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -661,8 +686,8 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- status: "ERROR_BAD_QUERY",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: justAfterRunAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -676,7 +701,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -688,7 +713,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -702,7 +727,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,},@@ -718,8 +743,8 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- status: "ACTIVE",- severity: "OK",+ status: MonitorStatusSchema.enum.ACTIVE,+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -733,7 +758,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -746,7 +771,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -760,7 +785,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -773,7 +798,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -789,7 +814,7 @@ const cases: ProcessCase[] = [{id: monitorAId,schedulerBatchId: 7n,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,lastClaimedAt: runAt,@@ -799,7 +824,7 @@ const cases: ProcessCase[] = [{id: monitorBId,schedulerBatchId: 7n,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -813,7 +838,7 @@ const cases: ProcessCase[] = [apiVersion: "v1",payload: {monitorId: monitorBId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,},},},@@ -821,7 +846,7 @@ const cases: ProcessCase[] = [// done: untouched{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: runAt,@@ -830,7 +855,7 @@ const cases: ProcessCase[] = [// claimable: fully processed{id: monitorBId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -844,7 +869,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -867,7 +892,10 @@ const cases: ProcessCase[] = [payload: {type: "monitor-alert",apiVersion: "v1",- payload: { monitorId: monitorAId, severity: "ALERT" },+ payload: {+ monitorId: monitorAId,+ severity: MonitorSeveritySchema.enum.ALERT,+ },},},{@@ -875,14 +903,17 @@ const cases: ProcessCase[] = [payload: {type: "monitor-alert",apiVersion: "v1",- payload: { monitorId: monitorAId, severity: "ALERT" },+ payload: {+ monitorId: monitorAId,+ severity: MonitorSeveritySchema.enum.ALERT,+ },},},],rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -896,7 +927,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},],@@ -911,7 +942,7 @@ const cases: ProcessCase[] = [{column: "severity",operator: "any of",- value: ["WARNING"],+ value: [MonitorSeveritySchema.enum.WARNING],type: "stringOptions",},],@@ -925,13 +956,16 @@ const cases: ProcessCase[] = [payload: {type: "monitor-alert",apiVersion: "v1",- payload: { monitorId: monitorAId, severity: "ALERT" },+ payload: {+ monitorId: monitorAId,+ severity: MonitorSeveritySchema.enum.ALERT,+ },},},rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -945,7 +979,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: laterPublish,},@@ -957,7 +991,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: null,@@ -971,7 +1005,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: null,},],@@ -982,7 +1016,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,lastClaimedAt: null,@@ -996,7 +1030,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,lastClaimedAt: justAfterRunAt,lastCompletedAt: null,@@ -1009,7 +1043,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -1023,7 +1057,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,lastClaimedAt: runAt,@@ -1037,7 +1071,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: runAt,@@ -1051,7 +1085,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: tenMinutesAgo,lastPublishedAt: runAt,@@ -1066,7 +1100,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: tenMinutesAgo,alertedAt: tenMinutesAgo,lastClaimedAt: laterPublish,@@ -1080,7 +1114,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastPublishedAt: runAt,@@ -1094,7 +1128,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "PAUSED",+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: pausedAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -1108,7 +1142,7 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,alertedAt: null,lastPublishedAt: runAt, // worker claims event with publishedAt=runAt, stamps lastClaimedAt=justAfterRunAt@@ -1122,7 +1156,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "OK", // complete CAS no-ops → prior severity preserved+ severity: MonitorSeveritySchema.enum.OK, // complete CAS no-ops → prior severity preservedseverityChangedAt: tenMinutesAgo,alertedAt: null,lastClaimedAt: justAfterRunAt, // worker's claim stamp, untouched by rescue@@ -1136,8 +1170,8 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- status: "PAUSED",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,+ severity: MonitorSeveritySchema.enum.PAUSED,lastPublishedAt: runAt,lastClaimedAt: null,lastCompletedAt: null,@@ -1150,7 +1184,7 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- severity: "PAUSED",+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: null,alertedAt: null,lastClaimedAt: null,@@ -1164,12 +1198,12 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,},{id: monitorBId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,metric: { measure: "bogus_measure", aggregation: "count" },@@ -1183,14 +1217,17 @@ const cases: ProcessCase[] = [payload: {type: "monitor-alert",apiVersion: "v1",- payload: { monitorId: monitorAId, severity: "ALERT" },+ payload: {+ monitorId: monitorAId,+ severity: MonitorSeveritySchema.enum.ALERT,+ },},},rows: [{id: monitorAId,- status: "ACTIVE",- severity: "ALERT",+ status: MonitorStatusSchema.enum.ACTIVE,+ severity: MonitorSeveritySchema.enum.ALERT,severityChangedAt: justAfterRunAt,alertedAt: justAfterRunAt,lastClaimedAt: justAfterRunAt,@@ -1198,8 +1235,8 @@ const cases: ProcessCase[] = [},{id: monitorBId,- status: "ERROR_BAD_QUERY",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: justAfterRunAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -1213,11 +1250,14 @@ const cases: ProcessCase[] = [monitors: [{id: monitorAId,- severity: "OK",+ severity: MonitorSeveritySchema.enum.OK,severityChangedAt: tenMinutesAgo,lastPublishedAt: runAt,metric: { measure: "bogus_measure", aggregation: "count" },- noData: { mode: "NOTIFY", intervalMinutes: 5 },+ noData: {+ mode: MonitorNoDataModeSchema.enum.NOTIFY_NO_DATA,+ intervalMinutes: 5,+ },},],ch: [{ count_count: 0 }],@@ -1227,8 +1267,8 @@ const cases: ProcessCase[] = [rows: [{id: monitorAId,- status: "ERROR_BAD_QUERY",- severity: "PAUSED",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,+ severity: MonitorSeveritySchema.enum.PAUSED,severityChangedAt: justAfterRunAt,alertedAt: null,lastClaimedAt: justAfterRunAt,@@ -1398,7 +1438,7 @@ describe("MonitorProcessor.process evaluation offset", () => {const monitorId = `m_off_${v4()}`;await seedMonitor(projectId, {id: monitorId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,triggerIds: ["trig_off"],});@@ -1471,7 +1511,7 @@ describe("MonitorProcessor.process wire deserialization", () => {const monitorId = `m_wire_${v4()}`;await seedMonitor(projectId, {id: monitorId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,triggerIds: ["trig_wire"],});@@ -1543,7 +1583,7 @@ describe("MonitorProcessor.process count metric", () => {const monitorId = `m_count_${v4()}`;await seedMonitor(projectId, {id: monitorId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,});@@ -1590,7 +1630,7 @@ describe("MonitorProcessor.process executeQuery failure logging", () => {try {await seedMonitor(projectId, {id: monitorAId,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,lastPublishedAt: runAt,});diff --git a/worker/src/__tests__/monitorScheduler.test.ts b/worker/src/__tests__/monitorScheduler.test.tsindex 72d4a31e98..ec3b1a6cab 100644--- a/worker/src/__tests__/monitorScheduler.test.ts+++ b/worker/src/__tests__/monitorScheduler.test.ts@@ -5,6 +5,11 @@ import {MonitorScheduler,type MonitorQueueEventInput,} from "@langfuse/shared/monitors/server";+import {+ MonitorNoDataModeSchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";import { prisma } from "@langfuse/shared/src/db";import type { Prisma } from "@prisma/client";@@ -86,12 +91,14 @@ async function seedMonitor(projectId: string, seed: MonitorSeed) {}) as unknown as Prisma.InputJsonValue,windowMs: seed.windowMs ?? 5n * oneMinuteMs,cadenceMs: seed.cadenceMs ?? oneMinuteMs,- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: 100,warningThreshold: null,- noData: { mode: "SILENT" } as unknown as Prisma.InputJsonValue,+ noData: {+ mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA,+ } as unknown as Prisma.InputJsonValue,renotify: { mode: "OFF" } as unknown as Prisma.InputJsonValue,- status: seed.status ?? "ACTIVE",+ status: seed.status ?? MonitorStatusSchema.enum.ACTIVE,schedulerBatchId: seed.schedulerBatchId ?? 0n,nextRunAt: seed.nextRunAt === undefined ? null : seed.nextRunAt,lastPublishedAt: seed.lastPublishedAt ?? null,@@ -372,7 +379,7 @@ const cases: SchedulerCase[] = [monitors: [{id: "m_paused",- status: "PAUSED",+ status: MonitorStatusSchema.enum.PAUSED,nextRunAt: prevCadence,},],@@ -394,7 +401,7 @@ const cases: SchedulerCase[] = [monitors: [{id: "m_error",- status: "ERROR_BAD_QUERY",+ status: MonitorStatusSchema.enum.ERROR_BAD_QUERY,nextRunAt: prevCadence,},],diff --git a/worker/src/__tests__/monitorWorkerIntegration.test.ts b/worker/src/__tests__/monitorWorkerIntegration.test.tsindex e30a42fe78..746a4b7ba6 100644--- a/worker/src/__tests__/monitorWorkerIntegration.test.ts+++ b/worker/src/__tests__/monitorWorkerIntegration.test.ts@@ -28,6 +28,12 @@ import {MonitorQueueEventSchema,MonitorScheduler,} from "@langfuse/shared/monitors/server";+import {+ MonitorNoDataModeSchema,+ MonitorSeveritySchema,+ MonitorStatusSchema,+ MonitorThresholdOperatorSchema,+} from "@langfuse/shared/monitors";import { prisma } from "@langfuse/shared/src/db";import { encrypt, generateWebhookSecret } from "@langfuse/shared/encryption";@@ -63,7 +69,7 @@ describe("monitor-alert e2e (scheduler → processor → dispatcher → webhook{column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],type: "stringOptions",},],@@ -128,7 +134,7 @@ describe("monitor-alert e2e (scheduler → processor → dispatcher → webhookapiVersion: "v1",payload: {monitorId,- severity: "ALERT",+ severity: MonitorSeveritySchema.enum.ALERT,fromTimestamp: expectedFrom,toTimestamp: expectedTo,},@@ -144,7 +150,7 @@ describe("monitor-alert e2e (scheduler → processor → dispatcher → webhook{column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],type: "stringOptions",},],@@ -214,7 +220,7 @@ describe("monitor-alert e2e (scheduler → processor → dispatcher → webhook{column: "severity",operator: "any of",- value: ["ALERT"],+ value: [MonitorSeveritySchema.enum.ALERT],type: "stringOptions",},],@@ -377,18 +383,18 @@ async function seedMonitor(args: {metric: { measure: "count", aggregation: "count" },windowMs: 5n * 60n * 1000n,cadenceMs: 60n * 1000n,- thresholdOperator: "GT",+ thresholdOperator: MonitorThresholdOperatorSchema.enum.GT,alertThreshold: args.alertThreshold,warningThreshold: null,- noData: { mode: "SILENT" },+ noData: { mode: MonitorNoDataModeSchema.enum.SHOW_NO_DATA },renotify: { mode: "OFF" },- status: "ACTIVE",+ status: MonitorStatusSchema.enum.ACTIVE,schedulerBatchId: 0n,nextRunAt: new Date(Date.now() - 1000),lastPublishedAt: null,lastClaimedAt: null,lastCompletedAt: null,- severity: "UNKNOWN",+ severity: MonitorSeveritySchema.enum.UNKNOWN,severityChangedAt: null,alertedAt: null,tags: [],