-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[chore] clean up kafkatopicsobserver #38412
[chore] clean up kafkatopicsobserver #38412
Conversation
c1bb934
to
cc4545c
Compare
Clean up the implementation and speed up the tests from 16s to subsecond. ListEndpoints is meant to be run in a loop by the EndpointsWatcher.ListAndWatchloop. I have refactored the implementation to use the "topics_sync_interval" config as the interval for the watcher, and moved the topic listing/matching directly inside ListEndpoints. Start is now a no-op, like in hostobserver. With this change we can speed up the tests by removing the sleeps, reducing the refresh interval, and using a channel to wait for observations.
cc4545c
to
9041271
Compare
I don't know why |
@@ -38,7 +38,7 @@ func TestLoadConfig(t *testing.T) { | |||
ProtocolVersion: "3.7.0", | |||
Brokers: []string{"1.2.3.4:9092", "2.3.4.5:9092"}, | |||
TopicRegex: "^topic[0-9]$", | |||
TopicsSyncInterval: 5 * time.Second, |
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.
Any particular reason to make this lower?
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.
To speed up TestCollectEndpointsAllConfigSettings, which currently takes 16 seconds to run, and is now ~instantaneous.
type kafkaTopicsEndpointsLister struct { | ||
o *kafkaTopicsObserver | ||
topicRegexp *regexp.Regexp | ||
|
||
mu sync.Mutex | ||
topics []string | ||
} |
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.
Any reason to move this to own type instead of the original combined?
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.
Basically the same answer as #38412 (comment), just API hygiene -- the EndpointsLister does not need to be exposed to external users of the observer.
…ackage (#38416) #### Description Move EndpointsLister and EndpointsWatcher to a new "endpointswatcher" package. The intention here is to more clearly delineates the public API of the observer package -- the bits inside endpointswatcher are intended only for implementations of observers. See #38412 (comment) and #38412 (comment) for further motivation. I've made the new package non-internal in case there are any observer implementations out of tree. #### Link to tracking issue N/A #### Testing Ran/updated unit tests #### Documentation N/A except for adding package doc explaining that endpointswatcher is intended for implementations only.
Description
Clean up the implementation and speed up the tests from 16s to subsecond.
ListEndpoints is run in a loop by the EndpointsWatcher.ListAndWatchloop, with differences being reported by a notifier interface - whereas the tests are calling ListEndpoints directly. I have refactored the implementation to use the "topics_sync_interval" config as the interval for the watcher, and moved the topic listing/matching directly inside ListEndpoints. Start is now a no-op, like in hostobserver.
With this change we can speed up the tests by removing the sleeps, reducing the refresh interval, and using a channel to wait for observations.
Link to tracking issue
None
Testing
Run the unit tests.
Before:
After:
Documentation
N/A