Skip to content

Commit

Permalink
Make scrapercontroler more generic and move closer to the scraperrece…
Browse files Browse the repository at this point in the history
…iver

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 15, 2025
1 parent a8f95d9 commit 61f3c51
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scraper/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (

// ScraperControllerOption apply changes to internal options.
type ScraperControllerOption interface {
apply(*controller)
apply(*controllerOptions)
}

type scraperControllerOptionFunc func(*controller)
type scraperControllerOptionFunc func(*controllerOptions)

func (of scraperControllerOptionFunc) apply(e *controller) {
func (of scraperControllerOptionFunc) apply(e *controllerOptions) {
of(e)
}

Expand All @@ -37,7 +37,7 @@ func (of scraperControllerOptionFunc) apply(e *controller) {
// Observability information will be reported, and the scraped metrics
// will be passed to the next consumer.
func AddScraper(t component.Type, scraper scraper.Metrics) ScraperControllerOption {
return scraperControllerOptionFunc(func(o *controller) {
return scraperControllerOptionFunc(func(o *controllerOptions) {
o.scrapers = append(o.scrapers, scraperWithID{
Metrics: scraper,
id: component.NewID(t),
Expand All @@ -49,18 +49,24 @@ func AddScraper(t component.Type, scraper scraper.Metrics) ScraperControllerOpti
// channel to specify when scrape is called. This is only expected to be
// used by tests.
func WithTickerChannel(tickerCh <-chan time.Time) ScraperControllerOption {
return scraperControllerOptionFunc(func(o *controller) {
return scraperControllerOptionFunc(func(o *controllerOptions) {
o.tickerCh = tickerCh
})
}

type controller struct {
type controllerOptions struct {
tickerCh <-chan time.Time
scrapers []scraperWithID
}

type consumeFunc[T any] func(ctx context.Context, req T) error

type controller[T any] struct {
collectionInterval time.Duration
initialDelay time.Duration
timeout time.Duration
nextConsumer consumer.Metrics
nextConsumer consumeFunc[T]

scrapers []scraperWithID
obsScrapers []scraper.Metrics

tickerCh <-chan time.Time
Expand Down

0 comments on commit 61f3c51

Please sign in to comment.