diff --git a/.chloggen/scrapercontrollersettings_scrapercontrollerconfig.yaml b/.chloggen/scrapercontrollersettings_scrapercontrollerconfig.yaml new file mode 100755 index 00000000000..ad5d1da081d --- /dev/null +++ b/.chloggen/scrapercontrollersettings_scrapercontrollerconfig.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: scraperhelper + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate ScraperControllerSettings, use ControllerConfig instead + +# One or more tracking issues or pull requests related to the change +issues: [6767] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] \ No newline at end of file diff --git a/receiver/scraperhelper/settings.go b/receiver/scraperhelper/config.go similarity index 64% rename from receiver/scraperhelper/settings.go rename to receiver/scraperhelper/config.go index c59ea932583..68f0a56297d 100644 --- a/receiver/scraperhelper/settings.go +++ b/receiver/scraperhelper/config.go @@ -20,8 +20,14 @@ var ( // ScraperControllerSettings defines common settings for a scraper controller // configuration. Scraper controller receivers can embed this struct, instead // of receiver.Settings, and extend it with more fields if needed. -type ScraperControllerSettings struct { - // CollectionInterval sets the how frequently the scraper +// Deprecated: [v0.95.0] Use ControllerConfig instead +type ScraperControllerSettings = ControllerConfig + +// ControllerConfig defines common settings for a scraper controller +// configuration. Scraper controller receivers can embed this struct, instead +// of receiver.Settings, and extend it with more fields if needed. +type ControllerConfig struct { + // CollectionInterval sets how frequently the scraper // should be called and used as the context timeout // to ensure that scrapers don't exceed the interval. CollectionInterval time.Duration `mapstructure:"collection_interval"` @@ -34,15 +40,22 @@ type ScraperControllerSettings struct { // NewDefaultScraperControllerSettings returns default scraper controller // settings with a collection interval of one minute. -func NewDefaultScraperControllerSettings(component.Type) ScraperControllerSettings { - return ScraperControllerSettings{ +// Deprecated: [v0.95.0] Use NewDefaultControllerConfig instead +func NewDefaultScraperControllerSettings(component.Type) ControllerConfig { + return NewDefaultControllerConfig() +} + +// NewDefaultControllerConfig returns default scraper controller +// settings with a collection interval of one minute. +func NewDefaultControllerConfig() ControllerConfig { + return ControllerConfig{ CollectionInterval: time.Minute, InitialDelay: time.Second, Timeout: 0, } } -func (set *ScraperControllerSettings) Validate() (errs error) { +func (set *ControllerConfig) Validate() (errs error) { if set.CollectionInterval <= 0 { errs = multierr.Append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval)) } diff --git a/receiver/scraperhelper/settings_test.go b/receiver/scraperhelper/config_test.go similarity index 79% rename from receiver/scraperhelper/settings_test.go rename to receiver/scraperhelper/config_test.go index 64a5cd67300..1da08e78006 100644 --- a/receiver/scraperhelper/settings_test.go +++ b/receiver/scraperhelper/config_test.go @@ -8,8 +8,6 @@ import ( "time" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/component" ) func TestScrapeControllerSettings(t *testing.T) { @@ -17,22 +15,22 @@ func TestScrapeControllerSettings(t *testing.T) { for _, tc := range []struct { name string - set ScraperControllerSettings + set ControllerConfig errVal string }{ { name: "default configuration", - set: NewDefaultScraperControllerSettings(component.MustNewType("test")), + set: NewDefaultControllerConfig(), errVal: "", }, { name: "zero value configuration", - set: ScraperControllerSettings{}, + set: ControllerConfig{}, errVal: `"collection_interval": requires positive value`, }, { name: "invalid timeout", - set: ScraperControllerSettings{ + set: ControllerConfig{ CollectionInterval: time.Minute, Timeout: -1 * time.Minute, }, diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index fb6da0a3ddf..d2b7410da67 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -65,7 +65,7 @@ type controller struct { // NewScraperControllerReceiver creates a Receiver with the configured options, that can control multiple scrapers. func NewScraperControllerReceiver( - cfg *ScraperControllerSettings, + cfg *ControllerConfig, set receiver.CreateSettings, nextConsumer consumer.Metrics, options ...ScraperControllerOption, diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index d4757a41d92..8e8ceca1d94 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -64,8 +64,8 @@ func (ts *testScrapeMetrics) scrape(context.Context) (pmetric.Metrics, error) { return md, nil } -func newTestNoDelaySettings() *ScraperControllerSettings { - return &ScraperControllerSettings{ +func newTestNoDelaySettings() *ControllerConfig { + return &ControllerConfig{ CollectionInterval: time.Second, InitialDelay: 0, } @@ -75,7 +75,7 @@ type metricsTestCase struct { name string scrapers int - scraperControllerSettings *ScraperControllerSettings + scraperControllerSettings *ControllerConfig nilNextConsumer bool scrapeErr error expectedNewErr string @@ -106,7 +106,7 @@ func TestScrapeController(t *testing.T) { { name: "AddMetricsScrapersWithCollectionInterval_InvalidCollectionIntervalError", scrapers: 2, - scraperControllerSettings: &ScraperControllerSettings{CollectionInterval: -time.Millisecond}, + scraperControllerSettings: &ControllerConfig{CollectionInterval: -time.Millisecond}, expectedNewErr: "collection_interval must be a positive duration", }, { @@ -383,7 +383,7 @@ func TestScrapeControllerStartsOnInit(t *testing.T) { require.NoError(t, err, "Must not error when creating scraper") r, err := NewScraperControllerReceiver( - &ScraperControllerSettings{ + &ControllerConfig{ CollectionInterval: time.Hour, InitialDelay: 0, }, @@ -409,7 +409,7 @@ func TestScrapeControllerInitialDelay(t *testing.T) { var ( elapsed = make(chan time.Time, 1) - cfg = ScraperControllerSettings{ + cfg = ControllerConfig{ CollectionInterval: time.Second, InitialDelay: 300 * time.Millisecond, }