From 89d611590f5a0b324da05e56e4b744452f793996 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 30 Jun 2022 17:07:43 +0200 Subject: [PATCH] deps: move from github.com/pkg/errors to 'errors' and 'fmt' (#11114) * deps: move from github.com/pkg/errors to 'errors' and 'fmt' Signed-off-by: Matthieu MOREL * clean changelog Signed-off-by: Matthieu MOREL Co-authored-by: Matthieu MOREL --- .golangci.yml | 1 + receiver/k8sclusterreceiver/go.mod | 2 +- receiver/k8sclusterreceiver/receiver.go | 7 ++- receiver/k8sclusterreceiver/watcher.go | 15 +++-- receiver/mongodbatlasreceiver/go.mod | 1 - receiver/mongodbatlasreceiver/go.sum | 1 - .../internal/mongodb_atlas_client.go | 13 ++--- receiver/mongodbatlasreceiver/receiver.go | 56 +++++++------------ 8 files changed, 39 insertions(+), 57 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e5b8b2511b78..35eb845a0bab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -102,6 +102,7 @@ linters-settings: packages-with-error-message: # See https://github.com/open-telemetry/opentelemetry-collector/issues/5200 for rationale - sync/atomic: "Use go.uber.org/atomic instead of sync/atomic" + - github.com/pkg/errors: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" linters: enable: diff --git a/receiver/k8sclusterreceiver/go.mod b/receiver/k8sclusterreceiver/go.mod index d77b84a14a17..f8871a3c2fe9 100644 --- a/receiver/k8sclusterreceiver/go.mod +++ b/receiver/k8sclusterreceiver/go.mod @@ -11,7 +11,6 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.54.0 github.com/openshift/api v0.0.0-20210521075222-e273a339932a github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.5 go.opentelemetry.io/collector v0.54.0 go.opentelemetry.io/collector/pdata v0.54.0 @@ -56,6 +55,7 @@ require ( github.com/onsi/ginkgo v1.14.1 // indirect github.com/onsi/gomega v1.10.3 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.54.0 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect go.opencensus.io v0.23.0 // indirect diff --git a/receiver/k8sclusterreceiver/receiver.go b/receiver/k8sclusterreceiver/receiver.go index bfc15aeef117..11d2f7476677 100644 --- a/receiver/k8sclusterreceiver/receiver.go +++ b/receiver/k8sclusterreceiver/receiver.go @@ -16,11 +16,11 @@ package k8sclusterreceiver // import "github.com/open-telemetry/opentelemetry-co import ( "context" + "errors" "fmt" "time" quotaclientset "github.com/openshift/client-go/quota/clientset/versioned" - "github.com/pkg/errors" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" @@ -115,11 +115,12 @@ func (kr *kubernetesReceiver) dispatchMetrics(ctx context.Context) { // newReceiver creates the Kubernetes cluster receiver with the given configuration. func newReceiver( set component.ReceiverCreateSettings, config *Config, consumer consumer.Metrics, - client kubernetes.Interface, osQuotaClient quotaclientset.Interface) (component.MetricsReceiver, error) { + client kubernetes.Interface, osQuotaClient quotaclientset.Interface, +) (component.MetricsReceiver, error) { resourceWatcher, err := newResourceWatcher(set.Logger, client, osQuotaClient, config.NodeConditionTypesToReport, config.AllocatableTypesToReport, defaultInitialSyncTimeout) if err != nil { - return nil, errors.Wrap(err, "Failed to setup the receiver") + return nil, fmt.Errorf("failed to setup the receiver: %w", err) } return &kubernetesReceiver{ diff --git a/receiver/k8sclusterreceiver/watcher.go b/receiver/k8sclusterreceiver/watcher.go index ca677d22ccd2..f034c537ebbf 100644 --- a/receiver/k8sclusterreceiver/watcher.go +++ b/receiver/k8sclusterreceiver/watcher.go @@ -23,7 +23,6 @@ import ( quotaclientset "github.com/openshift/client-go/quota/clientset/versioned" quotainformersv1 "github.com/openshift/client-go/quota/informers/externalversions" - "github.com/pkg/errors" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config" "go.uber.org/atomic" @@ -63,7 +62,8 @@ type metadataConsumer func(metadata []*metadata.MetadataUpdate) error func newResourceWatcher( logger *zap.Logger, client kubernetes.Interface, osQuotaClient quotaclientset.Interface, nodeConditionTypesToReport, allocatableTypesToReport []string, - initialSyncTimeout time.Duration) (*resourceWatcher, error) { + initialSyncTimeout time.Duration, +) (*resourceWatcher, error) { rw := &resourceWatcher{ client: client, osQuotaClient: osQuotaClient, @@ -141,7 +141,7 @@ func (rw *resourceWatcher) isKindSupported(gvk schema.GroupVersionKind) (bool, e rw.logger.Debug("Group version is not supported", zap.String("group", gvk.GroupVersion().String())) return false, nil } - return false, errors.Wrap(err, "Failed to fetch group version details") + return false, fmt.Errorf("failed to fetch group version details: %w", err) } for _, r := range resources.APIResources { @@ -269,7 +269,6 @@ func (rw *resourceWatcher) setupMetadataExporters( exporters map[config.ComponentID]component.Exporter, metadataExportersFromConfig []string, ) error { - var out []metadataConsumer metadataExportersSet := utils.StringSliceToMap(metadataExportersFromConfig) @@ -296,8 +295,8 @@ func (rw *resourceWatcher) setupMetadataExporters( } func validateMetadataExporters(metadataExporters map[string]bool, - exporters map[config.ComponentID]component.Exporter) error { - + exporters map[config.ComponentID]component.Exporter, +) error { configuredExporters := map[string]bool{} for cfg := range exporters { configuredExporters[cfg.String()] = true @@ -313,8 +312,8 @@ func validateMetadataExporters(metadataExporters map[string]bool, } func (rw *resourceWatcher) syncMetadataUpdate(oldMetadata, - newMetadata map[metadata.ResourceID]*collection.KubernetesMetadata) { - + newMetadata map[metadata.ResourceID]*collection.KubernetesMetadata, +) { metadataUpdate := collection.GetMetadataUpdate(oldMetadata, newMetadata) if len(metadataUpdate) == 0 { return diff --git a/receiver/mongodbatlasreceiver/go.mod b/receiver/mongodbatlasreceiver/go.mod index 758bb90cab69..e373ae320929 100644 --- a/receiver/mongodbatlasreceiver/go.mod +++ b/receiver/mongodbatlasreceiver/go.mod @@ -6,7 +6,6 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 github.com/hashicorp/go-multierror v1.1.1 github.com/mongodb-forks/digest v1.0.4 - github.com/pkg/errors v0.9.1 go.mongodb.org/atlas v0.16.0 go.opentelemetry.io/collector v0.54.0 go.uber.org/zap v1.21.0 diff --git a/receiver/mongodbatlasreceiver/go.sum b/receiver/mongodbatlasreceiver/go.sum index 8062d3d1d5ef..9cb9774984bd 100644 --- a/receiver/mongodbatlasreceiver/go.sum +++ b/receiver/mongodbatlasreceiver/go.sum @@ -175,7 +175,6 @@ github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= diff --git a/receiver/mongodbatlasreceiver/internal/mongodb_atlas_client.go b/receiver/mongodbatlasreceiver/internal/mongodb_atlas_client.go index 9afc9ccb390f..e57c6ed1ffb9 100644 --- a/receiver/mongodbatlasreceiver/internal/mongodb_atlas_client.go +++ b/receiver/mongodbatlasreceiver/internal/mongodb_atlas_client.go @@ -23,7 +23,6 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/mongodb-forks/digest" - "github.com/pkg/errors" "go.mongodb.org/atlas/mongodbatlas" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.uber.org/zap" @@ -42,8 +41,8 @@ type clientRoundTripper struct { func newClientRoundTripper( originalTransport http.RoundTripper, log *zap.Logger, - retrySettings exporterhelper.RetrySettings) *clientRoundTripper { - + retrySettings exporterhelper.RetrySettings, +) *clientRoundTripper { return &clientRoundTripper{ originalTransport: originalTransport, log: log, @@ -171,7 +170,7 @@ func (s *MongoDBAtlasClient) Organizations(ctx context.Context) ([]*mongodbatlas if err != nil { // TODO: Add error to a metric // Stop, returning what we have (probably empty slice) - return allOrgs, errors.Wrap(err, "error retrieving organizations from MongoDB Atlas API") + return allOrgs, fmt.Errorf("error retrieving organizations from MongoDB Atlas API: %w", err) } allOrgs = append(allOrgs, orgs...) if !hasNext { @@ -209,7 +208,7 @@ func (s *MongoDBAtlasClient) Projects( projects, hasNext, err := s.getProjectsPage(ctx, orgID, page) page++ if err != nil { - return allProjects, errors.Wrap(err, "error retrieving list of projects from MongoDB Atlas API") + return allProjects, fmt.Errorf("error retrieving list of projects from MongoDB Atlas API: %w", err) } allProjects = append(allProjects, projects...) if !hasNext { @@ -231,7 +230,7 @@ func (s *MongoDBAtlasClient) getProjectsPage( ) err = checkMongoDBClientErr(err, response) if err != nil { - return nil, false, errors.Wrap(err, "error retrieving project page") + return nil, false, fmt.Errorf("error retrieving project page: %w", err) } return projects.Results, hasNext(projects.Links), nil } @@ -259,7 +258,7 @@ func (s *MongoDBAtlasClient) Processes( ) err = checkMongoDBClientErr(err, response) if err != nil { - return make([]*mongodbatlas.Process, 0), errors.Wrap(err, "error retrieving processes from MongoDB Atlas API") + return make([]*mongodbatlas.Process, 0), fmt.Errorf("error retrieving processes from MongoDB Atlas API: %w", err) } return processes, nil } diff --git a/receiver/mongodbatlasreceiver/receiver.go b/receiver/mongodbatlasreceiver/receiver.go index d98da1be9996..2c516975a396 100644 --- a/receiver/mongodbatlasreceiver/receiver.go +++ b/receiver/mongodbatlasreceiver/receiver.go @@ -16,10 +16,10 @@ package mongodbatlasreceiver // import "github.com/open-telemetry/opentelemetry- import ( "context" + "fmt" "strconv" "time" - "github.com/pkg/errors" "go.mongodb.org/atlas/mongodbatlas" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pmetric" @@ -83,17 +83,17 @@ func (s *receiver) shutdown(context.Context) error { func (s *receiver) poll(ctx context.Context, time timeconstraints) error { orgs, err := s.client.Organizations(ctx) if err != nil { - return errors.Wrap(err, "error retrieving organizations") + return fmt.Errorf("error retrieving organizations: %w", err) } for _, org := range orgs { projects, err := s.client.Projects(ctx, org.ID) if err != nil { - return errors.Wrap(err, "error retrieving projects") + return fmt.Errorf("error retrieving projects: %w", err) } for _, project := range projects { processes, err := s.client.Processes(ctx, project.ID) if err != nil { - return errors.Wrap(err, "error retrieving MongoDB Atlas processes") + return fmt.Errorf("error retrieving MongoDB Atlas processes: %w", err) } for _, process := range processes { if err := s.extractProcessMetrics( @@ -129,35 +129,25 @@ func (s *receiver) extractProcessMetrics( ) error { // This receiver will support both logs and metrics- if one pipeline // or the other is not configured, it will be nil. - if err := - s.client.ProcessMetrics( - ctx, - s.mb, - project.ID, - process.Hostname, - process.Port, - time.start, - time.end, - time.resolution, - ); err != nil { - return errors.Wrap( - err, - "error when polling process metrics from MongoDB Atlas", - ) + if err := s.client.ProcessMetrics( + ctx, + s.mb, + project.ID, + process.Hostname, + process.Port, + time.start, + time.end, + time.resolution, + ); err != nil { + return fmt.Errorf("error when polling process metrics from MongoDB Atlas: %w", err) } if err := s.extractProcessDatabaseMetrics(ctx, time, orgName, project, process); err != nil { - return errors.Wrap( - err, - "error when polling process database metrics from MongoDB Atlas", - ) + return fmt.Errorf("error when polling process database metrics from MongoDB Atlas: %w", err) } if err := s.extractProcessDiskMetrics(ctx, time, orgName, project, process); err != nil { - return errors.Wrap( - err, - "error when polling process disk metrics from MongoDB Atlas", - ) + return fmt.Errorf("error when polling process disk metrics from MongoDB Atlas: %w", err) } return nil } @@ -176,7 +166,7 @@ func (s *receiver) extractProcessDatabaseMetrics( process.Port, ) if err != nil { - return errors.Wrap(err, "error retrieving process databases") + return fmt.Errorf("error retrieving process databases: %w", err) } for _, db := range processDatabases { @@ -191,10 +181,7 @@ func (s *receiver) extractProcessDatabaseMetrics( time.end, time.resolution, ); err != nil { - return errors.Wrap( - err, - "error when polling database metrics from MongoDB Atlas", - ) + return fmt.Errorf("error when polling database metrics from MongoDB Atlas: %w", err) } s.mb.EmitForResource( metadata.WithMongodbAtlasOrgName(orgName), @@ -229,10 +216,7 @@ func (s *receiver) extractProcessDiskMetrics( time.end, time.resolution, ); err != nil { - return errors.Wrap( - err, - "error when polling from MongoDB Atlas", - ) + return fmt.Errorf("error when polling from MongoDB Atlas: %w", err) } s.mb.EmitForResource( metadata.WithMongodbAtlasOrgName(orgName),