Skip to content

Commit

Permalink
[scraperhelper] Deprecate ScraperControllerSettings, use ControllerCo…
Browse files Browse the repository at this point in the history
…nfig instead (#9401)

**Description:**
Deprecate ScraperControllerSettings, use ~Scraper~ControllerConfig
instead

**Link to tracking Issue:**
#6767
  • Loading branch information
atoulme authored Feb 16, 2024
1 parent a8b00dc commit 0ab8f44
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
25 changes: 25 additions & 0 deletions .chloggen/scrapercontrollersettings_scrapercontrollerconfig.yaml
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ import (
"time"

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component"
)

func TestScrapeControllerSettings(t *testing.T) {
t.Parallel()

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,
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -75,7 +75,7 @@ type metricsTestCase struct {
name string

scrapers int
scraperControllerSettings *ScraperControllerSettings
scraperControllerSettings *ControllerConfig
nilNextConsumer bool
scrapeErr error
expectedNewErr string
Expand Down Expand Up @@ -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",
},
{
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
}
Expand Down

0 comments on commit 0ab8f44

Please sign in to comment.