(ctx context.Context)
| 94 | } |
| 95 | |
| 96 | func (wb *WatcherBridge) poll(ctx context.Context) { |
| 97 | if !wb.serverClient.IsConnected() { |
| 98 | if err := wb.discoverAndConnect(ctx); err != nil { |
| 99 | wb.logger.Debug("Server discovery failed", zap.Error(err)) |
| 100 | return |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | resp, err := wb.serverClient.GetAlerts(ctx) |
| 105 | if err != nil { |
| 106 | wb.logger.Warn("GetAlerts RPC failed", zap.Error(err)) |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | if len(resp.Alerts) == 0 { |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | wb.logger.Info("Received alerts from server", zap.Int("count", len(resp.Alerts))) |
| 115 | |
| 116 | for _, alert := range resp.Alerts { |
| 117 | hash := wb.computeAlertHash(ctx, alert) |
| 118 | if wb.isDuplicate(hash) { |
| 119 | continue |
| 120 | } |
| 121 | |
| 122 | if err := wb.createAnomaly(ctx, alert); err != nil { |
| 123 | wb.logger.Error("Failed to create Anomaly CR", zap.Error(err), zap.String("alert_type", alert.Type)) |
| 124 | continue |
| 125 | } |
| 126 | ns := alert.Namespace |
| 127 | if ns == "" { |
| 128 | ns = "default" |
| 129 | } |
| 130 | wb.markSeen(hash, alert.Deployment, ns) |
| 131 | } |
| 132 | |
| 133 | wb.pruneDedup() |
| 134 | } |
| 135 | |
| 136 | // discoverAndConnect finds a ready Instance CR and connects to its server. |
| 137 | func (wb *WatcherBridge) discoverAndConnect(ctx context.Context) error { |
no test coverage detected