[scraperhelper] Add extension-based scraper controller support#15116
[scraperhelper] Add extension-based scraper controller support#15116axw wants to merge 23 commits into
Conversation
43fa995 to
e904e60
Compare
Merging this PR will create unknown performance changes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15116 +/- ##
==========================================
+ Coverage 91.09% 91.12% +0.02%
==========================================
Files 725 725
Lines 48066 48133 +67
==========================================
+ Hits 43788 43861 +73
+ Misses 2979 2975 -4
+ Partials 1299 1297 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ffacd96 to
e6602b9
Compare
Add tests to the internal/controller package, so we have baseline coverage before making the changes in open-telemetry#15116.
#### Description Add tests to the internal/controller package, so we have baseline coverage before making the changes in #15116. #### Link to tracking issue N/A #### Testing Yes #### Documentation No Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
3aa92a2 to
8aef2b0
Compare
#### Description Various changes to newTestController to simplify tests: - newTestController no longer accepts a ticker, it always calls NewController with a nil ticker so one is created internally; the tests now use synctest where relevant. - newTestController no longer conditionally creates a no-op scrapeFunc, we introduce a nopScrapeFunc function and update relevant tests to pass it in. - scrapers has been made the final parameter, and is now variadic. Tests no longer need to explicitly create a slice. TestStartScrapingWithNilTickerCh has been removed, since that is now covered by the use of synctest. Several tests has been updated to use newTestController rather than calling NewController directly. #### Link to tracking issue Prep for open-telemetry#15116 (trying to cut the diff down) #### Testing Yes #### Documentation No Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
8aef2b0 to
7a80b44
Compare
Implement the extensionscrapercontroller package and integrate it with the scraper controller, allowing extensions to trigger scrapes based on external events instead of (or in addition to) a fixed timer interval. - Add extensionscrapercontroller.ControllerExtension interface and DeregisterFunc helper in extension/xextension/extensionscrapercontroller - Add Controllers field to ControllerConfig for specifying extension IDs - Allow CollectionInterval=0 when Controllers are configured - Register scrapers with controller extensions on Start, deregister on Shutdown - Update RFC to remove scraperID parameter from RegisterScraper Assisted-by: Claude Opus 4.5
7a80b44 to
e126197
Compare
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
|
||
| // RegistrationHandle is returned by ControllerExtension.RegisterScraper and | ||
| // is used to deregister the scraper during shutdown. | ||
| type RegistrationHandle interface { |
There was a problem hiding this comment.
Suggest making this a closed interface so that you can add methods in the future, with a constructor method (as described in the RFC)
There was a problem hiding this comment.
Hmm. I think that makes sense for something like Factory, which is a collection of methods. This interface is more akin to io.Reader, i.e. it has a singular purpose, so I don't think expanding methods is realistic.
Perhaps I should just make it a function type, so RegisterScraper becomes:
RegisterScraper(context.Context, ScrapeFunc) (DeregisterFunc, error)WDYT?
There was a problem hiding this comment.
I made this change, can easily revert if you're against it
…nscrapercontroller
- Create ScrapeFunc type - Replace RegistrationHandle type with DeregisterFunc type - Update collection_interval error message per review
- Deregister extensions concurrently in Shutdown so total wait time is bounded by the slowest single extension, not the sum of all - Capture scraper Shutdown errors in Start's failure-cleanup defer instead of silently discarding them - Fix TestStartScrapingNoCollectionInterval to use a valid config (zero CollectionInterval requires at least one controller) - Move MockHost and MockControllerExtension to internal/testhelper, eliminating the duplicate definitions across the two test packages; the shared mock correctly blocks DeregisterFunc on in-flight scrapes Assisted-by: Claude Sonnet 4.6
…el teardown - Document that RegisterScraper must return a non-nil DeregisterFunc when err is nil; add defensive nil guard in teardown - Fix TOCTOU race in MockControllerExtension.Scrape: hold mu across the nil/deregistered check and scrapeWG.Add so DeregisterFunc cannot observe a zero count between the two - Extract shared teardown helper used by both Start cleanup and Shutdown: deregisters extensions and shuts down scrapers concurrently, clearing deregFuncs first to prevent double-invocation - Fix TestShutdownScrapers: protect shared slice with mutex and use ElementsMatch since scraper shutdown order is now non-deterministic Assisted-by: Claude Sonnet 4.6
Not quite right, but not worth the hassle of breaking contrib tests.
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
| }) | ||
| } | ||
| wg.Wait() | ||
| for _, scrp := range scrapers { |
There was a problem hiding this comment.
Should we guard this in a similar way to deregFuncs so we don't call Shutdown twice? (It could happen if Start fails since we call Shutdown in that case
opentelemetry-collector/otelcol/collector.go
Lines 264 to 265 in da5e6f6
There was a problem hiding this comment.
On main we only ever shutdown the scrapers when the controller's Shutdown method is called, and not on when Start fails. I'll revert to that for scrapers, and only call deregFuncs when Start fails, so that there's nothing actively scraping after Start returns an error.
Description
Implement the extensionscrapercontroller package and integrate it with the scraper controller, allowing extensions to trigger scrapes based on external events instead of (or in addition to) a fixed timer interval.
Assisted-by: Claude Opus 4.5
Link to tracking issue
Closes #12449
Testing
Tests added.
Documentation
https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/rfcs/scraper-controller-extension.md