mirror of
https://github.com/grafana/loki.git
synced 2026-03-13 09:33:58 +08:00
chore: replace pkg/errors with errors (#13583)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user