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

[chore] migrate receiver/* to use errors.Join #8225

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion receiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.25.0
)

Expand Down Expand Up @@ -52,6 +51,7 @@ require (
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions receiver/scrapererror/scrapeerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package scrapererror // import "go.opentelemetry.io/collector/receiver/scrapererror"

import (
"go.uber.org/multierr"
"errors"
)

// ScrapeErrors contains multiple PartialScrapeErrors and can also contain generic errors.
Expand Down Expand Up @@ -34,7 +34,7 @@ func (s *ScrapeErrors) Combine() error {
}
}

combined := multierr.Combine(s.errs...)
combined := errors.Join(s.errs...)
if !partialScrapeErr {
return combined
}
Expand Down
7 changes: 3 additions & 4 deletions receiver/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"time"

"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -144,12 +143,12 @@ func (sc *controller) Shutdown(ctx context.Context) error {
<-sc.terminated
}

var errs error
var errs []error
for _, scraper := range sc.scrapers {
errs = multierr.Append(errs, scraper.Shutdown(ctx))
errs = append(errs, scraper.Shutdown(ctx))
}

return errs
return errors.Join(errs...)
}

// startScraping initiates a ticker that calls Scrape based on the configured
Expand Down
7 changes: 3 additions & 4 deletions receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/codes"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/multierr"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
Expand Down Expand Up @@ -248,15 +247,15 @@ func getExpectedStartErr(test metricsTestCase) error {
}

func getExpectedShutdownErr(test metricsTestCase) error {
var errs error
var errs []error

if test.closeErr != nil {
for i := 0; i < test.scrapers; i++ {
errs = multierr.Append(errs, test.closeErr)
errs = append(errs, test.closeErr)
}
}

return errs
return errors.Join(errs...)
}

func assertChannelsCalled(t *testing.T, chs []chan bool, message string) {
Expand Down
11 changes: 5 additions & 6 deletions receiver/scraperhelper/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"fmt"
"time"

"go.uber.org/multierr"

"go.opentelemetry.io/collector/component"
)

Expand Down Expand Up @@ -42,12 +40,13 @@ func NewDefaultScraperControllerSettings(component.Type) ScraperControllerSettin
}
}

func (set *ScraperControllerSettings) Validate() (errs error) {
func (set *ScraperControllerSettings) Validate() error {
var errs []error
if set.CollectionInterval <= 0 {
errs = multierr.Append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval))
errs = append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval))
}
if set.Timeout < 0 {
errs = multierr.Append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval))
errs = append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval))
}
return errs
return errors.Join(errs...)
}
Loading