clarax commented on code in PR #685:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/685#discussion_r1368183966


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/EventUtils.java:
##########
@@ -117,53 +119,53 @@ public static boolean createByInterval(
             EventRecorder.Component component,
             Consumer<Event> eventListener,
             @Nullable String messageKey,
-            Duration interval) {
-
+            @Nullable BiPredicate<Map<String, String>, Instant> 
suppressionPredicate,
+            @Nullable Map<String, String> labels) {
         String eventName =
                 generateEventName(
                         target, type, reason, messageKey != null ? messageKey 
: message, component);
         Event existing = findExistingEvent(client, target, eventName);
 
         if (existing != null) {
-            if (Objects.equals(existing.getMessage(), message)
-                    && Instant.now()
-                            .isBefore(
-                                    Instant.parse(existing.getLastTimestamp())
-                                            .plusMillis(interval.toMillis()))) 
{
-                return false;
-            } else {
-                createUpdatedEvent(existing, client, message, eventListener);
+            if (suppressionPredicate != null
+                    && existing.getMetadata() != null
+                    && suppressionPredicate.test(
+                            existing.getMetadata().getLabels(),
+                            Instant.parse(existing.getLastTimestamp()))) {
                 return false;
             }
+            updatedEventWithLabels(existing, client, message, eventListener, 
labels);
+            return false;
         } else {
-            createNewEvent(
-                    client, target, type, reason, message, component, 
eventListener, eventName);
+            Event event = buildEvent(target, type, reason, message, component, 
eventName);
+            setLabels(event, labels);
+            eventListener.accept(client.resource(event).createOrReplace());
             return true;
         }
     }
 
-    private static void createUpdatedEvent(
+    private static void updatedEventWithLabels(
             Event existing,
             KubernetesClient client,
             String message,
-            Consumer<Event> eventListener) {
+            Consumer<Event> eventListener,
+            @Nullable Map<String, String> labels) {
         existing.setLastTimestamp(Instant.now().toString());
         existing.setCount(existing.getCount() + 1);
         existing.setMessage(message);
+        setLabels(existing, labels);
         eventListener.accept(client.resource(existing).createOrReplace());
     }
 
-    private static void createNewEvent(
-            KubernetesClient client,
-            HasMetadata target,
-            EventRecorder.Type type,
-            String reason,
-            String message,
-            EventRecorder.Component component,
-            Consumer<Event> eventListener,
-            String eventName) {
-        Event event = buildEvent(target, type, reason, message, component, 
eventName);
-        eventListener.accept(client.resource(event).createOrReplace());
+    private static void setLabels(Event existing, @Nullable Map<String, 
String> labels) {
+        if (existing.getMetadata() == null) {
+            var metaData = new ObjectMeta();
+            metaData.setLabels(labels);
+        } else if (existing.getMetadata().getLabels() == null) {
+            existing.getMetadata().setLabels(labels);
+        } else {
+            existing.getMetadata().setLabels(labels);
+        }

Review Comment:
   Good catch. Will update.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to