Skip to content

Commit

Permalink
chore: replace pkg/errors with errors (grafana#13583)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Jul 19, 2024
1 parent 757bde0 commit 71cb767
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions pkg/ingester/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ingester
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/index/multi.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package index

import (
"fmt"
"time"

"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"

Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ingester

import (
"context"
"errors"
"flag"
"fmt"
"math/rand"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ingester

import (
"context"
"errors"
"fmt"
"math"
"net/http"
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions pkg/ingester/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/ingester/recovery.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pkg/ingester/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ingester
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"sync"
Expand All @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/ingester/wal/encoding.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 71cb767

Please sign in to comment.