Skip to content

Commit

Permalink
Remove use of github.com/pkg/errors, golang has all the utils (#1957)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Jan 7, 2021
1 parent 0b4c121 commit 0d4da96
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 19 deletions.
1 change: 0 additions & 1 deletion exporter/signalfxexporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion receiver/kubeletstatsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ 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)
}

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 {
Expand Down
7 changes: 3 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion receiver/kubeletstatsreceiver/kubelet/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
7 changes: 3 additions & 4 deletions receiver/kubeletstatsreceiver/kubelet/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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)
}
}

Expand Down
1 change: 0 additions & 1 deletion receiver/signalfxreceiver/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion testbed/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 0d4da96

Please sign in to comment.