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

Add ScrapeErrors struct to simplify errors usage #2414

Merged

Conversation

ozerovandrei
Copy link
Contributor

@ozerovandrei ozerovandrei commented Jan 28, 2021

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

@ozerovandrei ozerovandrei requested a review from a team January 28, 2021 08:18
@codecov
Copy link

codecov bot commented Jan 28, 2021

Codecov Report

Merging #2414 (0c4c329) into main (d442d7d) will decrease coverage by 0.01%.
The diff coverage is 95.45%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
receiver/scraperhelper/scrapercontroller.go 96.59% <66.66%> (-2.26%) ⬇️
consumer/consumererror/scrapeerrors.go 100.00% <100.00%> (ø)
...al/scraper/filesystemscraper/filesystem_scraper.go 100.00% <100.00%> (ø)
...internal/scraper/networkscraper/network_scraper.go 97.91% <100.00%> (ø)
...nal/scraper/pagingscraper/paging_scraper_others.go 100.00% <100.00%> (ø)
...internal/scraper/processscraper/process_scraper.go 98.14% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d442d7d...0c4c329. Read the comment docs.

Base automatically changed from master to main January 28, 2021 18:06
@ozerovandrei ozerovandrei force-pushed the 2046-improve-part-scrape-err branch from 655c573 to 37f7da5 Compare January 29, 2021 18:59
@ozerovandrei ozerovandrei force-pushed the 2046-improve-part-scrape-err branch from 37f7da5 to 8c83cd7 Compare February 3, 2021 18:21
component/componenterror/errors.go Outdated Show resolved Hide resolved
consumer/consumererror/combineerrors_test.go Outdated Show resolved Hide resolved
consumer/consumererror/combineerrors.go Outdated Show resolved Hide resolved
@ozerovandrei ozerovandrei force-pushed the 2046-improve-part-scrape-err branch from 8c83cd7 to af87ba0 Compare February 4, 2021 08:44
@ozerovandrei ozerovandrei force-pushed the 2046-improve-part-scrape-err branch 4 times, most recently from 97aab26 to cc49843 Compare February 14, 2021 18:26
@ozerovandrei
Copy link
Contributor Author

ozerovandrei commented Feb 14, 2021

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) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 45 to 47
func (s *ScrapeErrors) AddRegularf(format string, a ...interface{}) {
s.errs = append(s.errs, fmt.Errorf(format, a...))
}
Copy link
Member

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, ...))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

consumer/consumererror/scrapeerrors.go Show resolved Hide resolved

// 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))
Copy link
Member

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.

Copy link
Contributor Author

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.
@ozerovandrei ozerovandrei force-pushed the 2046-improve-part-scrape-err branch from cc49843 to 0c4c329 Compare February 17, 2021 17:06
Copy link
Member

@bogdandrutu bogdandrutu left a 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.

@bogdandrutu bogdandrutu merged commit 8fda120 into open-telemetry:main Feb 19, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants