-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Loki: Fix multitenant querying #7708
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
09c71b9
Use longest timeout across all tenants.
DylanGuedes b0a4966
Implement multitenant check tests.
DylanGuedes ce855f1
Add missing CHANGELOG entry.
DylanGuedes 79e7398
Add test that checks multitenant behavior.
DylanGuedes ba2529d
Simplify timeout assigning.
DylanGuedes c64a892
Use tenants instead of tenantIDS for consistency.
DylanGuedes 4b77032
Join tenants string when logging message.
DylanGuedes d381fbd
Use smallest/shortest limits instead.
DylanGuedes cd034e3
Use validation.SmallestValue* functions instead.
DylanGuedes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/grafana/loki/integration/client" | ||
"github.com/grafana/loki/integration/cluster" | ||
) | ||
|
||
func TestMultiTenantQuery(t *testing.T) { | ||
clu := cluster.New() | ||
defer func() { | ||
assert.NoError(t, clu.Cleanup()) | ||
}() | ||
|
||
var ( | ||
tAll = clu.AddComponent( | ||
"all", | ||
"-target=all", | ||
) | ||
) | ||
|
||
require.NoError(t, clu.Run()) | ||
|
||
cliTenant1 := client.New("org1", "", tAll.HTTPURL()) | ||
cliTenant2 := client.New("org2", "", tAll.HTTPURL()) | ||
cliMultitenant := client.New("org1|org2", "", tAll.HTTPURL()) | ||
|
||
// ingest log lines for tenant 1 and tenant 2. | ||
require.NoError(t, cliTenant1.PushLogLineWithTimestamp("lineA", cliTenant1.Now.Add(-45*time.Minute), map[string]string{"job": "fake1"})) | ||
require.NoError(t, cliTenant2.PushLogLineWithTimestamp("lineB", cliTenant2.Now.Add(-45*time.Minute), map[string]string{"job": "fake2"})) | ||
|
||
// check that tenant1 only have access to log line A. | ||
matchLines(t, cliTenant1, `{job="fake2"}`, []string{}) | ||
matchLines(t, cliTenant1, `{job=~"fake.*"}`, []string{"lineA"}) | ||
matchLines(t, cliTenant1, `{job="fake1"}`, []string{"lineA"}) | ||
|
||
// check that tenant2 only have access to log line B. | ||
matchLines(t, cliTenant2, `{job="fake1"}`, []string{}) | ||
matchLines(t, cliTenant2, `{job=~"fake.*"}`, []string{"lineB"}) | ||
matchLines(t, cliTenant2, `{job="fake2"}`, []string{"lineB"}) | ||
|
||
// check that multitenant has access to all log lines on same query. | ||
matchLines(t, cliMultitenant, `{job=~"fake.*"}`, []string{"lineA", "lineB"}) | ||
matchLines(t, cliMultitenant, `{job="fake1"}`, []string{"lineA"}) | ||
matchLines(t, cliMultitenant, `{job="fake2"}`, []string{"lineB"}) | ||
matchLines(t, cliMultitenant, `{job="fake3"}`, []string{}) | ||
} | ||
|
||
func matchLines(t *testing.T, client *client.Client, labels string, expectedLines []string) { | ||
resp, err := client.RunRangeQuery(context.Background(), labels) | ||
require.NoError(t, err) | ||
|
||
var lines []string | ||
for _, stream := range resp.Data.Stream { | ||
for _, val := range stream.Values { | ||
lines = append(lines, val[1]) | ||
} | ||
} | ||
require.ElementsMatch(t, expectedLines, lines) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test!