From 0d4da965196df4efd19f6a030081ae8a1871cebd Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Wed, 6 Jan 2021 17:58:48 -0800 Subject: [PATCH] Remove use of github.com/pkg/errors, golang has all the utils (#1957) Signed-off-by: Bogdan Drutu --- exporter/signalfxexporter/go.sum | 1 - go.sum | 1 - receiver/kubeletstatsreceiver/go.mod | 1 - receiver/kubeletstatsreceiver/kubelet/cert.go | 8 ++++---- receiver/kubeletstatsreceiver/kubelet/client.go | 7 +++---- receiver/kubeletstatsreceiver/kubelet/metadata.go | 2 +- .../kubelet/metadata_provider_test.go | 2 +- receiver/kubeletstatsreceiver/kubelet/resource.go | 7 +++---- receiver/signalfxreceiver/go.sum | 1 - testbed/go.sum | 1 - 10 files changed, 12 insertions(+), 19 deletions(-) diff --git a/exporter/signalfxexporter/go.sum b/exporter/signalfxexporter/go.sum index 952d10ce2c67..ee4bb914d130 100644 --- a/exporter/signalfxexporter/go.sum +++ b/exporter/signalfxexporter/go.sum @@ -888,7 +888,6 @@ github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M= github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/go.sum b/go.sum index a5c5674dbf71..e897ce42a080 100644 --- a/go.sum +++ b/go.sum @@ -193,7 +193,6 @@ github.com/aws/aws-sdk-go v1.16.26/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi github.com/aws/aws-sdk-go v1.23.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.35.5/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= -github.com/aws/aws-sdk-go v1.36.19 h1:zbJZKkxeDiYxUYFjymjWxPye+qa1G2gRVyhIzZrB9zA= github.com/aws/aws-sdk-go v1.36.19/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.36.20 h1:IQr81xegCd40Xq21ZjFToKw9llaCzO1LRE75CgnvJ1Q= github.com/aws/aws-sdk-go v1.36.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= diff --git a/receiver/kubeletstatsreceiver/go.mod b/receiver/kubeletstatsreceiver/go.mod index e5687c2c982c..94adaa50dac4 100644 --- a/receiver/kubeletstatsreceiver/go.mod +++ b/receiver/kubeletstatsreceiver/go.mod @@ -6,7 +6,6 @@ require ( github.com/census-instrumentation/opencensus-proto v0.3.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.0.0-00010101000000-000000000000 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.0.0-00010101000000-000000000000 - github.com/pkg/errors v0.9.1 github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.6.1 go.opentelemetry.io/collector v0.17.0 diff --git a/receiver/kubeletstatsreceiver/kubelet/cert.go b/receiver/kubeletstatsreceiver/kubelet/cert.go index c4e947d0becc..c3ca2cd1bb80 100644 --- a/receiver/kubeletstatsreceiver/kubelet/cert.go +++ b/receiver/kubeletstatsreceiver/kubelet/cert.go @@ -16,15 +16,15 @@ package kubelet import ( "crypto/x509" + "errors" + "fmt" "io/ioutil" - - "github.com/pkg/errors" ) func systemCertPoolPlusPath(certPath string) (*x509.CertPool, error) { sysCerts, err := x509.SystemCertPool() if err != nil { - return nil, errors.WithMessage(err, "Could not load system x509 cert pool") + return nil, fmt.Errorf("could not load system x509 cert pool: %w", err) } return certPoolPlusPath(sysCerts, certPath) } @@ -32,7 +32,7 @@ func systemCertPoolPlusPath(certPath string) (*x509.CertPool, error) { func certPoolPlusPath(certPool *x509.CertPool, certPath string) (*x509.CertPool, error) { certBytes, err := ioutil.ReadFile(certPath) if err != nil { - return nil, errors.Wrapf(err, "Cert path %s could not be read", certPath) + return nil, fmt.Errorf("cert path %s could not be read: %w", certPath, err) } ok := certPool.AppendCertsFromPEM(certBytes) if !ok { diff --git a/receiver/kubeletstatsreceiver/kubelet/client.go b/receiver/kubeletstatsreceiver/kubelet/client.go index cfc9c1723fd3..42eb007a3fb6 100644 --- a/receiver/kubeletstatsreceiver/kubelet/client.go +++ b/receiver/kubeletstatsreceiver/kubelet/client.go @@ -22,7 +22,6 @@ import ( "net/http" "os" - "github.com/pkg/errors" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" @@ -98,7 +97,7 @@ func (p *saClientProvider) BuildClient() (Client, error) { } tok, err := ioutil.ReadFile(p.tokenPath) if err != nil { - return nil, errors.WithMessagef(err, "Unable to read token file %s", p.tokenPath) + return nil, fmt.Errorf("unable to read token file %s: %w", p.tokenPath, err) } tr := defaultTransport() tr.TLSClientConfig = &tls.Config{ @@ -143,7 +142,7 @@ func defaultTLSClient( func defaultEndpoint() (string, error) { hostname, err := os.Hostname() if err != nil { - return "", errors.WithMessage(err, "Unable to get hostname for default endpoint") + return "", fmt.Errorf("unable to get hostname for default endpoint: %w", err) } const kubeletPort = "10250" return hostname + ":" + kubeletPort, nil @@ -182,7 +181,7 @@ func (c *clientImpl) Get(path string) ([]byte, error) { body, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, errors.WithMessage(err, "failed to read Kubelet response body") + return nil, fmt.Errorf("failed to read Kubelet response body: %w", err) } if resp.StatusCode != http.StatusOK { diff --git a/receiver/kubeletstatsreceiver/kubelet/metadata.go b/receiver/kubeletstatsreceiver/kubelet/metadata.go index 35e837ee5d3f..28d389e357b5 100644 --- a/receiver/kubeletstatsreceiver/kubelet/metadata.go +++ b/receiver/kubeletstatsreceiver/kubelet/metadata.go @@ -15,10 +15,10 @@ package kubelet import ( + "errors" "fmt" "regexp" - "github.com/pkg/errors" "go.opentelemetry.io/collector/translator/conventions" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" diff --git a/receiver/kubeletstatsreceiver/kubelet/metadata_provider_test.go b/receiver/kubeletstatsreceiver/kubelet/metadata_provider_test.go index 94874a46b91c..34c103127a29 100644 --- a/receiver/kubeletstatsreceiver/kubelet/metadata_provider_test.go +++ b/receiver/kubeletstatsreceiver/kubelet/metadata_provider_test.go @@ -15,10 +15,10 @@ package kubelet import ( + "errors" "io/ioutil" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/receiver/kubeletstatsreceiver/kubelet/resource.go b/receiver/kubeletstatsreceiver/kubelet/resource.go index bbe9615ede71..90273458955e 100644 --- a/receiver/kubeletstatsreceiver/kubelet/resource.go +++ b/receiver/kubeletstatsreceiver/kubelet/resource.go @@ -18,7 +18,6 @@ import ( "fmt" resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1" - "github.com/pkg/errors" "go.opentelemetry.io/collector/translator/conventions" stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1" ) @@ -55,7 +54,7 @@ func containerResource(pod *resourcepb.Resource, s stats.ContainerStats, metadat MetadataLabelContainerID, labels[conventions.AttributeK8sContainer], ) if err != nil { - return nil, errors.WithMessage(err, "failed to set extra labels from metadata") + return nil, fmt.Errorf("failed to set extra labels from metadata: %w", err) } return &resourcepb.Resource{ @@ -74,7 +73,7 @@ func volumeResource(pod *resourcepb.Resource, vs stats.VolumeStats, metadata Met MetadataLabelVolumeType, labels[labelVolumeName], ) if err != nil { - return nil, errors.WithMessage(err, "failed to set extra labels from metadata") + return nil, fmt.Errorf("failed to set extra labels from metadata: %w", err) } if labels[labelVolumeType] == labelValuePersistentVolumeClaim { @@ -84,7 +83,7 @@ func volumeResource(pod *resourcepb.Resource, vs stats.VolumeStats, metadata Met pod.Labels[conventions.AttributeK8sNamespace], labels, ) if err != nil { - return nil, errors.WithMessage(err, "failed to set labels from volume claim") + return nil, fmt.Errorf("failed to set labels from volume claim: %w", err) } } diff --git a/receiver/signalfxreceiver/go.sum b/receiver/signalfxreceiver/go.sum index 952d10ce2c67..ee4bb914d130 100644 --- a/receiver/signalfxreceiver/go.sum +++ b/receiver/signalfxreceiver/go.sum @@ -888,7 +888,6 @@ github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M= github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/testbed/go.sum b/testbed/go.sum index 5886b00717e6..7dd627e27fca 100644 --- a/testbed/go.sum +++ b/testbed/go.sum @@ -966,7 +966,6 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs= github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.20.12+incompatible h1:6VEGkOXP/eP4o2Ilk8cSsX0PhOEfX6leqAnD+urrp9M= github.com/shirou/gopsutil v3.20.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=