Skip to content

Commit 8cf8e29

Browse files
committed
Opmizing GetLabels and GetLabels values from store gateway
Signed-off-by: Alan Protasio <[email protected]>
1 parent a899c65 commit 8cf8e29

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pkg/querier/blocks_store_queryable.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, matchers ...*labels
345345

346346
var (
347347
resMtx sync.Mutex
348-
resNameSets = [][]string{}
348+
resNameSet = []string{}
349349
resWarnings = annotations.Annotations(nil)
350350
convertedMatchers = convertMatchersToLabelMatcher(matchers)
351351
)
@@ -357,7 +357,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, matchers ...*labels
357357
}
358358

359359
resMtx.Lock()
360-
resNameSets = append(resNameSets, nameSets...)
360+
resNameSet = strutil.MergeSlices(resNameSet, nameSets)
361361
resWarnings.Merge(warnings)
362362
resMtx.Unlock()
363363

@@ -368,7 +368,7 @@ func (q *blocksStoreQuerier) LabelNames(ctx context.Context, matchers ...*labels
368368
return nil, nil, err
369369
}
370370

371-
return strutil.MergeSlices(resNameSets...), resWarnings, nil
371+
return resNameSet, resWarnings, nil
372372
}
373373

374374
func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
@@ -383,7 +383,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, match
383383
minT, maxT := q.minT, q.maxT
384384

385385
var (
386-
resValueSets = [][]string{}
386+
resValueSets = []string{}
387387
resWarnings = annotations.Annotations(nil)
388388

389389
resultMtx sync.Mutex
@@ -396,7 +396,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, match
396396
}
397397

398398
resultMtx.Lock()
399-
resValueSets = append(resValueSets, valueSets...)
399+
resValueSets = strutil.MergeSlices(resValueSets, valueSets)
400400
resWarnings.Merge(warnings)
401401
resultMtx.Unlock()
402402

@@ -407,7 +407,7 @@ func (q *blocksStoreQuerier) LabelValues(ctx context.Context, name string, match
407407
return nil, nil, err
408408
}
409409

410-
return strutil.MergeSlices(resValueSets...), resWarnings, nil
410+
return resValueSets, resWarnings, nil
411411
}
412412

413413
func (q *blocksStoreQuerier) Close() error {
@@ -819,12 +819,12 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
819819
minT int64,
820820
maxT int64,
821821
matchers []storepb.LabelMatcher,
822-
) ([][]string, annotations.Annotations, []ulid.ULID, error, error) {
822+
) ([]string, annotations.Annotations, []ulid.ULID, error, error) {
823823
var (
824824
reqCtx = grpc_metadata.AppendToOutgoingContext(ctx, cortex_tsdb.TenantIDExternalLabel, userID)
825825
g, gCtx = errgroup.WithContext(reqCtx)
826826
mtx = sync.Mutex{}
827-
nameSets = [][]string{}
827+
nameSet = []string{}
828828
warnings = annotations.Annotations(nil)
829829
queriedBlocks = []ulid.ULID(nil)
830830
spanLog = spanlogger.FromContext(ctx)
@@ -894,7 +894,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
894894

895895
// Store the result.
896896
mtx.Lock()
897-
nameSets = append(nameSets, namesResp.Names)
897+
nameSet = strutil.MergeSlices(nameSet, namesResp.Names)
898898
for _, w := range namesResp.Warnings {
899899
warnings.Add(errors.New(w))
900900
}
@@ -910,7 +910,7 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(
910910
return nil, nil, nil, err, merr.Err()
911911
}
912912

913-
return nameSets, warnings, queriedBlocks, nil, merr.Err()
913+
return nameSet, warnings, queriedBlocks, nil, merr.Err()
914914
}
915915

916916
func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
@@ -921,12 +921,12 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
921921
minT int64,
922922
maxT int64,
923923
matchers ...*labels.Matcher,
924-
) ([][]string, annotations.Annotations, []ulid.ULID, error, error) {
924+
) ([]string, annotations.Annotations, []ulid.ULID, error, error) {
925925
var (
926926
reqCtx = grpc_metadata.AppendToOutgoingContext(ctx, cortex_tsdb.TenantIDExternalLabel, userID)
927927
g, gCtx = errgroup.WithContext(reqCtx)
928928
mtx = sync.Mutex{}
929-
valueSets = [][]string{}
929+
valueSet = []string{}
930930
warnings = annotations.Annotations(nil)
931931
queriedBlocks = []ulid.ULID(nil)
932932
spanLog = spanlogger.FromContext(ctx)
@@ -995,11 +995,13 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
995995
"queried blocks", strings.Join(convertULIDsToString(myQueriedBlocks), " "))
996996

997997
// Values returned need not be sorted, but we need them to be sorted so we can merge.
998-
sort.Strings(valuesResp.Values)
998+
if !sort.StringsAreSorted(valuesResp.Values) {
999+
sort.Strings(valuesResp.Values)
1000+
}
9991001

10001002
// Store the result.
10011003
mtx.Lock()
1002-
valueSets = append(valueSets, valuesResp.Values)
1004+
valueSet = strutil.MergeSlices(valueSet, valuesResp.Values)
10031005
for _, w := range valuesResp.Warnings {
10041006
warnings.Add(errors.New(w))
10051007
}
@@ -1015,7 +1017,7 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(
10151017
return nil, nil, nil, err, merr.Err()
10161018
}
10171019

1018-
return valueSets, warnings, queriedBlocks, nil, merr.Err()
1020+
return valueSet, warnings, queriedBlocks, nil, merr.Err()
10191021
}
10201022

10211023
func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shardingInfo *storepb.ShardInfo, skipChunks bool, blockIDs []ulid.ULID) (*storepb.SeriesRequest, error) {

0 commit comments

Comments
 (0)