Skip to content
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/xscraperhelper-AddProfilesScraper.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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
component: pkg/xscraperhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add AddProfilesScraper similar to scraperhelper.AddMetricsScraper

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

# (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]
14 changes: 14 additions & 0 deletions scraper/scraperhelper/xscraperhelper/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/xreceiver"
"go.opentelemetry.io/collector/scraper"
"go.opentelemetry.io/collector/scraper/scrapererror"
"go.opentelemetry.io/collector/scraper/scraperhelper"
"go.opentelemetry.io/collector/scraper/scraperhelper/internal/controller"
Expand Down Expand Up @@ -50,6 +51,19 @@ func (of optionFunc) apply(e *controllerOptions) {
of(e)
}

// AddProfilesScraper configures the xscraper.Profiles to be called with the specified options,
// and at the specified collection interval.
//
// Observability information will be reported, and the scraped profiles
// will be passed to the next consumer.
func AddProfilesScraper(t component.Type, sc xscraper.Profiles) ControllerOption {
f := xscraper.NewFactory(t, nil,
xscraper.WithProfiles(func(context.Context, scraper.Settings, component.Config) (xscraper.Profiles, error) {
return sc, nil
}, component.StabilityLevelDevelopment))
return AddFactoryWithConfig(f, nil)
}

// AddFactoryWithConfig configures the scraper.Factory and associated config that
// will be used to create a new scraper. The created scraper will be called with
// the specified options, and at the specified collection interval.
Expand Down
18 changes: 5 additions & 13 deletions scraper/scraperhelper/xscraperhelper/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func configureProfilesOptions(t *testing.T, test scraperTestCase, initializeChs
scp, err := xscraper.NewProfiles(ts.scrapeProfiles, xscraperOptions...)
require.NoError(t, err)

profilesOptions = append(profilesOptions, addProfilesScraper(component.MustNewType("scraper"), scp))
profilesOptions = append(profilesOptions, AddProfilesScraper(component.MustNewType("scraper"), scp))
}

return profilesOptions
Expand All @@ -242,7 +242,7 @@ func TestSingleProfilesScraperPerInterval(t *testing.T) {
cfg,
receivertest.NewNopSettings(receivertest.NopType),
new(consumertest.ProfilesSink),
addProfilesScraper(component.MustNewType("scraper"), scp),
AddProfilesScraper(component.MustNewType("scraper"), scp),
WithTickerChannel(tickerCh),
)
require.NoError(t, err)
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestProfilesScraperControllerStartsOnInit(t *testing.T) {
},
receivertest.NewNopSettings(receivertest.NopType),
new(consumertest.ProfilesSink),
addProfilesScraper(component.MustNewType("scraper"), scp),
AddProfilesScraper(component.MustNewType("scraper"), scp),
)
require.NoError(t, err, "Must not error when creating scrape controller")

Expand Down Expand Up @@ -323,7 +323,7 @@ func TestProfilesScraperControllerInitialDelay(t *testing.T) {
&cfg,
receivertest.NewNopSettings(receivertest.NopType),
new(consumertest.ProfilesSink),
addProfilesScraper(component.MustNewType("scraper"), scp),
AddProfilesScraper(component.MustNewType("scraper"), scp),
)
require.NoError(t, err, "Must not error when creating receiver")

Expand Down Expand Up @@ -353,7 +353,7 @@ func TestProfilesScraperShutdownBeforeScrapeCanStart(t *testing.T) {
&cfg,
receivertest.NewNopSettings(receivertest.NopType),
new(consumertest.ProfilesSink),
addProfilesScraper(component.MustNewType("scraper"), scp),
AddProfilesScraper(component.MustNewType("scraper"), scp),
)
require.NoError(t, err, "Must not error when creating receiver")
require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -409,14 +409,6 @@ func assertProfilesScraperObsMetrics(t *testing.T, tel *componenttest.Telemetry,
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
}

func addProfilesScraper(t component.Type, sc xscraper.Profiles) ControllerOption {
f := xscraper.NewFactory(t, nil,
xscraper.WithProfiles(func(context.Context, scraper.Settings, component.Config) (xscraper.Profiles, error) {
return sc, nil
}, component.StabilityLevelDevelopment))
return AddFactoryWithConfig(f, nil)
}

// TestNewProfilesControllerCreateError tests that NewProfilesController returns an error
// when the scraper factory's CreateProfiles method fails.
func TestNewProfilesControllerCreateError(t *testing.T) {
Expand Down
Loading