From d62da19308f3df8a19853833925fa350d0bfd259 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Fri, 20 Mar 2026 13:45:10 +0000 Subject: [PATCH] feat(kubernetes): add on-call policy dropdown options to Kubernetes criteria form --- .../KubernetesSimplifiedCriteriaForm.tsx | 91 ++++++++++++++++++- .../Components/Form/Monitor/MonitorStep.tsx | 1 + 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/App/FeatureSet/Dashboard/src/Components/Form/Monitor/KubernetesMonitor/KubernetesSimplifiedCriteriaForm.tsx b/App/FeatureSet/Dashboard/src/Components/Form/Monitor/KubernetesMonitor/KubernetesSimplifiedCriteriaForm.tsx index c835724a52..8a15f3a0a1 100644 --- a/App/FeatureSet/Dashboard/src/Components/Form/Monitor/KubernetesMonitor/KubernetesSimplifiedCriteriaForm.tsx +++ b/App/FeatureSet/Dashboard/src/Components/Form/Monitor/KubernetesMonitor/KubernetesSimplifiedCriteriaForm.tsx @@ -30,6 +30,7 @@ export interface ComponentProps { monitorStatusDropdownOptions: Array; incidentSeverityDropdownOptions: Array; alertSeverityDropdownOptions: Array; + onCallPolicyDropdownOptions: Array; value?: MonitorCriteria | undefined; onChange: (value: MonitorCriteria) => void; } @@ -48,6 +49,8 @@ function extractStateFromCriteria(criteria: MonitorCriteria | undefined): { alertSeverityId: string; incidentSeverityId: string; autoResolve: boolean; + alertOnCallPolicyIds: Array; + incidentOnCallPolicyIds: Array; } { const defaults = { filterType: FilterType.GreaterThan, @@ -55,6 +58,8 @@ function extractStateFromCriteria(criteria: MonitorCriteria | undefined): { alertSeverityId: "", incidentSeverityId: "", autoResolve: true, + alertOnCallPolicyIds: [] as Array, + incidentOnCallPolicyIds: [] as Array, }; if (!criteria?.data?.monitorCriteriaInstanceArray?.length) { @@ -83,6 +88,8 @@ function extractStateFromCriteria(criteria: MonitorCriteria | undefined): { if (alert) { defaults.alertSeverityId = alert.alertSeverityId?.toString() || ""; defaults.autoResolve = alert.autoResolveAlert !== false; + defaults.alertOnCallPolicyIds = + alert.onCallPolicyIds?.map((id: ObjectID) => id.toString()) || []; } } @@ -91,6 +98,8 @@ function extractStateFromCriteria(criteria: MonitorCriteria | undefined): { if (incident) { defaults.incidentSeverityId = incident.incidentSeverityId?.toString() || ""; + defaults.incidentOnCallPolicyIds = + incident.onCallPolicyIds?.map((id: ObjectID) => id.toString()) || []; } } @@ -119,6 +128,12 @@ const KubernetesSimplifiedCriteriaForm: FunctionComponent = ( const [autoResolve, setAutoResolve] = useState( initialState.autoResolve, ); + const [alertOnCallPolicyIds, setAlertOnCallPolicyIds] = useState< + Array + >(initialState.alertOnCallPolicyIds); + const [incidentOnCallPolicyIds, setIncidentOnCallPolicyIds] = useState< + Array + >(initialState.incidentOnCallPolicyIds); // Find online/offline status IDs from monitor status options const offlineMonitorStatusId: ObjectID = new ObjectID( @@ -150,15 +165,21 @@ const KubernetesSimplifiedCriteriaForm: FunctionComponent = ( value: thresholdValue, }); - // Set auto-resolve on alerts and incidents + // Set auto-resolve and on-call policies on alerts and incidents if (offlineInstance.data?.alerts) { for (const alert of offlineInstance.data.alerts) { alert.autoResolveAlert = autoResolve; + alert.onCallPolicyIds = alertOnCallPolicyIds.map( + (id: string) => new ObjectID(id), + ); } } if (offlineInstance.data?.incidents) { for (const incident of offlineInstance.data.incidents) { incident.autoResolveIncident = autoResolve; + incident.onCallPolicyIds = incidentOnCallPolicyIds.map( + (id: string) => new ObjectID(id), + ); } } @@ -185,6 +206,8 @@ const KubernetesSimplifiedCriteriaForm: FunctionComponent = ( alertSeverityId, incidentSeverityId, autoResolve, + alertOnCallPolicyIds, + incidentOnCallPolicyIds, props.metricAlias, props.monitorName, ]); @@ -271,6 +294,72 @@ const KubernetesSimplifiedCriteriaForm: FunctionComponent = ( /> + {/* Alert On-Call Policy */} + {props.onCallPolicyDropdownOptions.length > 0 && ( +
+ + + alertOnCallPolicyIds.includes(o.value?.toString() || ""), + )} + onChange={( + value: DropdownValue | Array | null, + ) => { + if (Array.isArray(value)) { + setAlertOnCallPolicyIds( + value.map((v: DropdownValue) => v.toString()), + ); + } else if (value) { + setAlertOnCallPolicyIds([value.toString()]); + } else { + setAlertOnCallPolicyIds([]); + } + }} + isMultiSelect={true} + placeholder="Select on-call policies..." + /> +
+ )} + + {/* Incident On-Call Policy */} + {props.onCallPolicyDropdownOptions.length > 0 && ( +
+ + + incidentOnCallPolicyIds.includes(o.value?.toString() || ""), + )} + onChange={( + value: DropdownValue | Array | null, + ) => { + if (Array.isArray(value)) { + setIncidentOnCallPolicyIds( + value.map((v: DropdownValue) => v.toString()), + ); + } else if (value) { + setIncidentOnCallPolicyIds([value.toString()]); + } else { + setIncidentOnCallPolicyIds([]); + } + }} + isMultiSelect={true} + placeholder="Select on-call policies..." + /> +
+ )} + {/* Auto-Resolve */}
{ monitorStep.setMonitorCriteria(value);