Files
3126b728a2 [chore] move receiver/scrapererror to scraper/scrapererror (#11733)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Migrates existing scrapererror code to new scraper package. Sets aliases
for receiver/scrapererror so that dependent code in contrib and
elsewhere can be updated
<!-- Issue number if applicable -->
#### Link to tracking issue
Relates to #11003

<!--Describe what testing was performed and which tests were added.-->
#### Testing
included unit/integration tests should suffice
<!--Describe the documentation added.-->
#### Documentation
changelog yaml
<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Pablo Baeyens <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
2024-12-02 10:20:12 -08:00

44 lines
1.2 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package scrapererror // import "go.opentelemetry.io/collector/scraper/scrapererror"
import (
"go.uber.org/multierr"
)
// ScrapeErrors contains multiple PartialScrapeErrors and can also contain generic errors.
type ScrapeErrors struct {
errs []error
failedScrapeCount int
}
// AddPartial adds a PartialScrapeError with the provided failed count and error.
func (s *ScrapeErrors) AddPartial(failed int, err error) {
s.errs = append(s.errs, NewPartialScrapeError(err, failed))
s.failedScrapeCount += failed
}
// Add adds a regular error.
func (s *ScrapeErrors) Add(err error) {
s.errs = append(s.errs, err)
}
// Combine converts a slice of errors into one error.
// It will return a PartialScrapeError if at least one error in the slice is a PartialScrapeError.
func (s *ScrapeErrors) Combine() error {
partialScrapeErr := false
for _, err := range s.errs {
if IsPartialScrapeError(err) {
partialScrapeErr = true
}
}
combined := multierr.Combine(s.errs...)
if !partialScrapeErr {
return combined
}
return NewPartialScrapeError(combined, s.failedScrapeCount)
}