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

[chore][receiver/splunkenterprise]Splunkent scrape refactor #31184

Merged
merged 47 commits into from Apr 4, 2024

Conversation

shalper2
Copy link
Contributor

Description: Refactored the way scrapes work to better utilize golang's language features to parallelize the scraping process.

Link to tracking Issue:

Testing: Existing tests cover the scrape process. Inclusion in a collector distribution was succesful.

Documentation: No changes to documentation

@shalper2 shalper2 requested a review from a team as a code owner March 6, 2024 14:21
Comment on lines 111 to 130
go func() {
errorListener(ctx, errChan, errOut)
}()

for _, fn := range metricScrapes {
wg.Add(1)
go func(
fn func(ctx context.Context, now pcommon.Timestamp, errs chan error),
ctx context.Context,
now pcommon.Timestamp,
errs chan error) {
// actual function body
defer wg.Done()
fn(ctx, now, errs)
}(fn, ctx, now, errChan)
}

wg.Wait()
errChan <- nil
errs = <-errOut

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor to channels is really smooth!

@shalper2
Copy link
Contributor Author

@open-telemetry/collector-contrib-approvers howdy! hoping someone could take a look at this for me

return
// or add an error to errs
} else {
errs.Add(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that threadsafe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Add adds a regular error.
func (s *ScrapeErrors) Add(err error) {
	s.errs = append(s.errs, err)
}

It is not threadsafe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about accumulating errors in the channel and emptying the channel all at once when the scrape is done?

Copy link
Contributor Author

@shalper2 shalper2 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry if im being a little dense but do i need to be worried about the threadsafety of Add() in this case? there is only one function which accesses the data in errs and it does so in a single routine.

if err == nil || !ok {
eOut <- errs
return
// or add an error to errs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// or add an error to errs
// or add an error to errs

@shalper2 shalper2 requested a review from atoulme March 27, 2024 13:57
return
case err, ok := <-eQueue:
// shutdown
if err == nil || !ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in #31260 (comment)

@dmitryax dmitryax merged commit 4eee6e5 into open-telemetry:main Apr 4, 2024
142 checks passed
@github-actions github-actions bot added this to the next release milestone Apr 4, 2024
ycombinator pushed a commit to ycombinator/opentelemetry-collector-contrib that referenced this pull request Apr 9, 2024
…emetry#31184)

**Description:** Refactored the way scrapes work to better utilize
golang's language features to parallelize the scraping process.

**Testing:** Existing tests cover the scrape process. Inclusion in a
collector distribution was succesful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants