Skip to content

Commit 820c3bf

Browse files
authored
Add matchers to LabelNames() ingester RPC (#6209)
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent 8b4630a commit 820c3bf

File tree

14 files changed

+293
-164
lines changed

14 files changed

+293
-164
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [ENHANCEMENT] Ingester: Add new API `/ingester/all_user_stats` which shows loaded blocks, active timeseries and ingestion rate for a specific ingester. #6178
1414
* [ENHANCEMENT] Distributor: Add new `cortex_reduced_resolution_histogram_samples_total` metric to track the number of histogram samples which resolution was reduced. #6182
1515
* [ENHANCEMENT] StoreGateway: Implement metadata API limit in queryable. #6195
16+
* [ENHANCEMENT] Ingester: Add matchers to ingester LabelNames() and LabelNamesStream() RPC. #6209
1617

1718
## 1.18.0 2024-09-03
1819

docs/blocks-storage/querier.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ querier:
109109
# CLI flag: -querier.ingester-metadata-streaming
110110
[ingester_metadata_streaming: <boolean> | default = true]
111111

112+
# Use LabelNames ingester RPCs with match params.
113+
# CLI flag: -querier.ingester-label-names-with-matchers
114+
[ingester_label_names_with_matchers: <boolean> | default = false]
115+
112116
# Maximum number of samples a single query can load into memory.
113117
# CLI flag: -querier.max-samples
114118
[max_samples: <int> | default = 50000000]

docs/configuration/config-file-reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,10 @@ The `querier_config` configures the Cortex querier.
37013701
# CLI flag: -querier.ingester-metadata-streaming
37023702
[ingester_metadata_streaming: <boolean> | default = true]
37033703
3704+
# Use LabelNames ingester RPCs with match params.
3705+
# CLI flag: -querier.ingester-label-names-with-matchers
3706+
[ingester_label_names_with_matchers: <boolean> | default = false]
3707+
37043708
# Maximum number of samples a single query can load into memory.
37053709
# CLI flag: -querier.max-samples
37063710
[max_samples: <int> | default = 50000000]

pkg/distributor/distributor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, t
11111111
}, matchers...)
11121112
}
11131113

1114-
func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time, hints *storage.LabelHints, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error)) ([]string, error) {
1114+
func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time, hints *storage.LabelHints, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error), matchers ...*labels.Matcher) ([]string, error) {
11151115
span, ctx := opentracing.StartSpanFromContext(ctx, "Distributor.LabelNames", opentracing.Tags{
11161116
"start": from.Unix(),
11171117
"end": to.Unix(),
@@ -1123,11 +1123,11 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
11231123
}
11241124

11251125
limit := getLimitFromLabelHints(hints)
1126-
req := &ingester_client.LabelNamesRequest{
1127-
StartTimestampMs: int64(from),
1128-
EndTimestampMs: int64(to),
1129-
Limit: int64(limit),
1126+
req, err := ingester_client.ToLabelNamesRequest(from, to, limit, matchers)
1127+
if err != nil {
1128+
return nil, err
11301129
}
1130+
11311131
resps, err := f(ctx, replicationSet, req)
11321132
if err != nil {
11331133
return nil, err
@@ -1152,7 +1152,7 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
11521152
return r, nil
11531153
}
11541154

1155-
func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time, hints *storage.LabelHints) ([]string, error) {
1155+
func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, error) {
11561156
return d.LabelNamesCommon(ctx, from, to, hints, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error) {
11571157
return d.ForReplicationSet(ctx, rs, d.cfg.ZoneResultsQuorumMetadata, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
11581158
stream, err := client.LabelNamesStream(ctx, req)
@@ -1174,11 +1174,11 @@ func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time,
11741174

11751175
return allLabelNames, nil
11761176
})
1177-
})
1177+
}, matchers...)
11781178
}
11791179

11801180
// LabelNames returns all the label names.
1181-
func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint *storage.LabelHints) ([]string, error) {
1181+
func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint *storage.LabelHints, matchers ...*labels.Matcher) ([]string, error) {
11821182
return d.LabelNamesCommon(ctx, from, to, hint, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error) {
11831183
return d.ForReplicationSet(ctx, rs, d.cfg.ZoneResultsQuorumMetadata, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
11841184
resp, err := client.LabelNames(ctx, req)
@@ -1187,7 +1187,7 @@ func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint
11871187
}
11881188
return resp.LabelNames, nil
11891189
})
1190-
})
1190+
}, matchers...)
11911191
}
11921192

11931193
// MetricsForLabelMatchers gets the metrics that match said matchers

pkg/ingester/client/compat.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@ func FromLabelValuesRequest(req *LabelValuesRequest) (string, int64, int64, int,
220220
return req.LabelName, req.StartTimestampMs, req.EndTimestampMs, int(req.Limit), matchers, nil
221221
}
222222

223+
// ToLabelNamesRequest builds a LabelNamesRequest proto
224+
func ToLabelNamesRequest(from, to model.Time, limit int, matchers []*labels.Matcher) (*LabelNamesRequest, error) {
225+
ms, err := toLabelMatchers(matchers)
226+
if err != nil {
227+
return nil, err
228+
}
229+
230+
return &LabelNamesRequest{
231+
StartTimestampMs: int64(from),
232+
EndTimestampMs: int64(to),
233+
Matchers: &LabelMatchers{Matchers: ms},
234+
Limit: int64(limit),
235+
}, nil
236+
}
237+
238+
// FromLabelNamesRequest unpacks a LabelNamesRequest proto
239+
func FromLabelNamesRequest(req *LabelNamesRequest) (int64, int64, int, []*labels.Matcher, error) {
240+
var err error
241+
var matchers []*labels.Matcher
242+
243+
if req.Matchers != nil {
244+
matchers, err = FromLabelMatchers(req.Matchers.Matchers)
245+
if err != nil {
246+
return 0, 0, 0, nil, err
247+
}
248+
}
249+
250+
return req.StartTimestampMs, req.EndTimestampMs, int(req.Limit), matchers, nil
251+
}
252+
223253
func toLabelMatchers(matchers []*labels.Matcher) ([]*LabelMatcher, error) {
224254
result := make([]*LabelMatcher, 0, len(matchers))
225255
for _, matcher := range matchers {

0 commit comments

Comments
 (0)