-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add ScrapeErrors struct to simplify errors usage #2414
Add ScrapeErrors struct to simplify errors usage #2414
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2414 +/- ##
==========================================
- Coverage 91.78% 91.76% -0.02%
==========================================
Files 266 266
Lines 15099 15090 -9
==========================================
- Hits 13858 13847 -11
- Misses 865 866 +1
- Partials 376 377 +1
Continue to review full report at Codecov.
|
655c573
to
37f7da5
Compare
37f7da5
to
8c83cd7
Compare
8c83cd7
to
af87ba0
Compare
97aab26
to
cc49843
Compare
Rebased and applied changes from 5cc0707. |
} | ||
|
||
// Add adds a PartialScrapeError with the provided failed count and error. | ||
func (s *ScrapeErrors) Add(failed int, err error) { |
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.
I would call this AddPartial
, and rename AddRegular
to just Add
?
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.
Done.
func (s *ScrapeErrors) AddRegularf(format string, a ...interface{}) { | ||
s.errs = append(s.errs, fmt.Errorf(format, a...)) | ||
} |
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 this too much? Users can simply call AddRegular(fmt.Errorf(format, ...))
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.
Removed.
|
||
// Addf adds a PartialScrapeError with the provided failed count and arguments to format an error. | ||
func (s *ScrapeErrors) Addf(failed int, format string, a ...interface{}) { | ||
s.errs = append(s.errs, NewPartialScrapeError(fmt.Errorf(format, a...), failed)) |
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.
Do we need PartialScrapeError
to be exposed anymore? We should not remove it in this PR, but want to make sure we have a plan either remove it in a followup, or keep it there and understand why is necessary.
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.
We use Failed
field of PartialScrapeError
in other packages:
https://github.com/open-telemetry/opentelemetry-collector/blob/main/obsreport/obsreport_scraper.go#L104
So we need to introduce a method to retrieve this value and maybe add an interface instead of the exported PartialScrapeError
struct.
Add ScrapeErrors that contains a slice with errors and that has methods to simplify adding new PartialScrapeErrors and regular generic errors. Use new methods to refactor errors appends in receiver/hostmetricsreceiver. Use ScrapeErrors.Combine() in component/componenterror to not create cycling dependencies in consumererrors package.
Leave componenterror.CombineErrors unchanged to not introduce too many changes in a single PR. Add a note about the necessity of componenterror.CombineErrors deprecation.
Rename scrapeErrsCount field to failedScrapeCount. Add failed count in every Add, Addf call of ScrapeErrors and use this info to call CombineErrors directly instead of iterating over all errors in ScrapeErrors. Fix filesystemscraper Scrape function to not cast error into PartialScrapeError since it will cause panics after combining ScrapeErrors. Use NewPartialScrapeError instead.
Cast getProcessMetadata() error into consumererror.PartialScrapeError to get the valid scrape errors count.
Cast Scrape() error into consumererror.PartialScrapeError to get the valid scrape errors count and to not skip combined errors.
Fix `Combine()` method to check if errs slice contains `PartialScrapeError` since we can have scrape errors with 0 failed metrics so checking only `failedScrapeCount` field is not enough.
Do not change comments in consumer/consumererror/combineerrors_test.go.
Apply 5cc0707 to component/componenterror.
Use only Add and AddPartial methods.
cc49843
to
0c4c329
Compare
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.
As an FYI, this may get moved (I don't think will be removed) in the next 2months while we work on the stability of the main packages.
Description: Add ScrapeErrors that contains a slice with errors and that has methods
to simplify adding new PartialScrapeErrors and regular generic errors.
Use new methods to refactor errors appends in
receiver/hostmetricsreceiver.
Use ScrapeErrors.Combine() in component/componenterror to not create
cycling dependencies in consumererrors package.
Link to tracking Issue: #2046