Skip to content

Commit

Permalink
dep: remove deprecated pkg/errors package
Browse files Browse the repository at this point in the history
  • Loading branch information
prichrd committed May 23, 2024
1 parent 0854343 commit 1face57
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 723 deletions.
4 changes: 2 additions & 2 deletions cmd/do-agent/config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"errors"
"fmt"
"hash/fnv"
"net/url"
"os"
"strings"
"time"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -161,7 +161,7 @@ func checkConfig() error {
var err error
for name, uri := range config.targets {
if _, err = url.Parse(uri); err != nil {
return errors.Wrapf(err, "url for target %q is not valid", name)
return fmt.Errorf("url for target %q is not valid: %w", name, err)
}
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/do-agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"time"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"

Expand Down Expand Up @@ -99,7 +98,7 @@ func run(w metricWriter, l limiter, dec decorate.Decorator, g gatherer, aggregat
// writeDiagnostics filters all metrics and gathers only the diagnostic information and sends the metrics
// in the event of a write failure
func writeDiagnostics(w metricWriter, mfs []*dto.MetricFamily, err error) {
diagnosticMetric.WithLabelValues(errors.Cause(err).Error()).Inc()
diagnosticMetric.WithLabelValues(err.Error()).Inc()
var diags []*dto.MetricFamily

for _, mf := range mfs {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.22
require (
github.com/go-kit/kit v0.13.0
github.com/golang/snappy v0.0.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.30.0
Expand Down
5 changes: 2 additions & 3 deletions pkg/aggregate/aggregate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aggregate

import (
"github.com/pkg/errors"
dto "github.com/prometheus/client_model/go"

"github.com/digitalocean/do-agent/pkg/clients/tsclient"
Expand Down Expand Up @@ -44,11 +43,11 @@ func Aggregate(metrics []*dto.MetricFamily, aggregateSpec map[string][]string) (
def := tsclient.NewDefinition(*mf.Name, tsclient.WithCommonLabels(labels))
lfm, err := tsclient.GetLFM(def, tslbls)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
lfmDelim, err := tsclient.ParseMetricDelimited(lfm)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
labelsToRemove, ok := aggregateSpec[mf.GetName()]
if ok {
Expand Down
7 changes: 3 additions & 4 deletions pkg/clients/tsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/golang/snappy"
"github.com/pkg/errors"

"github.com/digitalocean/do-agent/internal/log"
"github.com/digitalocean/do-agent/pkg/clients/tsclient/structuredstream"
Expand Down Expand Up @@ -340,13 +339,13 @@ func (c *HTTPClient) addMetricWithMSEpochTime(def *Definition, ms int64, value f
}
lfm, err := GetLFM(def, labels)
if err != nil {
return errors.Wrap(err, "failed to get LFM")
return fmt.Errorf("failed to get LFM: %w", err)
}

if !isZeroTime {
// ensure sufficient time between reported metric values
if lastSend, ok := c.lastSend[lfm]; ok && (time.Duration(ms-lastSend)*time.Millisecond) < c.WaitDuration() {
return errors.WithStack(ErrSendTooFrequent)
return ErrSendTooFrequent
}
c.lastSend[lfm] = ms
}
Expand All @@ -357,7 +356,7 @@ func (c *HTTPClient) addMetricWithMSEpochTime(def *Definition, ms int64, value f
writer.Write(value)
if err := writer.Error(); err != nil {
log.Error("failed to write: %+v", err)
return errors.WithStack(ErrWriteFailure)
return ErrWriteFailure
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/collector/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/digitalocean/do-agent/internal/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/node_exporter/collector"
Expand Down Expand Up @@ -49,7 +48,7 @@ var metricWhitelist = []string{
func NewNodeCollector() (*NodeCollector, error) {
c, err := collector.NewNodeCollector(log.GetCollectorLogger())
if err != nil {
return nil, errors.Wrap(err, "failed to create NodeCollector")
return nil, fmt.Errorf("failed to create NodeCollector: %w", err)
}

return &NodeCollector{
Expand Down
13 changes: 6 additions & 7 deletions pkg/collector/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/digitalocean/do-agent/internal/log"
"github.com/digitalocean/do-agent/pkg/clients"
"github.com/digitalocean/do-agent/pkg/clients/roundtrippers"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
Expand Down Expand Up @@ -82,7 +81,7 @@ func NewScraper(name, metricsEndpoint string, extraMetricLabels []*dto.LabelPair
metricsEndpoint = strings.TrimRight(metricsEndpoint, "/")
req, err := http.NewRequest("GET", metricsEndpoint, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to create http request")
return nil, fmt.Errorf("failed to create http request: %w", err)
}
req.Header.Add("Accept", `text/plain;version=0.0.4;q=1,*/*;q=0.1`)
req.Header.Add("Accept-Encoding", "gzip")
Expand Down Expand Up @@ -149,25 +148,25 @@ func (s *Scraper) readStream(ctx context.Context) (r io.ReadCloser, outerr error
if err := r.Close(); err != nil {
// This should not happen, but if it does it'll be nice
// to know why we have a bunch of unclosed messages
s.log("failed to close stream on error: %+v", errors.WithStack(err))
s.log("failed to close stream on error: %s", err)
}
}()

resp, err := s.client.Do(s.req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "HTTP request failed")
return nil, fmt.Errorf("HTTP request failed: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("server returned bad HTTP status %s", resp.Status)
return nil, fmt.Errorf("server returned bad HTTP status %s", resp.Status)
}

if resp.Header.Get("Content-Encoding") != "gzip" {
return resp.Body, nil
}

reader, err := gzip.NewReader(bufio.NewReader(resp.Body))
return reader, errors.Wrap(err, "failed to create gzip reader")
return reader, fmt.Errorf("failed to create gzip reader: %w", err)
}

// Describe describes this collector
Expand Down Expand Up @@ -207,7 +206,7 @@ func (s *Scraper) scrape(ctx context.Context, ch chan<- prometheus.Metric) (oute

parsed, err := new(expfmt.TextParser).TextToMetricFamilies(stream)
if err != nil {
return errors.Wrapf(err, "parsing message failed")
return fmt.Errorf("parsing message failed: %w", err)
}

for _, mf := range parsed {
Expand Down
6 changes: 2 additions & 4 deletions pkg/writer/sonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/digitalocean/do-agent/pkg/aggregate"
"github.com/digitalocean/do-agent/pkg/clients/tsclient"
"github.com/prometheus/client_golang/prometheus"

"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -45,14 +43,14 @@ func NewSonar(client tsclient.Client, c *prometheus.CounterVec) *Sonar {
func (s *Sonar) Write(mets []aggregate.MetricWithValue) error {
if len(mets) > s.client.MaxBatchSize() {
s.c.WithLabelValues("failure", "too many metrics").Inc()
return errors.Wrap(ErrTooManyMetrics, "cannot write metrics")
return fmt.Errorf("cannot write metrics: %w", ErrTooManyMetrics)
}

for _, m := range mets {
lfmEncoded := tsclient.ConvertLFMMapToPrometheusEncodedName(m.LFM)
if len(lfmEncoded) > s.client.MaxMetricLength() {
s.c.WithLabelValues("failure", "metric exceeds max length").Inc()
return errors.Wrapf(ErrMetricTooLong, "cannot send metric: %q", lfmEncoded)
return fmt.Errorf("cannot send metric %q: %w", lfmEncoded, ErrMetricTooLong)
}
err := s.client.AddMetric(tsclient.NewDefinitionFromMap(m.LFM), m.Value)
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions vendor/github.com/pkg/errors/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/pkg/errors/.travis.yml

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/pkg/errors/LICENSE

This file was deleted.

44 changes: 0 additions & 44 deletions vendor/github.com/pkg/errors/Makefile

This file was deleted.

59 changes: 0 additions & 59 deletions vendor/github.com/pkg/errors/README.md

This file was deleted.

Loading

0 comments on commit 1face57

Please sign in to comment.