Skip to content

Commit

Permalink
Removing support for options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Marciniak committed Jul 5, 2023
1 parent 26f25f7 commit 822463e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 137 deletions.
42 changes: 0 additions & 42 deletions receiver/scraperhelper/option.go

This file was deleted.

71 changes: 0 additions & 71 deletions receiver/scraperhelper/option_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion receiver/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ func (sc *controller) startScraping() {
for {
select {
case <-sc.tickerCh:
sc.scrapeMetricsAndReport(context.Background())
ctx, done = withScrapeContext(sc.timeout)
sc.scrapeMetricsAndReport(ctx)
done()
case <-sc.done:
sc.terminated <- struct{}{}
return
Expand Down
8 changes: 4 additions & 4 deletions receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ func TestScrapeControllerInitialDelay(t *testing.T) {

var (
elapsed = make(chan time.Time, 1)
cfg = NewDefaultScraperControllerSettingsWithOptions(
WithCollectionInterval(time.Second),
WithTimeout(300*time.Millisecond),
)
cfg = ScraperControllerSettings{
CollectionInterval: time.Second,
Timeout: 300 * time.Millisecond,
}
)

scp, err := NewScraper("timed", func(ctx context.Context) (pmetric.Metrics, error) {
Expand Down
17 changes: 1 addition & 16 deletions receiver/scraperhelper/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,12 @@ type ScraperControllerSettings struct {

// NewDefaultScraperControllerSettings returns default scraper controller
// settings with a collection interval of one minute.
//
// Deprecated: Use `NewDefaultScraperControllerSettingsWithOptions` instead
func NewDefaultScraperControllerSettings(component.Type) ScraperControllerSettings {
return NewDefaultScraperControllerSettingsWithOptions()
}

// NewDefaultScraperControllerSettingsWithOptions returns a default scraper controller settings
// settings with a collection interval of one minute.
// The options are applied in order and will override the set defaults.
func NewDefaultScraperControllerSettingsWithOptions(options ...Option) ScraperControllerSettings {
set := ScraperControllerSettings{
return ScraperControllerSettings{
CollectionInterval: time.Minute,
InitialDelay: time.Second,
Timeout: 0,
}

for _, opt := range options {
opt.apply(&set)
}

return set
}

func (set *ScraperControllerSettings) Validate() (errs error) {
Expand Down
10 changes: 7 additions & 3 deletions receiver/scraperhelper/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package scraperhelper

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -19,7 +20,7 @@ func TestScrapeControllerSettings(t *testing.T) {
}{
{
name: "default configuration",
set: NewDefaultScraperControllerSettingsWithOptions(),
set: NewDefaultScraperControllerSettings(""),
errVal: "",
},
{
Expand All @@ -28,8 +29,11 @@ func TestScrapeControllerSettings(t *testing.T) {
errVal: `"collection_interval": requires positive value`,
},
{
name: "invalid timeout",
set: NewDefaultScraperControllerSettingsWithOptions(WithTimeout(-10)),
name: "invalid timeout",
set: ScraperControllerSettings{
CollectionInterval: time.Minute,
Timeout: -1 * time.Minute,
},
errVal: `"timeout": requires positive value`,
},
} {
Expand Down

0 comments on commit 822463e

Please sign in to comment.