MCPcopy Create free account
hub / github.com/diillson/chatcli / poll

Method poll

operator/controllers/watcher_bridge.go:96–134  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

94}
95
96func (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.
137func (wb *WatcherBridge) discoverAndConnect(ctx context.Context) error {

Callers 1

StartMethod · 0.95

Calls 12

discoverAndConnectMethod · 0.95
computeAlertHashMethod · 0.95
isDuplicateMethod · 0.95
createAnomalyMethod · 0.95
markSeenMethod · 0.95
pruneDedupMethod · 0.95
WarnMethod · 0.80
IsConnectedMethod · 0.65
ErrorMethod · 0.65
GetAlertsMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected