Skip to content

Commit

Permalink
deps: move from github.com/pkg/errors to 'errors' and 'fmt' (open-tel…
Browse files Browse the repository at this point in the history
…emetry#11114)

* deps: move from github.com/pkg/errors to 'errors' and 'fmt'

Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>

* clean changelog

Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>

Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
  • Loading branch information
mmorel-35 and mmorel-35 authored Jun 30, 2022
1 parent 877066b commit 89d6115
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 57 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions receiver/k8sclusterreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
15 changes: 7 additions & 8 deletions receiver/k8sclusterreceiver/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -269,7 +269,6 @@ func (rw *resourceWatcher) setupMetadataExporters(
exporters map[config.ComponentID]component.Exporter,
metadataExportersFromConfig []string,
) error {

var out []metadataConsumer

metadataExportersSet := utils.StringSliceToMap(metadataExportersFromConfig)
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion receiver/mongodbatlasreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion receiver/mongodbatlasreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions receiver/mongodbatlasreceiver/internal/mongodb_atlas_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
56 changes: 20 additions & 36 deletions receiver/mongodbatlasreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 89d6115

Please sign in to comment.