AddAlert adds an alert to the store. Duplicates (same Type+Object) are skipped to prevent alert accumulation from repeated poll cycles detecting the same condition.
(alert Alert)
| 58 | // AddAlert adds an alert to the store. Duplicates (same Type+Object) are skipped |
| 59 | // to prevent alert accumulation from repeated poll cycles detecting the same condition. |
| 60 | func (s *ObservabilityStore) AddAlert(alert Alert) { |
| 61 | s.mu.Lock() |
| 62 | defer s.mu.Unlock() |
| 63 | |
| 64 | // Dedup: skip if same Type+Object already exists in window |
| 65 | for _, existing := range s.alerts { |
| 66 | if existing.Type == alert.Type && existing.Object == alert.Object { |
| 67 | return |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | s.alerts = append(s.alerts, alert) |
| 72 | // Keep only alerts within the window |
| 73 | cutoff := time.Now().Add(-s.window) |
| 74 | filtered := s.alerts[:0] |
| 75 | for _, a := range s.alerts { |
| 76 | if a.Timestamp.After(cutoff) { |
| 77 | filtered = append(filtered, a) |
| 78 | } |
| 79 | } |
| 80 | s.alerts = filtered |
| 81 | } |
| 82 | |
| 83 | // LatestSnapshot returns the most recent snapshot, if any. |
| 84 | func (s *ObservabilityStore) LatestSnapshot() (ResourceSnapshot, bool) { |