-
Notifications
You must be signed in to change notification settings - Fork 220
Enhance event handling #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…t is invoked by the constructor
…k to determine if an event source is already registerd
4498d40
to
f3d2ade
Compare
@@ -155,7 +180,8 @@ public void onClose(WatcherException e) { | |||
if (e.isHttpGone()) { | |||
log.warn("Received error for watch, will try to reconnect.", e); | |||
try { | |||
registerWatch(); | |||
close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really close all the watches? I guess there's no other option since we can't really know which watcher caused the exception…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the issue was that in case of an error on of a single watcher, calling registerWatch
would re-register all the watcher, potentially you could end up in duplicated watchers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was another thing I wondered about (using a List for the watchers as opposed to a Set but I'm not sure we have consistent equals/hashCode
implementations for the Watch
implementations)…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we need a way to improve how watchers are handled, I may try to have a look once this is done
} | ||
|
||
@Override | ||
public <T extends EventSource> void registerEventSource(String name, T eventSource) { | ||
public final void registerEventSource(String name, EventSource eventSource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make this method final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it is invoked by the constructor so either the class is marked as final or this method need to be final to avoid issues in classes extending DefaultEventSourceManager
and overriding registerEventSource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. I remember hearing about this but I have never run into such issues in practice… Have you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, got bitten hard by it 😂 that's why I notice them
@@ -17,9 +17,8 @@ | |||
private static final Logger log = LoggerFactory.getLogger(DefaultEventSourceManager.class); | |||
|
|||
private final ReentrantLock lock = new ReentrantLock(); | |||
private Map<String, EventSource> eventSources = new ConcurrentHashMap<>(); | |||
private CustomResourceEventSource customResourceEventSource; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see it correctly that this has been CustomResourceEventSource
is moved to the Operator? Why is that?
The intention was that this class will own all the custom resources related to a controller.
But are there particular reasons to move it?
The downside is that if we want to have other events,between event sources and controllers vs event source, but also access access CustomResourceEventSource (where we thinking to move the caching for example) will not be accessible in this manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason was that the method:
public void registerCustomResourceEventSource(
CustomResourceEventSource customResourceEventSource) {
this.customResourceEventSource = customResourceEventSource;
this.customResourceEventSource.addedToEventManager();
}
Was not really meaningful as yes the customResourceEventSource
was assigned to an instance of the DefaultEventManager but was never accesses by the manager.
A better option would have been either to use registerEventSource
as any other event source or pass the customResourceEventSource
as a constructor parameter to make it clear that the DefaultEventManager
requires it whereas as today, it looks like an unrelated method.
The event handler for the CustomResourceEventSource
was also set outside the event manager directly in the operator which is quite confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, ok, yes this part definetelly needs improvements and refactorings. (Just like the others :) )
As I mentioned I would like to keep the event sources in one place, I think the constructor would make sense.
CustomResourceEventSource currently has quite special position, it's required always as an event source, so constructor is good ide also do express this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I will probably make some other improvements after this, getting back to work on #392
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csviri yep I think I got the reasoning and I do agree but for the sake of the lifecycle it was quite confusing so I opted to make at little bit more clear (i.e to have set-up / tear-down on the same side, in this case on the Operator). If we move it on the contructor then we can move its set-up/tear-down as part of the event manager.
Thank you! |
This PR includes:
Fixes #368