Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine scraperhelper.NewScraper to take component.Type directly #11082

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/refine-new-scraper.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 NewScraper, should use NewScraperWithComponentType

# One or more tracking issues or pull requests related to the change
issues: [11082]

# (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]
10 changes: 9 additions & 1 deletion receiver/scraperhelper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,21 @@

// NewScraper creates a Scraper that calls Scrape at the specified collection interval,
// reports observability information, and passes the scraped metrics to the next consumer.
//
// Deprecated: [v0.109.0] use NewScraperWithComponentType instead.
func NewScraper(name string, scrape ScrapeFunc, options ...ScraperOption) (Scraper, error) {
return NewScraperWithComponentType(component.MustNewType(name), scrape, options...)

Check warning on line 67 in receiver/scraperhelper/scraper.go

View check run for this annotation

Codecov / codecov/patch

receiver/scraperhelper/scraper.go#L67

Added line #L67 was not covered by tests
}

// NewScraperWithComponentType creates a Scraper that calls Scrape at the specified collection interval,
// reports observability information, and passes the scraped metrics to the next consumer.
func NewScraperWithComponentType(t component.Type, scrape ScrapeFunc, options ...ScraperOption) (Scraper, error) {
if scrape == nil {
return nil, errNilFunc
}
bs := &baseScraper{
ScrapeFunc: scrape,
id: component.NewID(component.MustNewType(name)),
id: component.NewID(t),
}
for _, op := range options {
op(bs)
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 @@ -223,7 +223,7 @@ func configureMetricOptions(t *testing.T, test metricsTestCase, initializeChs []

scrapeMetricsChs[i] = make(chan int)
tsm := &testScrapeMetrics{ch: scrapeMetricsChs[i], err: test.scrapeErr}
scp, err := NewScraper("scraper", tsm.scrape, scraperOptions...)
scp, err := NewScraperWithComponentType(component.MustNewType("scraper"), tsm.scrape, scraperOptions...)
assert.NoError(t, err)

metricOptions = append(metricOptions, AddScraper(scp))
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestSingleScrapePerInterval(t *testing.T) {

tickerCh := make(chan time.Time)

scp, err := NewScraper("scaper", tsm.scrape)
scp, err := NewScraperWithComponentType(component.MustNewType("scaper"), tsm.scrape)
assert.NoError(t, err)

receiver, err := NewScraperControllerReceiver(
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestScrapeControllerStartsOnInit(t *testing.T) {
ch: make(chan int, 1),
}

scp, err := NewScraper("scraper", tsm.scrape)
scp, err := NewScraperWithComponentType(component.MustNewType("scraper"), tsm.scrape)
require.NoError(t, err, "Must not error when creating scraper")

r, err := NewScraperControllerReceiver(
Expand Down Expand Up @@ -403,7 +403,7 @@ func TestScrapeControllerInitialDelay(t *testing.T) {
}
)

scp, err := NewScraper("timed", func(context.Context) (pmetric.Metrics, error) {
scp, err := NewScraperWithComponentType(component.MustNewType("timed"), func(context.Context) (pmetric.Metrics, error) {
elapsed <- time.Now()
return pmetric.NewMetrics(), nil
})
Expand Down
Loading