Skip to content
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

Select correct tenant during query federation #5943

Merged
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
2 changes: 1 addition & 1 deletion pkg/querier/tenantfederation/merge_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (m *mergeQuerier) Select(ctx context.Context, sortSeries bool, hints *stora
return fmt.Errorf("unexpected type %T", jobIntf)
}
// Based on parent ctx here as we are using lazy querier.
newCtx := user.InjectOrgID(parentCtx, ids[job.pos])
newCtx := user.InjectOrgID(parentCtx, job.id)
seriesSets[job.pos] = &addLabelsSeriesSet{
upstream: job.querier.Select(newCtx, sortSeries, hints, filteredMatchers...),
labels: labels.Labels{
Expand Down
44 changes: 44 additions & 0 deletions pkg/querier/tenantfederation/merge_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,42 @@ func TestMergeQueryable_Select(t *testing.T) {
name: "should return only series for team-a and team-c tenants when there is a not-equals matcher for the team-b tenant",
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchNotEqual}},
expectedSeriesCount: 4,
expectedLabels: []labels.Labels{
{
{Name: "__tenant_id__", Value: "team-a"},
{Name: "instance", Value: "host1"},
{Name: "tenant-team-a", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-a"},
{Name: "instance", Value: "host2.team-a"},
},
{
{Name: "__tenant_id__", Value: "team-c"},
{Name: "instance", Value: "host1"},
{Name: "tenant-team-c", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-c"},
{Name: "instance", Value: "host2.team-c"},
},
},
},
{
name: "should return only series for team-b when there is an equals matcher for the team-b tenant",
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchEqual}},
expectedSeriesCount: 2,
expectedLabels: []labels.Labels{
{
{Name: "__tenant_id__", Value: "team-b"},
{Name: "instance", Value: "host1"},
{Name: "tenant-team-b", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-b"},
{Name: "instance", Value: "host2.team-b"},
},
},
},
{
name: "should return one series for each tenant when there is an equals matcher for the host1 instance",
Expand Down Expand Up @@ -516,6 +547,19 @@ func TestMergeQueryable_Select(t *testing.T) {
name: "should return only series for team-b when there is an equals matcher for team-b tenant",
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchEqual}},
expectedSeriesCount: 2,
expectedLabels: []labels.Labels{
{
{Name: "__tenant_id__", Value: "team-b"},
{Name: "instance", Value: "host1"},
{Name: "original___tenant_id__", Value: "original-value"},
{Name: "tenant-team-b", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-b"},
{Name: "instance", Value: "host2.team-b"},
{Name: "original___tenant_id__", Value: "original-value"},
},
},
},
{
name: "should return all series when there is an equals matcher for the original value of __tenant_id__ using the revised tenant label",
Expand Down
Loading