Merge pull request #13133 from mmorel-35/patch-8

tsdb/record: use Go standard errors package
This commit is contained in:
Julien Pivotto 2023-11-14 00:51:16 +01:00 committed by GitHub
commit 17fe6bc296
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 20 deletions

View file

@ -16,10 +16,10 @@
package record
import (
"errors"
"fmt"
"math"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/textparse"
@ -229,7 +229,7 @@ func (d *Decoder) Series(rec []byte, series []RefSeries) ([]RefSeries, error) {
return nil, dec.Err()
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return series, nil
}
@ -272,7 +272,7 @@ func (d *Decoder) Metadata(rec []byte, metadata []RefMetadata) ([]RefMetadata, e
return nil, dec.Err()
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return metadata, nil
}
@ -321,10 +321,10 @@ func (d *Decoder) Samples(rec []byte, samples []RefSample) ([]RefSample, error)
}
if dec.Err() != nil {
return nil, errors.Wrapf(dec.Err(), "decode error after %d samples", len(samples))
return nil, fmt.Errorf("decode error after %d samples: %w", len(samples), dec.Err())
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return samples, nil
}
@ -348,7 +348,7 @@ func (d *Decoder) Tombstones(rec []byte, tstones []tombstones.Stone) ([]tombston
return nil, dec.Err()
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return tstones, nil
}
@ -386,10 +386,10 @@ func (d *Decoder) ExemplarsFromBuffer(dec *encoding.Decbuf, exemplars []RefExemp
}
if dec.Err() != nil {
return nil, errors.Wrapf(dec.Err(), "decode error after %d exemplars", len(exemplars))
return nil, fmt.Errorf("decode error after %d exemplars: %w", len(exemplars), dec.Err())
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return exemplars, nil
}
@ -414,10 +414,10 @@ func (d *Decoder) MmapMarkers(rec []byte, markers []RefMmapMarker) ([]RefMmapMar
}
if dec.Err() != nil {
return nil, errors.Wrapf(dec.Err(), "decode error after %d mmap markers", len(markers))
return nil, fmt.Errorf("decode error after %d mmap markers: %w", len(markers), dec.Err())
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return markers, nil
}
@ -450,10 +450,10 @@ func (d *Decoder) HistogramSamples(rec []byte, histograms []RefHistogramSample)
}
if dec.Err() != nil {
return nil, errors.Wrapf(dec.Err(), "decode error after %d histograms", len(histograms))
return nil, fmt.Errorf("decode error after %d histograms: %w", len(histograms), dec.Err())
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return histograms, nil
}
@ -532,10 +532,10 @@ func (d *Decoder) FloatHistogramSamples(rec []byte, histograms []RefFloatHistogr
}
if dec.Err() != nil {
return nil, errors.Wrapf(dec.Err(), "decode error after %d histograms", len(histograms))
return nil, fmt.Errorf("decode error after %d histograms: %w", len(histograms), dec.Err())
}
if len(dec.B) > 0 {
return nil, errors.Errorf("unexpected %d bytes left in entry", len(dec.B))
return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
}
return histograms, nil
}

View file

@ -15,10 +15,10 @@
package record
import (
"errors"
"math/rand"
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/prometheus/prometheus/model/histogram"
@ -209,7 +209,7 @@ func TestRecord_Corrupted(t *testing.T) {
corrupted := enc.Samples(samples, nil)[:8]
_, err := dec.Samples(corrupted, nil)
require.Equal(t, errors.Cause(err), encoding.ErrInvalidSize)
require.True(t, errors.Is(err, encoding.ErrInvalidSize))
})
t.Run("Test corrupted tombstone record", func(t *testing.T) {
@ -232,7 +232,7 @@ func TestRecord_Corrupted(t *testing.T) {
corrupted := enc.Exemplars(exemplars, nil)[:8]
_, err := dec.Exemplars(corrupted, nil)
require.Equal(t, errors.Cause(err), encoding.ErrInvalidSize)
require.True(t, errors.Is(err, encoding.ErrInvalidSize))
})
t.Run("Test corrupted metadata record", func(t *testing.T) {
@ -242,7 +242,7 @@ func TestRecord_Corrupted(t *testing.T) {
corrupted := enc.Metadata(meta, nil)[:8]
_, err := dec.Metadata(corrupted, nil)
require.Equal(t, errors.Cause(err), encoding.ErrInvalidSize)
require.True(t, errors.Is(err, encoding.ErrInvalidSize))
})
t.Run("Test corrupted histogram record", func(t *testing.T) {
@ -267,7 +267,7 @@ func TestRecord_Corrupted(t *testing.T) {
corrupted := enc.HistogramSamples(histograms, nil)[:8]
_, err := dec.HistogramSamples(corrupted, nil)
require.Equal(t, errors.Cause(err), encoding.ErrInvalidSize)
require.True(t, errors.Is(err, encoding.ErrInvalidSize))
})
}