-
Notifications
You must be signed in to change notification settings - Fork 86
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
tenant: introduce systemtenant #863
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,22 @@ | ||
// Package systemtenant exports UnsafeCtx which allows to access shards across | ||
// all tenants. This must only be used for tasks that are not request specific. | ||
package systemtenant | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type contextKey int | ||
|
||
const systemTenantKey contextKey = iota | ||
|
||
// UnsafeCtx is a context that allows queries across all tenants. Don't use this | ||
// for user requests. | ||
var UnsafeCtx = context.WithValue(context.Background(), systemTenantKey, systemTenantKey) | ||
|
||
// Is returns true if the context has been marked to allow queries across all | ||
// tenants. | ||
func Is(ctx context.Context) bool { | ||
_, ok := ctx.Value(systemTenantKey).(contextKey) | ||
return ok | ||
} |
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,15 @@ | ||
package systemtenant | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSystemtenantRoundtrip(t *testing.T) { | ||
if Is(context.Background()) { | ||
t.Fatal() | ||
} | ||
require.True(t, Is(UnsafeCtx)) | ||
} |
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
Oops, something went wrong.
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.
Would there be a way to bypass
List
and load the repo metadata directly? So this just obviously becomes a low-level, privileged operation. This would introducingsystemtenant
just for this single privileged call. Or maybe it's not possible to refactor things to support this 🤔I'm not an expert on this code and totally lack context, so just ignore me if this not helpful :)
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.
My initial thoughts was around this, but I couldn't think of a nice way. EG we want to take into account tombstones/etc and anything else we may add to List in the future. So using List feels like the cleanest approach.