From ffb744d71152831dd9f5be3acb0055cbeaff763d Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Tue, 9 Sep 2025 21:04:00 +0000 Subject: [PATCH] fix: properly handle 100% thresholds to disable alerts (addresses #434) When a threshold is set to 100%, it now effectively disables alerts for that metric. This allows users to turn off specific alerts without disabling all alerts for a resource. Also clears any existing alerts when threshold is changed to 100%. --- internal/alerts/alerts.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go index d3dd2b711..fa97ff630 100644 --- a/internal/alerts/alerts.go +++ b/internal/alerts/alerts.go @@ -923,6 +923,35 @@ func (m *Manager) checkMetric(resourceID, resourceName, node, instance, resource return } + // Special case: 100% threshold effectively disables alerts for this metric + if threshold.Trigger >= 100 { + log.Debug(). + Str("resource", resourceName). + Str("metric", metricType). + Float64("value", value). + Float64("threshold", threshold.Trigger). + Msg("Alert disabled (100% threshold)") + + // Clear any existing alert for this metric + alertID := fmt.Sprintf("%s-%s", resourceID, metricType) + m.mu.Lock() + if _, exists := m.activeAlerts[alertID]; exists { + delete(m.activeAlerts, alertID) + log.Info(). + Str("alertID", alertID). + Str("resource", resourceName). + Str("metric", metricType). + Msg("Cleared alert - threshold set to 100%") + + // Notify resolution + if m.onResolved != nil { + go m.onResolved(alertID) + } + } + m.mu.Unlock() + return + } + log.Debug(). Str("resource", resourceName). Str("metric", metricType).