Skip to content

Update Prometheus; add matchers parameter to LabelValues on ingester #3806

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

Merged
merged 5 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/Azure/azure-storage-blob-go v0.8.0
github.com/Masterminds/squirrel v0.0.0-20161115235646-20f192218cf5
github.com/NYTimes/gziphandler v1.1.1
github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/armon/go-metrics v0.3.6
github.com/aws/aws-sdk-go v1.36.15
github.com/aws/aws-sdk-go v1.37.8
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
github.com/cespare/xxhash v1.1.0
github.com/dustin/go-humanize v1.0.0
Expand All @@ -22,7 +22,7 @@ require (
github.com/go-kit/kit v0.10.0
github.com/go-redis/redis/v8 v8.2.3
github.com/gocql/gocql v0.0.0-20200526081602-cd04bd7f22a7
github.com/gogo/protobuf v1.3.1
github.com/gogo/protobuf v1.3.2
github.com/gogo/status v1.0.3
github.com/golang-migrate/migrate/v4 v4.7.0
github.com/golang/protobuf v1.4.3
Expand All @@ -47,24 +47,24 @@ require (
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.15.0
github.com/prometheus/prometheus v1.8.2-0.20210124145330-b5dfa2414b9e
github.com/prometheus/prometheus v1.8.2-0.20210215121130-6f488061dfb4
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e
github.com/sony/gobreaker v0.4.1
github.com/spf13/afero v1.2.2
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/thanos-io/thanos v0.13.1-0.20210204123931-82545cdd16fe
github.com/uber/jaeger-client-go v2.25.0+incompatible
github.com/weaveworks/common v0.0.0-20210112142934-23c8d7fa6120
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50
go.etcd.io/etcd v0.5.0-alpha.5.0.20200520232829-54ba9589114f
go.uber.org/atomic v1.7.0
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
google.golang.org/api v0.36.0
google.golang.org/grpc v1.33.2
google.golang.org/api v0.39.0
google.golang.org/grpc v1.34.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
sigs.k8s.io/yaml v1.2.0
)

Expand Down
108 changes: 82 additions & 26 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func NewQuerierHandler(
api := v1.NewAPI(
engine,
errorTranslateQueryable{queryable}, // Translate errors to errors expected by API.
nil, // No remote write support.
func(context.Context) v1.TargetRetriever { return &querier.DummyTargetRetriever{} },
func(context.Context) v1.AlertmanagerRetriever { return &querier.DummyAlertmanagerRetriever{} },
func() config.Config { return config.Config{} },
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ type errorTranslateQuerier struct {
q storage.Querier
}

func (e errorTranslateQuerier) LabelValues(name string) ([]string, storage.Warnings, error) {
values, warnings, err := e.q.LabelValues(name)
func (e errorTranslateQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([]string, storage.Warnings, error) {
values, warnings, err := e.q.LabelValues(name, matchers...)
return values, warnings, translateError(err)
}

Expand All @@ -99,8 +99,8 @@ type errorTranslateChunkQuerier struct {
q storage.ChunkQuerier
}

func (e errorTranslateChunkQuerier) LabelValues(name string) ([]string, storage.Warnings, error) {
values, warnings, err := e.q.LabelValues(name)
func (e errorTranslateChunkQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([]string, storage.Warnings, error) {
values, warnings, err := e.q.LabelValues(name, matchers...)
return values, warnings, translateError(err)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/api/queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func createPrometheusAPI(q storage.SampleAndChunkQueryable) *route.Router {
api := v1.NewAPI(
engine,
q,
nil,
func(context.Context) v1.TargetRetriever { return &querier.DummyTargetRetriever{} },
func(context.Context) v1.AlertmanagerRetriever { return &querier.DummyAlertmanagerRetriever{} },
func() config.Config { return config.Config{} },
Expand Down Expand Up @@ -180,7 +181,7 @@ type testQuerier struct {
err error
}

func (t testQuerier) LabelValues(name string) ([]string, storage.Warnings, error) {
func (t testQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([]string, storage.Warnings, error) {
return nil, nil, t.err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/configs/legacy_promql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type errQuerier struct {
func (q *errQuerier) Select(bool, *storage.SelectHints, ...*labels.Matcher) storage.SeriesSet {
return storage.ErrSeriesSet(q.err)
}
func (q *errQuerier) LabelValues(name string) ([]string, storage.Warnings, error) {
func (q *errQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([]string, storage.Warnings, error) {
return nil, nil, q.err
}
func (q *errQuerier) LabelNames() ([]string, storage.Warnings, error) { return nil, nil, q.err }
Expand Down
10 changes: 5 additions & 5 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,17 +702,17 @@ func (d *Distributor) ForReplicationSet(ctx context.Context, replicationSet ring
}

// LabelValuesForLabelName returns all of the label values that are associated with a given label name.
func (d *Distributor) LabelValuesForLabelName(ctx context.Context, from, to model.Time, labelName model.LabelName) ([]string, error) {
func (d *Distributor) LabelValuesForLabelName(ctx context.Context, from, to model.Time, labelName model.LabelName, matchers ...*labels.Matcher) ([]string, error) {
replicationSet, err := d.GetIngestersForMetadata(ctx)
if err != nil {
return nil, err
}

req := &ingester_client.LabelValuesRequest{
LabelName: string(labelName),
StartTimestampMs: int64(from),
EndTimestampMs: int64(to),
req, err := ingester_client.ToLabelValuesRequest(labelName, from, to, matchers)
if err != nil {
return nil, err
}

resps, err := d.ForReplicationSet(ctx, replicationSet, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
return client.LabelValues(ctx, req)
})
Expand Down
30 changes: 30 additions & 0 deletions pkg/ingester/client/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ func FromMetricsForLabelMatchersResponse(resp *MetricsForLabelMatchersResponse)
return metrics
}

// ToLabelValuesRequest builds a LabelValuesRequest proto
func ToLabelValuesRequest(labelName model.LabelName, from, to model.Time, matchers []*labels.Matcher) (*LabelValuesRequest, error) {
ms, err := toLabelMatchers(matchers)
if err != nil {
return nil, err
}

return &LabelValuesRequest{
LabelName: string(labelName),
StartTimestampMs: int64(from),
EndTimestampMs: int64(to),
Matchers: &LabelMatchers{Matchers: ms},
}, nil
}

// FromLabelValuesRequest unpacks a LabelValuesRequest proto
func FromLabelValuesRequest(req *LabelValuesRequest) (string, int64, int64, []*labels.Matcher, error) {
var err error
var matchers []*labels.Matcher

if req.Matchers != nil {
matchers, err = fromLabelMatchers(req.Matchers.Matchers)
if err != nil {
return "", 0, 0, nil, err
}
}

return req.LabelName, req.StartTimestampMs, req.EndTimestampMs, matchers, nil
}

func toLabelMatchers(matchers []*labels.Matcher) ([]*LabelMatcher, error) {
result := make([]*LabelMatcher, 0, len(matchers))
for _, matcher := range matchers {
Expand Down
Loading