From 45d35f6a45a60c621a8ba634625e890d05750b3f Mon Sep 17 00:00:00 2001 From: shivanshu1333 Date: Mon, 14 Aug 2023 10:38:06 +0530 Subject: [PATCH 1/3] use errors.Join instead of go.uber.org/multierr --- receiver/scrapererror/scrapeerror.go | 4 ++-- receiver/scraperhelper/scrapercontroller.go | 3 +-- receiver/scraperhelper/scrapercontroller_test.go | 3 +-- receiver/scraperhelper/settings.go | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/receiver/scrapererror/scrapeerror.go b/receiver/scrapererror/scrapeerror.go index 9c1b4b08a20..db1548ea55c 100644 --- a/receiver/scrapererror/scrapeerror.go +++ b/receiver/scrapererror/scrapeerror.go @@ -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. @@ -34,7 +34,7 @@ func (s *ScrapeErrors) Combine() error { } } - combined := multierr.Combine(s.errs...) + combined := errors.Join(s.errs...) if !partialScrapeErr { return combined } diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index 9f3dd0b5f86..e43bfbb2fe7 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -8,7 +8,6 @@ import ( "errors" "time" - "go.uber.org/multierr" "go.uber.org/zap" "go.opentelemetry.io/collector/component" @@ -146,7 +145,7 @@ func (sc *controller) Shutdown(ctx context.Context) error { var errs error for _, scraper := range sc.scrapers { - errs = multierr.Append(errs, scraper.Shutdown(ctx)) + errs = errors.Join(errs, scraper.Shutdown(ctx)) } return errs diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index 707f683cf97..4a6964667e7 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -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" @@ -252,7 +251,7 @@ func getExpectedShutdownErr(test metricsTestCase) error { if test.closeErr != nil { for i := 0; i < test.scrapers; i++ { - errs = multierr.Append(errs, test.closeErr) + errs = errors.Join(errs, test.closeErr) } } diff --git a/receiver/scraperhelper/settings.go b/receiver/scraperhelper/settings.go index c59ea932583..00fa2a8d5bf 100644 --- a/receiver/scraperhelper/settings.go +++ b/receiver/scraperhelper/settings.go @@ -8,8 +8,6 @@ import ( "fmt" "time" - "go.uber.org/multierr" - "go.opentelemetry.io/collector/component" ) @@ -44,10 +42,10 @@ func NewDefaultScraperControllerSettings(component.Type) ScraperControllerSettin func (set *ScraperControllerSettings) Validate() (errs error) { if set.CollectionInterval <= 0 { - errs = multierr.Append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval)) + errs = errors.Join(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval)) } if set.Timeout < 0 { - errs = multierr.Append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval)) + errs = errors.Join(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval)) } return errs } From 11f01230ecae1e558986ced9bdd639b973715d63 Mon Sep 17 00:00:00 2001 From: shivanshu1333 Date: Mon, 14 Aug 2023 10:47:49 +0530 Subject: [PATCH 2/3] go mod tidy --- receiver/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/receiver/go.mod b/receiver/go.mod index 509ae7806bd..85131c41fce 100644 --- a/receiver/go.mod +++ b/receiver/go.mod @@ -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 ) @@ -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 From e481279875eee29b49d2bbd335a149f45b2c2342 Mon Sep 17 00:00:00 2001 From: shivanshu1333 Date: Fri, 1 Sep 2023 12:11:18 +0530 Subject: [PATCH 3/3] review comments: use slice to append errors --- receiver/scraperhelper/scrapercontroller.go | 6 +++--- receiver/scraperhelper/scrapercontroller_test.go | 6 +++--- receiver/scraperhelper/settings.go | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index e43bfbb2fe7..741583c43df 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -143,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 = errors.Join(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 diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index 4a6964667e7..5ea3eabcd35 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -247,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 = errors.Join(errs, test.closeErr) + errs = append(errs, test.closeErr) } } - return errs + return errors.Join(errs...) } func assertChannelsCalled(t *testing.T, chs []chan bool, message string) { diff --git a/receiver/scraperhelper/settings.go b/receiver/scraperhelper/settings.go index 00fa2a8d5bf..d5b99a16141 100644 --- a/receiver/scraperhelper/settings.go +++ b/receiver/scraperhelper/settings.go @@ -40,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 = errors.Join(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval)) + errs = append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval)) } if set.Timeout < 0 { - errs = errors.Join(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval)) + errs = append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval)) } - return errs + return errors.Join(errs...) }