mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--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]>
44 lines
1.2 KiB
Go
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)
|
|
}
|