Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded Prometheus and Cortex dependencies #3382

Merged
merged 9 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/thanos/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func registerCheckRules(app extkingpin.AppClause) {
}

func checkRulesFiles(logger log.Logger, files *[]string) error {
var failed tsdb_errors.MultiError
failed := tsdb_errors.NewMulti()

for _, fn := range *files {
level.Info(logger).Log("msg", "checking", "filename", fn)
Expand All @@ -49,7 +49,7 @@ func checkRulesFiles(logger log.Logger, files *[]string) error {
defer func() { _ = f.Close() }()

n, errs := rules.ValidateAndCount(f)
if errs.Err() != nil {
if len(errs) > 0 {
level.Error(logger).Log("result", "FAILED")
for _, e := range errs {
level.Error(logger).Log("error", e.Error())
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/cespare/xxhash v1.1.0
github.com/chromedp/cdproto v0.0.0-20200424080200-0de008e41fa0
github.com/chromedp/chromedp v0.5.3
github.com/cortexproject/cortex v1.4.1-0.20201027005950-747d5950481b
github.com/cortexproject/cortex v1.4.1-0.20201030080541-83ad6df2abea
github.com/davecgh/go-spew v1.1.1
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
github.com/fatih/structtag v1.1.0
Expand All @@ -25,7 +25,7 @@ require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
github.com/golang/snappy v0.0.2
github.com/googleapis/gax-go v2.0.2+incompatible
github.com/gophercloud/gophercloud v0.12.0
github.com/gophercloud/gophercloud v0.13.0
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/golang-lru v0.5.4
Expand All @@ -48,16 +48,16 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.14.0
github.com/prometheus/prometheus v1.8.2-0.20201014093524-73e2ce1bd643
github.com/prometheus/prometheus v1.8.2-0.20201029103703-63be30dceed9
github.com/uber/jaeger-client-go v2.25.0+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
github.com/uber/jaeger-lib v2.4.0+incompatible
github.com/weaveworks/common v0.0.0-20200914083218-61ffdd448099
go.elastic.co/apm v1.5.0
go.elastic.co/apm/module/apmot v1.5.0
go.uber.org/atomic v1.7.0
go.uber.org/automaxprocs v1.2.0
go.uber.org/goleak v1.1.10
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/sync v0.0.0-20200930132711-30421366ff76
golang.org/x/text v0.3.3
Expand All @@ -77,7 +77,7 @@ replace (
// Update to v1.1.1 to make sure windows CI pass.
github.com/elastic/go-sysinfo => github.com/elastic/go-sysinfo v1.1.1
// Make sure Prometheus version is pinned as Prometheus semver does not include Go APIs.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20200922180708-b0145884d381
github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20201029103703-63be30dceed9
github.com/sercand/kuberesolver => github.com/sercand/kuberesolver v2.4.0+incompatible
google.golang.org/grpc => google.golang.org/grpc v1.29.1
k8s.io/klog => k8s.io/klog v0.3.1
Expand Down
118 changes: 64 additions & 54 deletions go.sum

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"testing"
"time"

"github.com/go-kit/kit/log"
"github.com/prometheus/common/route"
promgate "github.com/prometheus/prometheus/pkg/gate"
"github.com/prometheus/prometheus/pkg/labels"
Expand All @@ -40,6 +41,8 @@ import (
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/tsdb/tsdbutil"

"github.com/thanos-io/thanos/pkg/compact"

baseAPI "github.com/thanos-io/thanos/pkg/api"
Expand Down Expand Up @@ -618,22 +621,23 @@ func TestMetadataEndpoints(t *testing.T) {
dir, err := ioutil.TempDir("", "prometheus-test")
testutil.Ok(t, err)

var (
mint int64 = 0
maxt int64 = 600_000
)
var metricSamples []*tsdb.MetricSample
const chunkRange int64 = 600_000
var series []storage.Series

for _, lbl := range old {
var samples []tsdbutil.Sample

for i := int64(0); i < 10; i++ {
metricSamples = append(metricSamples, &tsdb.MetricSample{
TimestampMs: i * 60_000,
Value: float64(i),
Labels: lbl,
samples = append(samples, sample{
t: i * 60_000,
v: float64(i),
})
}

series = append(series, storage.NewListSeries(lbl, samples))
}

_, err = tsdb.CreateBlock(metricSamples, dir, mint, maxt, nil)
_, err = tsdb.CreateBlock(series, dir, chunkRange, log.NewNopLogger())
testutil.Ok(t, err)

opts := tsdb.DefaultOptions()
Expand Down Expand Up @@ -1626,3 +1630,17 @@ type mockedRulesClient struct {
func (c mockedRulesClient) Rules(_ context.Context, req *rulespb.RulesRequest) (*rulespb.RuleGroups, storage.Warnings, error) {
return &rulespb.RuleGroups{Groups: c.g[req.Type]}, c.w, c.err
}


type sample struct {
t int64
v float64
}

func (s sample) T() int64 {
return s.t
}

func (s sample) V() float64 {
return s.v
}
6 changes: 3 additions & 3 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ type response struct {
metas map[ulid.ULID]*metadata.Meta
partial map[ulid.ULID]error
// If metaErr > 0 it means incomplete view, so some metas, failed to be loaded.
metaErrs tsdberrors.MultiError
metaErrs []error

noMetas float64
corruptedMetas float64
Expand Down Expand Up @@ -310,7 +310,7 @@ func (f *BaseFetcher) fetchMetadata(ctx context.Context) (interface{}, error) {
switch errors.Cause(err) {
default:
mtx.Lock()
resp.metaErrs.Add(err)
resp.metaErrs = append(resp.metaErrs, err)
mtx.Unlock()
continue
case ErrorSyncMetaNotFound:
Expand Down Expand Up @@ -447,7 +447,7 @@ func (f *BaseFetcher) fetch(ctx context.Context, metrics *fetcherMetrics, filter
metrics.submit()

if len(resp.metaErrs) > 0 {
return metas, resp.partial, errors.Wrap(resp.metaErrs, "incomplete view")
return metas, resp.partial, errors.Wrap(tsdberrors.NewMulti(resp.metaErrs...).Err(), "incomplete view")
}

level.Info(f.logger).Log("msg", "successfully synchronized block metadata", "duration", time.Since(start).String(), "cached", len(f.cached), "returned", len(metas), "partial", len(resp.partial))
Expand Down
10 changes: 5 additions & 5 deletions pkg/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/tsdb"
terrors "github.com/prometheus/prometheus/tsdb/errors"

"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/compact/downsample"
"github.com/thanos-io/thanos/pkg/errutil"
"github.com/thanos-io/thanos/pkg/objstore"
)

Expand Down Expand Up @@ -516,7 +516,7 @@ func (e HaltError) Error() string {
// IsHaltError returns true if the base error is a HaltError.
// If a multierror is passed, any halt error will return true.
func IsHaltError(err error) bool {
if multiErr, ok := errors.Cause(err).(terrors.MultiError); ok {
if multiErr, ok := errors.Cause(err).(errutil.MultiError); ok {
for _, err := range multiErr {
if _, ok := errors.Cause(err).(HaltError); ok {
return true
Expand Down Expand Up @@ -549,7 +549,7 @@ func (e RetryError) Error() string {
// IsRetryError returns true if the base error is a RetryError.
// If a multierror is passed, all errors must be retriable.
func IsRetryError(err error) bool {
if multiErr, ok := errors.Cause(err).(terrors.MultiError); ok {
if multiErr, ok := errors.Cause(err).(errutil.MultiError); ok {
for _, err := range multiErr {
if _, ok := errors.Cause(err).(RetryError); !ok {
return false
Expand Down Expand Up @@ -963,7 +963,7 @@ func (c *BucketCompactor) Compact(ctx context.Context) (rerr error) {
level.Info(c.logger).Log("msg", "start of compactions")

// Send all groups found during this pass to the compaction workers.
var groupErrs terrors.MultiError
var groupErrs errutil.MultiError
groupLoop:
for _, g := range groups {
select {
Expand All @@ -985,7 +985,7 @@ func (c *BucketCompactor) Compact(ctx context.Context) (rerr error) {

workCtxCancel()
if len(groupErrs) > 0 {
return groupErrs
return groupErrs.Err()
}

if finishedAllGroups {
Expand Down
11 changes: 6 additions & 5 deletions pkg/compact/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/tsdb"
terrors "github.com/prometheus/prometheus/tsdb/errors"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/errutil"
"github.com/thanos-io/thanos/pkg/testutil"
)

Expand All @@ -32,7 +33,7 @@ func TestHaltMultiError(t *testing.T) {
haltErr := halt(errors.New("halt error"))
nonHaltErr := errors.New("not a halt error")

errs := terrors.MultiError{nonHaltErr}
errs := errutil.MultiError{nonHaltErr}
testutil.Assert(t, !IsHaltError(errs), "should not be a halt error")

errs.Add(haltErr)
Expand All @@ -45,15 +46,15 @@ func TestRetryMultiError(t *testing.T) {
retryErr := retry(errors.New("retry error"))
nonRetryErr := errors.New("not a retry error")

errs := terrors.MultiError{nonRetryErr}
errs := errutil.MultiError{nonRetryErr}
testutil.Assert(t, !IsRetryError(errs), "should not be a retry error")

errs = terrors.MultiError{retryErr}
errs = errutil.MultiError{retryErr}
testutil.Assert(t, IsRetryError(errs), "if all errors are retriable this should return true")

testutil.Assert(t, IsRetryError(errors.Wrap(errs, "wrap")), "retry error with wrap")

errs = terrors.MultiError{nonRetryErr, retryErr}
errs = errutil.MultiError{nonRetryErr, retryErr}
testutil.Assert(t, !IsRetryError(errs), "mixed errors should return false")
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/compact/downsample/downsample.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func Downsample(
// Remove blockDir in case of errors.
defer func() {
if err != nil {
var merr tsdberrors.MultiError
merr.Add(err)
merr.Add(os.RemoveAll(blockDir))
err = merr.Err()
err = tsdberrors.NewMulti(err, os.RemoveAll(blockDir)).Err()
}
}()

Expand Down
4 changes: 4 additions & 0 deletions pkg/compact/downsample/downsample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ func (b *memBlock) Close() error {
return nil
}

func (b *memBlock) Size() int64 {
return 0
}

type emptyTombstoneReader struct{}

func (emptyTombstoneReader) Get(ref uint64) (tombstones.Intervals, error) { return nil, nil }
Expand Down
5 changes: 2 additions & 3 deletions pkg/compact/downsample/streamed_block_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func NewStreamedBlockWriter(
// We should close any opened Closer up to an error.
defer func() {
if err != nil {
var merr tsdberrors.MultiError
merr.Add(err)
merr := tsdberrors.NewMulti(err)
for _, cl := range closers {
merr.Add(cl.Close())
}
Expand Down Expand Up @@ -143,7 +142,7 @@ func (w *streamedBlockWriter) Close() error {
}
w.finalized = true

merr := tsdberrors.MultiError{}
merr := tsdberrors.NewMulti()

if w.ignoreFinalize {
// Close open file descriptors anyway.
Expand Down
2 changes: 1 addition & 1 deletion pkg/discovery/dns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func GetQTypeName(addr string) (qtype string, name string) {
// defaultPort is used for non-SRV records when a port is not supplied.
func (p *Provider) Resolve(ctx context.Context, addrs []string) error {
resolvedAddrs := map[string][]string{}
errs := tsdberrors.MultiError{}
errs := tsdberrors.NewMulti()

for _, addr := range addrs {
var resolved []string
Expand Down
48 changes: 48 additions & 0 deletions pkg/errutil/multierror.go.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package errutil

import (
"bytes"
"fmt"
)

// The MultiError type implements the error interface, and contains the
// Errors used to construct it.
type MultiError []error

// Returns a concatenated string of the contained errors
func (es MultiError) Error() string {
var buf bytes.Buffer

if len(es) > 1 {
fmt.Fprintf(&buf, "%d errors: ", len(es))
}

for i, err := range es {
if i != 0 {
buf.WriteString("; ")
}
buf.WriteString(err.Error())
}

return buf.String()
}

// Add adds the error to the error list if it is not nil.
func (es *MultiError) Add(err error) {
if err == nil {
return
}
if merr, ok := err.(MultiError); ok {
*es = append(*es, merr...)
} else {
*es = append(*es, err)
}
}

// Err returns the error list as an error or nil if it is empty.
func (es MultiError) Err() error {
if len(es) == 0 {
return nil
}
return es
}
8 changes: 4 additions & 4 deletions pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"github.com/prometheus/common/route"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb"
terrors "github.com/prometheus/prometheus/tsdb/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/thanos-io/thanos/pkg/errutil"
extpromhttp "github.com/thanos-io/thanos/pkg/extprom/http"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/server/http/middleware"
Expand Down Expand Up @@ -389,7 +389,7 @@ func (h *Handler) writeQuorum() int {
// fanoutForward fans out concurrently given set of write requests. It returns status immediately when quorum of
// requests succeeds or fails or if context is canceled.
func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas map[string]replica, wreqs map[string]*prompb.WriteRequest, successThreshold int) error {
var errs terrors.MultiError
var errs errutil.MultiError

fctx, cancel := context.WithTimeout(tracing.CopyTraceContext(context.Background(), pctx), h.options.ForwardTimeout)
defer func() {
Expand Down Expand Up @@ -453,7 +453,7 @@ func (h *Handler) fanoutForward(pctx context.Context, tenant string, replicas ma
if err != nil {
// When a MultiError is added to another MultiError, the error slices are concatenated, not nested.
// To avoid breaking the counting logic, we need to flatten the error.
if errs, ok := err.(terrors.MultiError); ok {
if errs, ok := err.(errutil.MultiError); ok {
if countCause(errs, isConflict) > 0 {
err = errors.Wrap(conflictErr, errs.Error())
} else if countCause(errs, isNotReady) > 0 {
Expand Down Expand Up @@ -656,7 +656,7 @@ func (h *Handler) RemoteWrite(ctx context.Context, r *storepb.WriteRequest) (*st
// countCause will inspect the error's cause or, if the error is a MultiError,
// the cause of each contained error but will not traverse any deeper.
func countCause(err error, f func(error) bool) int {
errs, ok := err.(terrors.MultiError)
errs, ok := err.(errutil.MultiError)
if !ok {
errs = []error{err}
}
Expand Down
Loading