-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[chore][receiver/splunkenterprise]Splunkent scrape refactor #31184
Conversation
ec46db8
to
e2bc83f
Compare
e2bc83f
to
07481d5
Compare
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 |
There was a problem hiding this comment.
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!
@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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that threadsafe?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// or add an error to errs | |
// or add an error to errs |
return | ||
case err, ok := <-eQueue: | ||
// shutdown | ||
if err == nil || !ok { |
There was a problem hiding this comment.
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)
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