Skip to content

Commit 5262d1e

Browse files
committed
Add matchers to LabelNames() ingester RPC
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent f74b4cd commit 5262d1e

14 files changed

+274
-146
lines changed

CHANGELOG.md

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

1516
## 1.18.0 2024-09-03
1617

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
@@ -1101,7 +1101,7 @@ func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, t
11011101
}, matchers...)
11021102
}
11031103

1104-
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) {
1104+
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) {
11051105
span, ctx := opentracing.StartSpanFromContext(ctx, "Distributor.LabelNames", opentracing.Tags{
11061106
"start": from.Unix(),
11071107
"end": to.Unix(),
@@ -1113,11 +1113,11 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
11131113
}
11141114

11151115
limit := getLimitFromLabelHints(hints)
1116-
req := &ingester_client.LabelNamesRequest{
1117-
StartTimestampMs: int64(from),
1118-
EndTimestampMs: int64(to),
1119-
Limit: int64(limit),
1116+
req, err := ingester_client.ToLabelNamesRequest(from, to, limit, matchers)
1117+
if err != nil {
1118+
return nil, err
11201119
}
1120+
11211121
resps, err := f(ctx, replicationSet, req)
11221122
if err != nil {
11231123
return nil, err
@@ -1142,7 +1142,7 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
11421142
return r, nil
11431143
}
11441144

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

11651165
return allLabelNames, nil
11661166
})
1167-
})
1167+
}, matchers...)
11681168
}
11691169

11701170
// LabelNames returns all the label names.
1171-
func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint *storage.LabelHints) ([]string, error) {
1171+
func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint *storage.LabelHints, matchers ...*labels.Matcher) ([]string, error) {
11721172
return d.LabelNamesCommon(ctx, from, to, hint, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest) ([]interface{}, error) {
11731173
return d.ForReplicationSet(ctx, rs, d.cfg.ZoneResultsQuorumMetadata, func(ctx context.Context, client ingester_client.IngesterClient) (interface{}, error) {
11741174
resp, err := client.LabelNames(ctx, req)
@@ -1177,7 +1177,7 @@ func (d *Distributor) LabelNames(ctx context.Context, from, to model.Time, hint
11771177
}
11781178
return resp.LabelNames, nil
11791179
})
1180-
})
1180+
}, matchers...)
11811181
}
11821182

11831183
// 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)