Skip to content

Commit e2be9f0

Browse files
committed
Select correct tenant during query federation
We are creating a job which has the tenant name for each tenant to query, but we use the incorrect index in the `ids` slice that contains the list of tenants. This causes the querier to select results for the first tenant in the list of tenants to match with instead of the actual tenant the querier was intended for. I updated the existing tests to check the labels of the results as well instead of only relying on the number of series found. Fixes cortexproject#5941 Signed-off-by: Charlie Le <[email protected]>
1 parent db10d87 commit e2be9f0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

pkg/querier/tenantfederation/merge_queryable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (m *mergeQuerier) Select(ctx context.Context, sortSeries bool, hints *stora
339339
return fmt.Errorf("unexpected type %T", jobIntf)
340340
}
341341
// Based on parent ctx here as we are using lazy querier.
342-
newCtx := user.InjectOrgID(parentCtx, ids[job.pos])
342+
newCtx := user.InjectOrgID(parentCtx, job.id)
343343
seriesSets[job.pos] = &addLabelsSeriesSet{
344344
upstream: job.querier.Select(newCtx, sortSeries, hints, filteredMatchers...),
345345
labels: labels.Labels{

pkg/querier/tenantfederation/merge_queryable_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,42 @@ func TestMergeQueryable_Select(t *testing.T) {
446446
name: "should return only series for team-a and team-c tenants when there is a not-equals matcher for the team-b tenant",
447447
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchNotEqual}},
448448
expectedSeriesCount: 4,
449+
expectedLabels: []labels.Labels{
450+
{
451+
{Name: "__tenant_id__", Value: "team-a"},
452+
{Name: "instance", Value: "host1"},
453+
{Name: "tenant-team-a", Value: "static"},
454+
},
455+
{
456+
{Name: "__tenant_id__", Value: "team-a"},
457+
{Name: "instance", Value: "host2.team-a"},
458+
},
459+
{
460+
{Name: "__tenant_id__", Value: "team-c"},
461+
{Name: "instance", Value: "host1"},
462+
{Name: "tenant-team-c", Value: "static"},
463+
},
464+
{
465+
{Name: "__tenant_id__", Value: "team-c"},
466+
{Name: "instance", Value: "host2.team-c"},
467+
},
468+
},
449469
},
450470
{
451471
name: "should return only series for team-b when there is an equals matcher for the team-b tenant",
452472
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchEqual}},
453473
expectedSeriesCount: 2,
474+
expectedLabels: []labels.Labels{
475+
{
476+
{Name: "__tenant_id__", Value: "team-b"},
477+
{Name: "instance", Value: "host1"},
478+
{Name: "tenant-team-b", Value: "static"},
479+
},
480+
{
481+
{Name: "__tenant_id__", Value: "team-b"},
482+
{Name: "instance", Value: "host2.team-b"},
483+
},
484+
},
454485
},
455486
{
456487
name: "should return one series for each tenant when there is an equals matcher for the host1 instance",
@@ -516,6 +547,19 @@ func TestMergeQueryable_Select(t *testing.T) {
516547
name: "should return only series for team-b when there is an equals matcher for team-b tenant",
517548
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchEqual}},
518549
expectedSeriesCount: 2,
550+
expectedLabels: []labels.Labels{
551+
{
552+
{Name: "__tenant_id__", Value: "team-b"},
553+
{Name: "instance", Value: "host1"},
554+
{Name: "original___tenant_id__", Value: "original-value"},
555+
{Name: "tenant-team-b", Value: "static"},
556+
},
557+
{
558+
{Name: "__tenant_id__", Value: "team-b"},
559+
{Name: "instance", Value: "host2.team-b"},
560+
{Name: "original___tenant_id__", Value: "original-value"},
561+
},
562+
},
519563
},
520564
{
521565
name: "should return all series when there is an equals matcher for the original value of __tenant_id__ using the revised tenant label",

0 commit comments

Comments
 (0)