Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Migrates toggle-track receiver from custom loop implementation to use scraperhelper framework, aligning with wavinsentio and zcs receivers.

Changes

Config (config.go)

  • Embed scraperhelper.ControllerConfig with mapstructure squash
  • Replace interval field with collection_interval from embedded config
  • Improve validation with error wrapping

Factory (factory.go)

  • Create scraper factory using scraper.NewFactory with logs support
  • Wire via scraperhelper.NewLogsController and AddFactoryWithConfig
  • Adapt metrics pattern (wavinsentio/zcs) for logs receiver

Scraper (receiver.go)

  • Convert togglTrackReceiver to togglTrackScraper with start()/scrape() methods
  • Remove manual ticker/goroutine—lifecycle managed by scraperhelper
  • Return plog.Logs directly from scrape() instead of consuming inline

Dependencies

Configuration Migration

# Before
toggltrack:
  interval: 30m
  api_token: ${TOKEN}

# After
toggltrack:
  collection_interval: 30m  # renamed from interval
  lookback: 720h            # explicit, was implicit default
  api_token: ${TOKEN}

Breaking: intervalcollection_interval (standard scraperhelper field)

Original prompt

Goal

Migrate the toggle-track receiver implementation to use the scraper pattern (scraper helper + scraper controller settings) the same way wavinsentio and zcs receivers do. This change should make toggle-track consistent with other receivers in this repo and with OpenTelemetry Collector best practices.

Background / rationale

Currently the toggle-track receiver implements scraping/collection logic directly inside a receiver or uses a custom loop (or some older pattern). The wavinsentio and zcs receivers were migrated to use the scraperhelper package and embed scraper controller settings in their configs, which simplifies lifecycle and scheduling and integrates better with observability conventions. We want toggle-track to follow the same pattern.

Scope / Acceptance criteria

  • Replace the current toggle-track receiver factory/implementation so it uses scraperhelper.NewScraper and the collector "scraper controller" pattern.
  • Update the toggle-track receiver config to embed scraperhelper.ScraperControllerSettings (or the equivalent package type used in wavinsentio/zcs) so that collection_interval and other common fields are available via mapstructure squash.
  • Implement a scraper struct (e.g. scraper) with Start(ctx, host) and Shutdown(ctx) methods and a Scrape(ctx) (or ScrapeMetrics) method that performs the same collection behavior as the previous receiver implementation.
  • Wire the scraper into the receiver factory using scraperhelper.NewScraper("toggletrack", s.Scrape, scraperhelper.WithStart(s.Start), scraperhelper.WithShutdown(s.Shutdown)) and then create a receiver using receiverhelper.NewScraperControllerReceiver or the same helper used by wavinsentio/zcs.
  • Preserve existing configuration fields (host/port/credentials/toggles) and behavior; mapping of config names must remain backwards compatible when possible. If defaults change, make sensible defaults (e.g., collection interval 10s) and clearly document them in code comments.
  • Update or add unit tests as needed so that existing tests still pass or new tests cover the scraper flow. Ensure code compiles.
  • Update go.mod or imports if any new import is added (scraperhelper path: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/scraperhelper). Run go vet/go test ./... to verify.

Concrete tasks for the coding agent

  1. Locate the toggle-track receiver packages and files (factory, receiver implementation, config, and tests). Typical paths in this repo: receiver/toggletrack*(check similar receivers like wavinsentio or zcs for file layout). Update these files in place.

  2. Modify config.go for toggle-track: embed scraperhelper.ScraperControllerSettings with mapstructure:",squash" and keep any existing fields. Update default config to set a sensible DefaultCollectionInterval if present.

  3. Create/modify a scraper type in scraper.go (or receiver.go) implementing:

    • func (s *scraper) Start(ctx context.Context, host component.Host) error
    • func (s *scraper) Scrape(ctx context.Context) (pmetric.Metrics, error)
    • func (s *scraper) Shutdown(ctx context.Context) error
      The Scrape body should call the same logic the old receiver used to collect metrics and return them in a pmetric.Metrics object.
  4. Update factory.go to use scraperhelper.NewScraper and receiverhelper.NewScraperControllerReceiver (or the exact helper used by wavinsentio/zcs) to create the receiver factory.

  5. Update or add tests to exercise the scrape lifecycle if the repo contains tests for the other receivers as reference.

  6. Run go test ./... and fix compilation or test errors. If a change requires small refactors (e.g., exported methods moved), keep refactors minimal and local to the toggle-track receiver package.

Notes / references

  • Use wavinsentio and zcs receivers as direct examples. The code in those packages shows how to embed ScraperControllerSettings, register a scraper with scraperhelper, and create a receiver factory.
  • Use scraperhelper.NewScraper constructor pattern and pass WithStart and WithShutdown options.
  • Keep behavioral parity with existing toggle-track receiver API and configuration where possible.

Please create a single pull request in zmoog/collector containing these changes, with a concise description referencing this issue and the receivers used as examples.

If you encounter ambiguous areas in the code (missing files or unclear structure), make the minimal safe changes needed to migrate to the scraper pattern and leave comments in the code explaining any assumptions for future manual review.

This pull request was created as a result of the following prompt from Copilot chat.

Goal

Migrate the toggle-track receiver implementation to use the scraper pattern (scraper helper + scraper controller settings) the same way wavinsentio and zcs receivers do. This change should make toggle-track consistent with other receivers in this repo and with OpenTelemetry Collector best practices.

Background / rationale

Currently the toggle-track receiver implements scraping/collection logic directly inside a receiver or uses a custom loop (or some older pattern). The wavinsentio and zcs receivers were migrated to use the scraperhelper package and embed scraper controller settings in their configs, which simplifies lifecycle and scheduling and integrates better with observability conventions. We want toggle-track to follow the same pattern.

Scope / Acceptance criteria

  • Replace the current toggle-track receiver factory/implementation so it uses scraperhelper.NewScraper and the collector "scraper controller" pattern.
  • Update the toggle-track receiver config to embed scraperhelper.ScraperControllerSettings (or the equivalent package type used in wavinsentio/zcs) so that collection_interval and other common fields are available via mapstructure squash.
  • Implement a scraper struct (e.g. scraper) with Start(ctx, host) and Shutdown(ctx) methods and a Scrape(ctx) (or ScrapeMetrics) method that performs the same collection behavior as the previous receiver implementation.
  • Wire the scraper into the receiver factory using scraperhelper.NewScraper("toggletrack", s.Scrape, scraperhelper.WithStart(s.Start), scraperhelper.WithShutdown(s.Shutdown)) and then create a receiver using receiverhelper.NewScraperControllerReceiver or the same helper used by wavinsentio/zcs.
  • Preserve existing configuration fields (host/port/credentials/toggles) and behavior; mapping of config names must remain backwards compatible when possible. If defaults change, make sensible defaults (e.g., collection interval 10s) and clearly document them in code comments.
  • Update or add unit tests as needed so that existing tests still pass or new tests cover the scraper flow. Ensure code compiles.
  • Update go.mod or imports if any new import is added (scraperhelper path: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/scraperhelper). Run go vet/go test ./... to verify.

Concrete tasks for the coding agent

  1. Locate the toggle-track receiver packages and files (factory, receiver implementation, config, and tests). Typical paths in this repo: receiver/toggletrack*(check similar receivers like wavinsentio or zcs for file layout). Update these files in place.

  2. Modify config.go for toggle-track: embed scraperhelper.ScraperControllerSettings with mapstructure:",squash" and keep any existing fields. Update default config to set a sensible DefaultCollectionInterval if present.

  3. Create/modify a scraper type in scraper.go (or receiver.go) implementing:

    • func (s *scraper) Start(ctx context.Context, host component.Host) error
    • func (s *scraper) Scrape(ctx context.Context) (pmetric.Metrics, error)
    • func (s *scraper) Shutdown(ctx context.Context) error
      The Scrape body should call the same logic the old receiver used to collect metrics and return them in a pmetric.Metrics object.
  4. Update factory.go to use scraperhelper.NewScraper and receiverhelper.NewScraperControllerReceiver (or the exact helper used by wavinsentio/zcs) to create the receiver factory.

  5. Update or add tests to exercise the scrape lifecycle if the repo contains tests for the other receivers as reference.

  6. Run go test ./... and fix compilation or test errors. If a change requires small refactors (e.g., exported methods moved), keep refactors minimal and local to the toggle-track receiver package.

Notes / references

  • Use wavinsentio and zcs receivers as direct examples. The code in those packages shows how to embed ScraperControllerSettings, register a scraper with scraperhelper, and create a receiver factory.
  • Use scraperhelper.NewScraper constructor pattern and pass WithStart and WithShutdown options.
  • Keep behavioral parity with existing toggle-track receiver API and configuration where possible.

Please create a single pull request in zmoog/collector containing these changes, with a concise description referencing this issue and the receivers used as examples.

If you encounter ambiguous areas in the code (missing files or unclear structure), make the minimal safe changes needed to migrate to the scraper pattern and leave comments in the code explaining any assumptions for future manual review.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Migrate toggle-track receiver to scraper pattern Migrate toggle-track receiver to scraper pattern Oct 31, 2025
Copilot AI requested a review from zmoog October 31, 2025 23:25
Copilot finished work on behalf of zmoog October 31, 2025 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants