@@ -80,6 +80,7 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request)
8080 eventLogger .Info ("dispatching event" , "message" , event .Message )
8181
8282 // Dispatch notifications.
83+ var droppedCommitStatusAlerts []* apiv1beta3.Alert
8384 var droppedChangeRequestAlerts []* apiv1beta3.Alert
8485 for i := range alerts {
8586 alert := & alerts [i ]
@@ -90,17 +91,33 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request)
9091 "providerName" : alert .Spec .ProviderRef .Name ,
9192 })
9293 ctx := log .IntoContext (ctx , alertLogger )
93- droppedChangeRequestProvider , err := s .dispatchNotification (ctx , event , alert )
94+ dropped , err := s .dispatchNotification (ctx , event , alert )
9495 if err != nil {
9596 alertLogger .Error (err , "failed to dispatch notification" )
9697 s .Eventf (alert , corev1 .EventTypeWarning , "NotificationDispatchFailed" ,
9798 "failed to dispatch notification for %s: %s" , involvedObjectString (event .InvolvedObject ), err )
99+ continue
98100 }
99- if droppedChangeRequestProvider {
101+ if dropped .commitStatus {
102+ droppedCommitStatusAlerts = append (droppedCommitStatusAlerts , alert )
103+ }
104+ if dropped .changeRequest {
100105 droppedChangeRequestAlerts = append (droppedChangeRequestAlerts , alert )
101106 }
102107 }
103108
109+ // Log if any events were dropped due to being related to a commit status provider
110+ // but not having the required commit metadata key.
111+ if len (droppedCommitStatusAlerts ) > 0 {
112+ var alertNames []string
113+ for _ , alert := range droppedCommitStatusAlerts {
114+ alertNames = append (alertNames , fmt .Sprintf ("%s/%s" , alert .Namespace , alert .Name ))
115+ }
116+ eventLogger .Info (
117+ "event dropped for commit status providers due to missing commit metadata key" ,
118+ "alerts" , alertNames )
119+ }
120+
104121 // Log if any events were dropped due to being related to a change request comment
105122 // provider but not having the required change request metadata key.
106123 if len (droppedChangeRequestAlerts ) > 0 {
@@ -223,13 +240,15 @@ func (s *EventServer) messageIsExcluded(ctx context.Context, msg string, alert *
223240// and alert data. The returned boolean indicates if the event was dropped due
224241// to being related to a change request provider but not having the required
225242// change request metadata key.
226- func (s * EventServer ) dispatchNotification (ctx context.Context , event * eventv1.Event , alert * apiv1beta3.Alert ) (bool , error ) {
227- params , droppedChangeRequestProvider , err := s .getNotificationParams (ctx , event , alert )
243+ func (s * EventServer ) dispatchNotification (ctx context.Context ,
244+ event * eventv1.Event , alert * apiv1beta3.Alert ) (droppedProviders , error ) {
245+
246+ params , dropped , err := s .getNotificationParams (ctx , event , alert )
228247 if err != nil {
229- return false , err
248+ return droppedProviders {} , err
230249 }
231250 if params == nil {
232- return droppedChangeRequestProvider , nil
251+ return dropped , nil
233252 }
234253
235254 go func (n notifier.Interface , e eventv1.Event ) {
@@ -249,7 +268,7 @@ func (s *EventServer) dispatchNotification(ctx context.Context, event *eventv1.E
249268 }
250269 }(params .sender , * params .event )
251270
252- return false , nil
271+ return droppedProviders {} , nil
253272}
254273
255274// notificationParams holds the results of the getNotificationParams function.
@@ -260,52 +279,67 @@ type notificationParams struct {
260279 timeout time.Duration
261280}
262281
282+ // droppedProviders holds boolean values indicating whether the event was dropped
283+ // due to being related to a provider that requires a specific metadata key but
284+ // the event didn't have that key.
285+ type droppedProviders struct {
286+ commitStatus bool
287+ changeRequest bool
288+ }
289+
263290// getNotificationParams constructs the notification parameters from the given
264291// event and alert, and returns a notifier, event, token and timeout for sending
265292// the notification. The returned event is a mutated form of the input event
266293// based on the alert configuration. A boolean is also returned to indicate if
267294// the event was dropped due to being related to a change request provider but
268295// not having the required change request metadata key.
269296func (s * EventServer ) getNotificationParams (ctx context.Context , event * eventv1.Event ,
270- alert * apiv1beta3.Alert ) (* notificationParams , bool , error ) {
297+ alert * apiv1beta3.Alert ) (* notificationParams , droppedProviders , error ) {
271298 // Check if event comes from a different namespace.
272299 if s .noCrossNamespaceRefs && event .InvolvedObject .Namespace != alert .Namespace {
273300 accessDenied := fmt .Errorf (
274301 "alert '%s/%s' can't process event from '%s', cross-namespace references have been blocked" ,
275302 alert .Namespace , alert .Name , involvedObjectString (event .InvolvedObject ))
276- return nil , false , fmt .Errorf ("discarding event, access denied to cross-namespace sources: %w" , accessDenied )
303+ return nil , droppedProviders {} , fmt .Errorf ("discarding event, access denied to cross-namespace sources: %w" , accessDenied )
277304 }
278305
279306 var provider apiv1beta3.Provider
280307 providerName := types.NamespacedName {Namespace : alert .Namespace , Name : alert .Spec .ProviderRef .Name }
281308
282309 err := s .kubeClient .Get (ctx , providerName , & provider )
283310 if err != nil {
284- return nil , false , fmt .Errorf ("failed to read provider: %w" , err )
311+ return nil , droppedProviders {} , fmt .Errorf ("failed to read provider: %w" , err )
285312 }
286313
287314 // Skip if the provider is suspended.
288315 if provider .Spec .Suspend {
289- return nil , false , nil
316+ return nil , droppedProviders {} , nil
290317 }
291318
292319 // Skip if the event has commit status update metadata but the provider is not a git provider.
293320 // Git providers (github, gitlab, etc.) are the ones that set commit statuses.
294321 if ! isCommitStatusProvider (provider .Spec .Type ) && isCommitStatusUpdate (event ) {
295- return nil , false , nil
322+ return nil , droppedProviders {}, nil
323+ }
324+
325+ // Skip if the provider is a commit status provider but the event doesn't have the commit metadata key.
326+ if isCommitStatusProvider (provider .Spec .Type ) && ! hasCommitKey (event ) {
327+ // Return true on dropped event for a commit status provider
328+ // when the event doesn't have the commit metadata key.
329+ return nil , droppedProviders {commitStatus : true }, nil
296330 }
297331
298- // Skip if the provider is a change request comment provider but the event
332+ // Skip if the provider is a change request provider but the event
299333 // doesn't have the change request metadata key.
300- if isChangeRequestCommentProvider (provider .Spec .Type ) && ! hasChangeRequestKey (event ) {
301- // Return true on dropped event for a change request comment provider
334+ if isChangeRequestProvider (provider .Spec .Type ) && ! hasChangeRequestKey (event ) {
335+ // Return true on dropped event for a change request provider
302336 // when the event doesn't have the change request metadata key.
303- return nil , true , nil
337+ return nil , droppedProviders { changeRequest : true } , nil
304338 }
305339
306340 // Check object-level workload identity feature gate.
307341 if provider .Spec .ServiceAccountName != "" && ! auth .IsObjectLevelWorkloadIdentityEnabled () {
308- return nil , false , fmt .Errorf (
342+ return nil , droppedProviders {} , fmt .Errorf (
309343 "to use spec.serviceAccountName for provider authentication please enable the %s feature gate in the controller" ,
310344 auth .FeatureGateObjectLevelWorkloadIdentity )
311345 }
@@ -317,20 +351,20 @@ func (s *EventServer) getNotificationParams(ctx context.Context, event *eventv1.
317351 // Create a commit status for the given provider and event, if applicable.
318352 commitStatus , err := createCommitStatus (ctx , & provider , & notification , alert )
319353 if err != nil {
320- return nil , false , fmt .Errorf ("failed to create commit status: %w" , err )
354+ return nil , droppedProviders {} , fmt .Errorf ("failed to create commit status: %w" , err )
321355 }
322356
323357 sender , token , err := createNotifier (ctx , s .kubeClient , & provider , commitStatus , s .tokenCache )
324358 if err != nil {
325- return nil , false , fmt .Errorf ("failed to initialize notifier for provider '%s': %w" , provider .Name , err )
359+ return nil , droppedProviders {} , fmt .Errorf ("failed to initialize notifier for provider '%s': %w" , provider .Name , err )
326360 }
327361
328362 return & notificationParams {
329363 sender : sender ,
330364 event : & notification ,
331365 token : token ,
332366 timeout : provider .GetTimeout (),
333- }, false , nil
367+ }, droppedProviders {} , nil
334368}
335369
336370// createCommitStatus creates a commit status for the given provider and event.
0 commit comments