refactor (documentation): move from github.com/pkg/errors to 'errors' and 'fmt' (#10808)

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

Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
This commit is contained in:
Matthieu MOREL 2022-06-03 13:27:01 +02:00 committed by GitHub
parent 8801b01468
commit 12de742ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 17 deletions

View file

@ -7,7 +7,6 @@ require (
github.com/gogo/protobuf v1.3.2 github.com/gogo/protobuf v1.3.2
github.com/golang/snappy v0.0.4 github.com/golang/snappy v0.0.4
github.com/influxdata/influxdb v1.9.5 github.com/influxdata/influxdb v1.9.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1 github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.32.1 github.com/prometheus/common v0.32.1
github.com/prometheus/prometheus v1.8.2-0.20220202104425-d819219dd438 github.com/prometheus/prometheus v1.8.2-0.20220202104425-d819219dd438
@ -30,6 +29,7 @@ require (
github.com/jpillora/backoff v1.0.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect github.com/prometheus/common/sigv4 v0.1.0 // indirect

View file

@ -15,6 +15,7 @@ package influxdb
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math" "math"
"os" "os"
@ -23,7 +24,6 @@ import (
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/go-kit/log/level" "github.com/go-kit/log/level"
influx "github.com/influxdata/influxdb/client/v2" influx "github.com/influxdata/influxdb/client/v2"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
@ -174,7 +174,7 @@ func (c *Client) buildCommand(q *prompb.Query) (string, error) {
case prompb.LabelMatcher_NRE: case prompb.LabelMatcher_NRE:
matchers = append(matchers, fmt.Sprintf("%q !~ /^%s$/", m.Name, escapeSlashes(m.Value))) matchers = append(matchers, fmt.Sprintf("%q !~ /^%s$/", m.Name, escapeSlashes(m.Value)))
default: default:
return "", errors.Errorf("unknown match type %v", m.Type) return "", fmt.Errorf("unknown match type %v", m.Type)
} }
} }
matchers = append(matchers, fmt.Sprintf("time >= %vms", q.StartTimestampMs)) matchers = append(matchers, fmt.Sprintf("time >= %vms", q.StartTimestampMs))
@ -253,27 +253,27 @@ func valuesToSamples(values [][]interface{}) ([]prompb.Sample, error) {
samples := make([]prompb.Sample, 0, len(values)) samples := make([]prompb.Sample, 0, len(values))
for _, v := range values { for _, v := range values {
if len(v) != 2 { if len(v) != 2 {
return nil, errors.Errorf("bad sample tuple length, expected [<timestamp>, <value>], got %v", v) return nil, fmt.Errorf("bad sample tuple length, expected [<timestamp>, <value>], got %v", v)
} }
jsonTimestamp, ok := v[0].(json.Number) jsonTimestamp, ok := v[0].(json.Number)
if !ok { if !ok {
return nil, errors.Errorf("bad timestamp: %v", v[0]) return nil, fmt.Errorf("bad timestamp: %v", v[0])
} }
jsonValue, ok := v[1].(json.Number) jsonValue, ok := v[1].(json.Number)
if !ok { if !ok {
return nil, errors.Errorf("bad sample value: %v", v[1]) return nil, fmt.Errorf("bad sample value: %v", v[1])
} }
timestamp, err := jsonTimestamp.Int64() timestamp, err := jsonTimestamp.Int64()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "unable to convert sample timestamp to int64") return nil, fmt.Errorf("unable to convert sample timestamp to int64: %w", err)
} }
value, err := jsonValue.Float64() value, err := jsonValue.Float64()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "unable to convert sample value to float64") return nil, fmt.Errorf("unable to convert sample value to float64: %w", err)
} }
samples = append(samples, prompb.Sample{ samples = append(samples, prompb.Sample{

View file

@ -30,7 +30,6 @@ import (
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/golang/snappy" "github.com/golang/snappy"
influx "github.com/influxdata/influxdb/client/v2" influx "github.com/influxdata/influxdb/client/v2"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
@ -148,7 +147,7 @@ func parseFlags() *config {
_, err := a.Parse(os.Args[1:]) _, err := a.Parse(os.Args[1:])
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments")) fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing commandline arguments: %w", err))
a.Usage(os.Args[1:]) a.Usage(os.Args[1:])
os.Exit(2) os.Exit(2)
} }

View file

@ -17,6 +17,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"math" "math"
"net/http" "net/http"
@ -25,7 +26,6 @@ import (
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/go-kit/log/level" "github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
) )
@ -136,7 +136,7 @@ func (c *Client) Write(samples model.Samples) error {
if err := json.Unmarshal(buf, &r); err != nil { if err := json.Unmarshal(buf, &r); err != nil {
return err return err
} }
return errors.Errorf("failed to write %d samples to OpenTSDB, %d succeeded", r["failed"], r["success"]) return fmt.Errorf("failed to write %d samples to OpenTSDB, %d succeeded", r["failed"], r["success"])
} }
// Name identifies the client as an OpenTSDB client. // Name identifies the client as an OpenTSDB client.

View file

@ -17,7 +17,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/pkg/errors"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
) )
@ -98,13 +97,13 @@ func (tv *TagValue) UnmarshalJSON(json []byte) error {
for i, b := range json { for i, b := range json {
if i == 0 { if i == 0 {
if b != '"' { if b != '"' {
return errors.Errorf("expected '\"', got %q", b) return fmt.Errorf("expected '\"', got %q", b)
} }
continue continue
} }
if i == len(json)-1 { if i == len(json)-1 {
if b != '"' { if b != '"' {
return errors.Errorf("expected '\"', got %q", b) return fmt.Errorf("expected '\"', got %q", b)
} }
break break
} }
@ -130,7 +129,7 @@ func (tv *TagValue) UnmarshalJSON(json []byte) error {
parsedByte = (b - 55) << 4 parsedByte = (b - 55) << 4
escapeLevel = 2 escapeLevel = 2
default: default:
return errors.Errorf( return fmt.Errorf(
"illegal escape sequence at byte %d (%c)", "illegal escape sequence at byte %d (%c)",
i, b, i, b,
) )
@ -142,7 +141,7 @@ func (tv *TagValue) UnmarshalJSON(json []byte) error {
case b >= 'A' && b <= 'F': // A-F case b >= 'A' && b <= 'F': // A-F
parsedByte += b - 55 parsedByte += b - 55
default: default:
return errors.Errorf( return fmt.Errorf(
"illegal escape sequence at byte %d (%c)", "illegal escape sequence at byte %d (%c)",
i, b, i, b,
) )