clarax commented on code in PR #685:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/685#discussion_r1368187442
##########
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) {
Review Comment:
Currently we don't call with non null value. But it doesn't hurt to allow
caller to set it to null as needed. It will be considered as different labels
from empty map so we don't accidentally dedupe.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]