Skip to content

Commit

Permalink
Bump github.com/prometheus/prometheus (#3074)
Browse files Browse the repository at this point in the history
Fix the broken build due to the new storage.Appender and new configuration loading API.

Fixes #3071.
Closes #3066.
  • Loading branch information
rakyll authored Apr 30, 2021
1 parent 1eb6d1a commit b05f61b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 80 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ require (
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/prometheus/client_golang v1.10.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.20.0
github.com/prometheus/prometheus v1.8.2-0.20210217141258-a6be548dbc17
github.com/prometheus/common v0.23.0
github.com/prometheus/prometheus v1.8.2-0.20210430082741-2a4b8e12bbf2
github.com/rs/cors v1.7.0
github.com/shirou/gopsutil v3.21.3+incompatible
github.com/soheilhy/cmux v0.1.5
Expand All @@ -43,9 +43,9 @@ require (
go.opencensus.io v0.23.0
go.uber.org/atomic v1.7.0
go.uber.org/zap v1.16.0
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
golang.org/x/text v0.3.6
google.golang.org/genproto v0.0.0-20210302174412-5ede27ff9881
google.golang.org/genproto v0.0.0-20210312152112-fc591d9ea70f
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
Expand Down
143 changes: 84 additions & 59 deletions go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions receiver/prometheusreceiver/internal/ocastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"sync/atomic"

"github.com/prometheus/prometheus/pkg/exemplar"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/scrape"
"github.com/prometheus/prometheus/storage"
Expand Down Expand Up @@ -94,12 +95,12 @@ type noopAppender struct{}

var errAlreadyStopped = errors.New("already stopped")

func (*noopAppender) Add(labels.Labels, int64, float64) (uint64, error) {
func (*noopAppender) Append(uint64, labels.Labels, int64, float64) (uint64, error) {
return 0, errAlreadyStopped
}

func (*noopAppender) AddFast(uint64, int64, float64) error {
return errAlreadyStopped
func (*noopAppender) AppendExemplar(ref uint64, l labels.Labels, e exemplar.Exemplar) (uint64, error) {
return 0, errAlreadyStopped
}

func (*noopAppender) Commit() error {
Expand Down
8 changes: 2 additions & 6 deletions receiver/prometheusreceiver/internal/ocastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ func TestOcaStore(t *testing.T) {
}

func TestNoopAppender(t *testing.T) {
if _, err := noop.Add(labels.FromStrings("t", "v"), 1, 1); err == nil {
if _, err := noop.Append(0, labels.FromStrings("t", "v"), 1, 1); err == nil {
t.Error("expecting error from Add method of noopApender")
}
if _, err := noop.Add(labels.FromStrings("t", "v"), 1, 1); err == nil {
if _, err := noop.Append(0, labels.FromStrings("t", "v"), 1, 1); err == nil {
t.Error("expecting error from Add method of noopApender")
}

if err := noop.AddFast(0, 1, 1); err == nil {
t.Error("expecting error from AddFast method of noopApender")
}

if err := noop.Commit(); err == nil {
t.Error("expecting error from Commit method of noopApender")
}
Expand Down
9 changes: 7 additions & 2 deletions receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/exemplar"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/storage"
"go.uber.org/zap"
Expand Down Expand Up @@ -92,8 +93,8 @@ func newTransaction(ctx context.Context, jobsMap *JobsMap, useStartTimeMetric bo
// ensure *transaction has implemented the storage.Appender interface
var _ storage.Appender = (*transaction)(nil)

// Add always returns 0 to disable label caching.
func (tr *transaction) Add(ls labels.Labels, t int64, v float64) (uint64, error) {
// Append always returns 0 to disable label caching.
func (tr *transaction) Append(ref uint64, ls labels.Labels, t int64, v float64) (uint64, error) {
// Important, must handle. prometheus will still try to feed the appender some data even if it failed to
// scrape the remote target, if the previous scrape was success and some data were cached internally
// in our case, we don't need these data, simply drop them shall be good enough. more details:
Expand All @@ -116,6 +117,10 @@ func (tr *transaction) Add(ls labels.Labels, t int64, v float64) (uint64, error)
return 0, tr.metricBuilder.AddDataPoint(ls, t, v)
}

func (tr *transaction) AppendExemplar(ref uint64, l labels.Labels, e exemplar.Exemplar) (uint64, error) {
return 0, nil
}

// AddFast always returns error since caching is not supported by Add() function.
func (tr *transaction) AddFast(_ uint64, _ int64, _ float64) error {
return storage.ErrNotFound
Expand Down
10 changes: 5 additions & 5 deletions receiver/prometheusreceiver/internal/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Test_transaction(t *testing.T) {
t.Run("Add One No Target", func(t *testing.T) {
nomc := consumertest.NewNop()
tr := newTransaction(context.Background(), nil, true, "", rn, ms, nomc, testLogger)
if _, got := tr.Add(badLabels, time.Now().Unix()*1000, 1.0); got == nil {
if _, got := tr.Append(0, badLabels, time.Now().Unix()*1000, 1.0); got == nil {
t.Errorf("expecting error from Add() but got nil")
}
})
Expand All @@ -93,7 +93,7 @@ func Test_transaction(t *testing.T) {
t.Run("Add One Job not found", func(t *testing.T) {
nomc := consumertest.NewNop()
tr := newTransaction(context.Background(), nil, true, "", rn, ms, nomc, testLogger)
if _, got := tr.Add(jobNotFoundLb, time.Now().Unix()*1000, 1.0); got == nil {
if _, got := tr.Append(0, jobNotFoundLb, time.Now().Unix()*1000, 1.0); got == nil {
t.Errorf("expecting error from Add() but got nil")
}
})
Expand All @@ -104,7 +104,7 @@ func Test_transaction(t *testing.T) {
t.Run("Add One Good", func(t *testing.T) {
sink := new(consumertest.MetricsSink)
tr := newTransaction(context.Background(), nil, true, "", rn, ms, sink, testLogger)
if _, got := tr.Add(goodLabels, time.Now().Unix()*1000, 1.0); got != nil {
if _, got := tr.Append(0, goodLabels, time.Now().Unix()*1000, 1.0); got != nil {
t.Errorf("expecting error == nil from Add() but got: %v\n", got)
}
tr.metricBuilder.startTime = 1.0 // set to a non-zero value
Expand Down Expand Up @@ -134,7 +134,7 @@ func Test_transaction(t *testing.T) {
t.Run("Error when start time is zero", func(t *testing.T) {
sink := new(consumertest.MetricsSink)
tr := newTransaction(context.Background(), nil, true, "", rn, ms, sink, testLogger)
if _, got := tr.Add(goodLabels, time.Now().Unix()*1000, 1.0); got != nil {
if _, got := tr.Append(0, goodLabels, time.Now().Unix()*1000, 1.0); got != nil {
t.Errorf("expecting error == nil from Add() but got: %v\n", got)
}
tr.metricBuilder.startTime = 0 // zero value means the start time metric is missing
Expand All @@ -149,7 +149,7 @@ func Test_transaction(t *testing.T) {
t.Run("Drop NaN value", func(t *testing.T) {
sink := new(consumertest.MetricsSink)
tr := newTransaction(context.Background(), nil, true, "", rn, ms, sink, testLogger)
if _, got := tr.Add(goodLabels, time.Now().Unix()*1000, math.NaN()); got != nil {
if _, got := tr.Append(0, goodLabels, time.Now().Unix()*1000, math.NaN()); got != nil {
t.Errorf("expecting error == nil from Add() but got: %v\n", got)
}
if got := tr.Commit(); got != nil {
Expand Down
3 changes: 2 additions & 1 deletion receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
gokitlog "github.com/go-kit/kit/log"
"github.com/golang/protobuf/ptypes/wrappers"
promcfg "github.com/prometheus/prometheus/config"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -164,7 +165,7 @@ func setupMockPrometheus(tds ...*testData) (*mockPrometheus, *promcfg.Config, er
}

cfgStr := strings.ReplaceAll(string(cfg), srvPlaceHolder, u.Host)
pCfg, err := promcfg.Load(cfgStr)
pCfg, err := promcfg.Load(cfgStr, false, gokitlog.NewNopLogger())
return mp, pCfg, err
}

Expand Down

0 comments on commit b05f61b

Please sign in to comment.