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

scraperhelper.NewScraper is awkward to use #9473

Closed
mx-psi opened this issue Feb 6, 2024 · 7 comments · Fixed by #11082 or #11294
Closed

scraperhelper.NewScraper is awkward to use #9473

mx-psi opened this issue Feb 6, 2024 · 7 comments · Fixed by #11082 or #11294
Assignees
Labels
area:receiver good first issue Good for newcomers help wanted Good issue for contributors to OpenTelemetry Service to pick up release:required-for-ga Must be resolved before GA release

Comments

@mx-psi
Copy link
Member

mx-psi commented Feb 6, 2024

While working on #9208 I realized that the current way scraperhelper.NewScraper works is a bit awkward. The function takes a name string and then builds an ID with it:

func NewScraper(name string, scrape ScrapeFunc, options ...ScraperOption) (Scraper, error) {

It is very common among contrib scrapers to name the scraper with the same name as the component itself, and so we end up building a component.Type, converting it to string to pass to NewScraper and then building it again. I propose we change the first argument to take a component.Type instead.

@mx-psi mx-psi added release:required-for-ga Must be resolved before GA release area:receiver labels Feb 6, 2024
@bogdandrutu
Copy link
Member

I think Scraper interface needs a bit more "love" than that. Will give a try to send some PRs/ideas soon

@hughesjj
Copy link

hughesjj commented Mar 2, 2024

I agree that it's a bit awkward to use and encountered similar, this is my "triage" attempt. Feel free to rip it apart or add to it if useful

Of note is that we may want to start limiting string length of component.Type as well

@hughesjj
Copy link

hughesjj commented Mar 6, 2024

So, we've change the underlying datatype from String to Struct in
9472, but there's still a few points of "awkwardness" remaining. From my perspective:

  • We don't allow "empty" Types to exist via the regex, but the empty value is still in use. This means not every constructed type will pass the validation logic.
  • ScraperHelper constructs a component.ID but never uses the Name field. This is awkward because the constructor itself takes in a string, and I've seen downstream consumers pass in component.ID.String() as the value for this. This leads to unexpected behavior given, if a Name is set on the component.ID passed into NewScraper, the .String() value will not pass the regex. Ex if a component.ID is type=foo,name=bar, the .String() method will be foo/bar and fail the regex.

@mx-psi
Copy link
Member Author

mx-psi commented Mar 7, 2024

the empty value is still in use

Where do we use the empty value?

@mx-psi mx-psi moved this to Todo in Collector: v1 Apr 18, 2024
@mx-psi mx-psi added the help wanted Good issue for contributors to OpenTelemetry Service to pick up label Jul 17, 2024
@mx-psi mx-psi added the good first issue Good for newcomers label Aug 21, 2024
@mrasu
Copy link
Contributor

mrasu commented Sep 8, 2024

I'd like to try this at #11082

@codeboten
Copy link
Contributor

Thanks @mrasu, I'll assign it to you

mx-psi pushed a commit that referenced this issue Sep 9, 2024
#### Description

Create new function to enable to pass `component.Type` to
`scraperhelper.NewScraper`

Because many contrib scrapers name the scraper with the same name as the
component itself, create a function to take `component.Type`.
For example,
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/0e2bea5ac2763421e1a3943093f67184e109265f/receiver/activedirectorydsreceiver/factory_windows.go#L35
passes `metadata.Type.String()` as a name of scraper. With this change,
you can pass `metadata.Type` instead

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #9473
@github-project-automation github-project-automation bot moved this from Todo to Done in Collector: v1 Sep 9, 2024
@codeboten
Copy link
Contributor

Re-opening as it wont be completed until the deprecated methods have been removed

@codeboten codeboten reopened this Sep 9, 2024
@github-project-automation github-project-automation bot moved this from Done to Blocked in Collector: v1 Sep 9, 2024
dmathieu pushed a commit to dmathieu/opentelemetry-collector that referenced this issue Sep 10, 2024
…-telemetry#11082)

#### Description

Create new function to enable to pass `component.Type` to
`scraperhelper.NewScraper`

Because many contrib scrapers name the scraper with the same name as the
component itself, create a function to take `component.Type`.
For example,
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/0e2bea5ac2763421e1a3943093f67184e109265f/receiver/activedirectorydsreceiver/factory_windows.go#L35
passes `metadata.Type.String()` as a name of scraper. With this change,
you can pass `metadata.Type` instead

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes open-telemetry#9473
bogdandrutu pushed a commit that referenced this issue Sep 12, 2024
#### Description

As a step of
#9473,
make the first argument of `scraperhelper.NewScraper` to take
`component.Type`.

This PR deprecates `NewScraperWithComponentType` as the method is
temporary and was created to change an argument of `NewScraper`
@github-project-automation github-project-automation bot moved this from In Progress to Done in Collector: v1 Sep 28, 2024
jackgopack4 pushed a commit to jackgopack4/opentelemetry-collector that referenced this issue Oct 8, 2024
…elemetry#11294)

#### Description
Remove deprecated `scraperhelper.NewScraperWithComponentType`

This is the last change for open-telemetry#9473

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes open-telemetry#9473
HongChenTW pushed a commit to HongChenTW/opentelemetry-collector that referenced this issue Dec 19, 2024
…elemetry#11294)

#### Description
Remove deprecated `scraperhelper.NewScraperWithComponentType`

This is the last change for open-telemetry#9473

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes open-telemetry#9473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:receiver good first issue Good for newcomers help wanted Good issue for contributors to OpenTelemetry Service to pick up release:required-for-ga Must be resolved before GA release
Projects
Archived in project
5 participants