Skip to content
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

Merged
merged 7 commits into from
Mar 11, 2025

Conversation

axw
Copy link
Contributor

@axw axw commented Mar 6, 2025

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:

ok      github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/kafkatopicsobserver        16.177s

After:

ok      github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/kafkatopicsobserver        0.461s

Documentation

N/A

@github-actions github-actions bot requested a review from dmitryax March 6, 2025 02:40
@axw axw force-pushed the kafkatopicsobserver-test-speedup branch from c1bb934 to cc4545c Compare March 6, 2025 02:56
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.
@axw axw force-pushed the kafkatopicsobserver-test-speedup branch from cc4545c to 9041271 Compare March 6, 2025 02:57
@axw
Copy link
Contributor Author

axw commented Mar 6, 2025

I don't know why build-examples failed, but it doesn't appear to be related to my changes. It also failed on #38414

@axw axw marked this pull request as ready for review March 6, 2025 03:16
@axw axw requested review from MovieStoreGuy and a team as code owners March 6, 2025 03:16
@@ -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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +75 to +81
type kafkaTopicsEndpointsLister struct {
o *kafkaTopicsObserver
topicRegexp *regexp.Regexp

mu sync.Mutex
topics []string
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

songy23 pushed a commit that referenced this pull request Mar 7, 2025
…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.
@axw axw requested a review from MovieStoreGuy March 10, 2025 06:48
@atoulme atoulme merged commit bad7c14 into open-telemetry:main Mar 11, 2025
171 checks passed
@github-actions github-actions bot added this to the next release milestone Mar 11, 2025
@axw axw deleted the kafkatopicsobserver-test-speedup branch March 11, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants