Skip to content

Commit d61f4c5

Browse files
committed
xscraperhelper: add AddProfilesScraper
Signed-off-by: Florian Lehner <[email protected]>
1 parent 0755152 commit d61f4c5

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
7+
component: scraper/scraperhelper/xscraperhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add AddProfilesScraper similar to scraperhelper.AddScraper
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: []
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

scraper/scraperhelper/xscraperhelper/controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go.opentelemetry.io/collector/pdata/pprofile"
1414
"go.opentelemetry.io/collector/receiver"
1515
"go.opentelemetry.io/collector/receiver/xreceiver"
16+
"go.opentelemetry.io/collector/scraper"
1617
"go.opentelemetry.io/collector/scraper/scrapererror"
1718
"go.opentelemetry.io/collector/scraper/scraperhelper"
1819
"go.opentelemetry.io/collector/scraper/scraperhelper/internal/controller"
@@ -50,6 +51,19 @@ func (of optionFunc) apply(e *controllerOptions) {
5051
of(e)
5152
}
5253

54+
// AddProfilesScraper configures the xscraper.Profiles to be called with the specified options,
55+
// and at the specified collection interval.
56+
//
57+
// Observability information will be reported, and the scraped profiles
58+
// will be passed to the next consumer.
59+
func AddProfilesScraper(t component.Type, sc xscraper.Profiles) ControllerOption {
60+
f := xscraper.NewFactory(t, nil,
61+
xscraper.WithProfiles(func(context.Context, scraper.Settings, component.Config) (xscraper.Profiles, error) {
62+
return sc, nil
63+
}, component.StabilityLevelDevelopment))
64+
return AddFactoryWithConfig(f, nil)
65+
}
66+
5367
// AddFactoryWithConfig configures the scraper.Factory and associated config that
5468
// will be used to create a new scraper. The created scraper will be called with
5569
// the specified options, and at the specified collection interval.

scraper/scraperhelper/xscraperhelper/controller_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func configureProfilesOptions(t *testing.T, test scraperTestCase, initializeChs
221221
scp, err := xscraper.NewProfiles(ts.scrapeProfiles, xscraperOptions...)
222222
require.NoError(t, err)
223223

224-
profilesOptions = append(profilesOptions, addProfilesScraper(component.MustNewType("scraper"), scp))
224+
profilesOptions = append(profilesOptions, AddProfilesScraper(component.MustNewType("scraper"), scp))
225225
}
226226

227227
return profilesOptions
@@ -242,7 +242,7 @@ func TestSingleProfilesScraperPerInterval(t *testing.T) {
242242
cfg,
243243
receivertest.NewNopSettings(receivertest.NopType),
244244
new(consumertest.ProfilesSink),
245-
addProfilesScraper(component.MustNewType("scraper"), scp),
245+
AddProfilesScraper(component.MustNewType("scraper"), scp),
246246
WithTickerChannel(tickerCh),
247247
)
248248
require.NoError(t, err)
@@ -287,7 +287,7 @@ func TestProfilesScraperControllerStartsOnInit(t *testing.T) {
287287
},
288288
receivertest.NewNopSettings(receivertest.NopType),
289289
new(consumertest.ProfilesSink),
290-
addProfilesScraper(component.MustNewType("scraper"), scp),
290+
AddProfilesScraper(component.MustNewType("scraper"), scp),
291291
)
292292
require.NoError(t, err, "Must not error when creating scrape controller")
293293

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

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

412-
func addProfilesScraper(t component.Type, sc xscraper.Profiles) ControllerOption {
413-
f := xscraper.NewFactory(t, nil,
414-
xscraper.WithProfiles(func(context.Context, scraper.Settings, component.Config) (xscraper.Profiles, error) {
415-
return sc, nil
416-
}, component.StabilityLevelDevelopment))
417-
return AddFactoryWithConfig(f, nil)
418-
}
419-
420412
// TestNewProfilesControllerCreateError tests that NewProfilesController returns an error
421413
// when the scraper factory's CreateProfiles method fails.
422414
func TestNewProfilesControllerCreateError(t *testing.T) {

0 commit comments

Comments
 (0)