diff --git a/pkg/ingester/checkpoint.go b/pkg/ingester/checkpoint.go index 9de54888f4748..1f6dcf8eefeee 100644 --- a/pkg/ingester/checkpoint.go +++ b/pkg/ingester/checkpoint.go @@ -3,6 +3,7 @@ package ingester import ( "bytes" "context" + "errors" "fmt" "os" "path/filepath" @@ -14,7 +15,6 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/gogo/protobuf/proto" - "github.com/pkg/errors" tsdb_errors "github.com/prometheus/prometheus/tsdb/errors" "github.com/prometheus/prometheus/tsdb/fileutil" "github.com/prometheus/prometheus/tsdb/wlog" @@ -125,7 +125,7 @@ func decodeCheckpointRecord(rec []byte, s *Series) error { case wal.CheckpointRecord: return proto.Unmarshal(cpy[1:], s) default: - return errors.Errorf("unexpected record type: %d", rec[0]) + return fmt.Errorf("unexpected record type: %d", rec[0]) } } @@ -345,12 +345,12 @@ func (w *WALCheckpointWriter) Advance() (bool, error) { } if err := os.MkdirAll(checkpointDirTemp, 0777); err != nil { - return false, errors.Wrap(err, "create checkpoint dir") + return false, fmt.Errorf("create checkpoint dir: %w", err) } checkpoint, err := wlog.NewSize(log.With(util_log.Logger, "component", "checkpoint_wal"), nil, checkpointDirTemp, walSegmentSize, wlog.CompressionNone) if err != nil { - return false, errors.Wrap(err, "open checkpoint") + return false, fmt.Errorf("open checkpoint: %w", err) } w.checkpointWAL = checkpoint @@ -493,7 +493,7 @@ func (w *WALCheckpointWriter) Close(abort bool) error { } if err := fileutil.Replace(w.checkpointWAL.Dir(), w.final); err != nil { - return errors.Wrap(err, "rename checkpoint directory") + return fmt.Errorf("rename checkpoint directory: %w", err) } level.Info(util_log.Logger).Log("msg", "atomic checkpoint finished", "old", w.checkpointWAL.Dir(), "new", w.final) // We delete the WAL segments which are before the previous checkpoint and not before the diff --git a/pkg/ingester/index/multi.go b/pkg/ingester/index/multi.go index 416876b1dcb25..293be18016b16 100644 --- a/pkg/ingester/index/multi.go +++ b/pkg/ingester/index/multi.go @@ -1,9 +1,9 @@ package index import ( + "fmt" "time" - "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" @@ -39,7 +39,7 @@ func NewMultiInvertedIndex(periods []config.PeriodConfig, indexShards uint32) (* if bitPrefixed == nil { bitPrefixed, err = NewBitPrefixWithShards(indexShards) if err != nil { - return nil, errors.Wrapf(err, "creating tsdb inverted index for period starting %v", pd.From) + return nil, fmt.Errorf("creating tsdb inverted index for period starting %v: %w", pd.From, err) } } periodIndices = append(periodIndices, periodIndex{ diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index af7f1fde288c9..da0021c11f3fd 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -2,6 +2,7 @@ package ingester import ( "context" + "errors" "flag" "fmt" "math/rand" @@ -29,7 +30,6 @@ import ( "github.com/grafana/dskit/services" "github.com/grafana/dskit/tenant" "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" @@ -543,7 +543,7 @@ func (i *Ingester) starting(ctx context.Context) error { shutdownMarkerPath := path.Join(i.cfg.ShutdownMarkerPath, shutdownMarkerFilename) shutdownMarker, err := shutdownMarkerExists(shutdownMarkerPath) if err != nil { - return errors.Wrap(err, "failed to check ingester shutdown marker") + return fmt.Errorf("failed to check ingester shutdown marker: %w", err) } if shutdownMarker { diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index 7391a8af71916..aeddd5e9f0f13 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.go @@ -2,6 +2,7 @@ package ingester import ( "context" + "errors" "fmt" "math" "net/http" @@ -15,7 +16,6 @@ import ( "github.com/grafana/dskit/ring" "github.com/grafana/dskit/tenant" "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/common/model" diff --git a/pkg/ingester/instance_test.go b/pkg/ingester/instance_test.go index 7a2647a3bb015..6867b0e1519c2 100644 --- a/pkg/ingester/instance_test.go +++ b/pkg/ingester/instance_test.go @@ -20,7 +20,6 @@ import ( "github.com/grafana/dskit/backoff" "github.com/grafana/dskit/flagext" - "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/require" @@ -53,7 +52,7 @@ func defaultConfig() *Config { OwnedStreamsCheckInterval: 1 * time.Second, } if err := cfg.Validate(); err != nil { - panic(errors.Wrap(err, "error building default test config")) + panic(fmt.Errorf("error building default test config: %w", err)) } return &cfg } diff --git a/pkg/ingester/recovery.go b/pkg/ingester/recovery.go index e8b1c244871bb..9ea4306bb5369 100644 --- a/pkg/ingester/recovery.go +++ b/pkg/ingester/recovery.go @@ -1,13 +1,14 @@ package ingester import ( + "errors" + "fmt" "io" "runtime" "sync" "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/pkg/errors" "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/record" "github.com/prometheus/prometheus/tsdb/wlog" @@ -159,12 +160,12 @@ func (r *ingesterRecoverer) Push(userID string, entries wal.RefEntries) error { return r.ing.replayController.WithBackPressure(func() error { out, ok := r.users.Load(userID) if !ok { - return errors.Errorf("user (%s) not set during WAL replay", userID) + return fmt.Errorf("user (%s) not set during WAL replay", userID) } s, ok := out.(*sync.Map).Load(entries.Ref) if !ok { - return errors.Errorf("stream (%d) not set during WAL replay for user (%s)", entries.Ref, userID) + return fmt.Errorf("stream (%d) not set during WAL replay for user (%s)", entries.Ref, userID) } // ignore out of order errors here (it's possible for a checkpoint to already have data from the wal segments) @@ -273,7 +274,7 @@ func RecoverWAL(ctx context.Context, reader WALReader, recoverer Recoverer) erro entries, ok := next.data.(wal.RefEntries) var err error if !ok { - err = errors.Errorf("unexpected type (%T) when recovering WAL, expecting (%T)", next.data, entries) + err = fmt.Errorf("unexpected type (%T) when recovering WAL, expecting (%T)", next.data, entries) } if err == nil { err = recoverer.Push(next.userID, entries) @@ -323,7 +324,7 @@ func RecoverCheckpoint(reader WALReader, recoverer Recoverer) error { series, ok := next.data.(*Series) var err error if !ok { - err = errors.Errorf("unexpected type (%T) when recovering WAL, expecting (%T)", next.data, series) + err = fmt.Errorf("unexpected type (%T) when recovering WAL, expecting (%T)", next.data, series) } if err == nil { err = recoverer.Series(series) diff --git a/pkg/ingester/recovery_test.go b/pkg/ingester/recovery_test.go index 4c5a4ce815d8d..97c55d3da9f8f 100644 --- a/pkg/ingester/recovery_test.go +++ b/pkg/ingester/recovery_test.go @@ -11,7 +11,6 @@ import ( "github.com/go-kit/log" "github.com/grafana/dskit/user" - "github.com/pkg/errors" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/record" @@ -142,7 +141,7 @@ func (r *MemRecoverer) SetStream(_ context.Context, userID string, series record } if _, exists := user[series.Ref]; exists { - return errors.Errorf("stream (%d) already exists for user (%s)", series.Ref, userID) + return fmt.Errorf("stream (%d) already exists for user (%s)", series.Ref, userID) } user[series.Ref] = make([]logproto.Entry, 0) @@ -156,12 +155,12 @@ func (r *MemRecoverer) Push(userID string, entries wal.RefEntries) error { user, ok := r.users[userID] if !ok { - return errors.Errorf("unexpected user access (%s)", userID) + return fmt.Errorf("unexpected user access (%s)", userID) } stream, ok := user[entries.Ref] if !ok { - return errors.Errorf("unexpected stream access") + return fmt.Errorf("unexpected stream access") } r.seriesCt += len(entries.Entries) diff --git a/pkg/ingester/stream.go b/pkg/ingester/stream.go index 7d37859b1541f..0754de9caf0fa 100644 --- a/pkg/ingester/stream.go +++ b/pkg/ingester/stream.go @@ -3,6 +3,7 @@ package ingester import ( "bytes" "context" + "errors" "fmt" "net/http" "sync" @@ -13,7 +14,6 @@ import ( "github.com/go-kit/log/level" "github.com/grafana/dskit/httpgrpc" "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" diff --git a/pkg/ingester/wal.go b/pkg/ingester/wal.go index 5a32aee050325..a87b2b995d79c 100644 --- a/pkg/ingester/wal.go +++ b/pkg/ingester/wal.go @@ -2,11 +2,11 @@ package ingester import ( "flag" + "fmt" "sync" "time" "github.com/go-kit/log/level" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/prometheus/tsdb/wlog" @@ -33,7 +33,7 @@ type WALConfig struct { func (cfg *WALConfig) Validate() error { if cfg.Enabled && cfg.CheckpointDuration < 1 { - return errors.Errorf("invalid checkpoint duration: %v", cfg.CheckpointDuration) + return fmt.Errorf("invalid checkpoint duration: %v", cfg.CheckpointDuration) } return nil } diff --git a/pkg/ingester/wal/encoding.go b/pkg/ingester/wal/encoding.go index a21ce57bf34b1..f59795c8a9fea 100644 --- a/pkg/ingester/wal/encoding.go +++ b/pkg/ingester/wal/encoding.go @@ -1,9 +1,10 @@ package wal import ( + "errors" + "fmt" "time" - "github.com/pkg/errors" "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/record" @@ -198,18 +199,18 @@ func DecodeEntries(b []byte, version RecordType, rec *Record) error { } if dec.Err() != nil { - return errors.Wrapf(dec.Err(), "entry decode error after %d RefEntries", nEntries-rem) + return fmt.Errorf("entry decode error after %d RefEntries: %w", nEntries-rem, dec.Err()) } rec.RefEntries = append(rec.RefEntries, refEntries) } if dec.Err() != nil { - return errors.Wrap(dec.Err(), "refEntry decode error") + return fmt.Errorf("refEntry decode error: %w", dec.Err()) } if len(dec.B) > 0 { - return errors.Errorf("unexpected %d bytes left in entry", len(dec.B)) + return fmt.Errorf("unexpected %d bytes left in entry", len(dec.B)) } return nil }