Skip to content

Commit 9e95fce

Browse files
committed
tenant: unexport EnforceTenant
The only place this was called outside of the tenant package was for deciding if we should call tenant.Log. However, we can inline that check and both simplify the tenant exported API as well as how you call tenant.Log. Test Plan: CI
1 parent 95acd6f commit 9e95fce

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

internal/tenant/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func FromContext(ctx context.Context) (*tenanttype.Tenant, error) {
2727
// Log logs the tenant ID to the trace. If tenant logging is enabled, it also
2828
// logs a stack trace to a pprof profile.
2929
func Log(ctx context.Context, tr *trace.Trace) {
30+
if !enforceTenant() {
31+
return
32+
}
33+
3034
if systemtenant.Is(ctx) {
3135
tr.LazyPrintf("tenant: system")
3236
return

internal/tenant/enforcement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/sourcegraph/zoekt/internal/tenant/internal/enforcement"
77
)
88

9-
func EnforceTenant() bool {
9+
func enforceTenant() bool {
1010
switch enforcement.EnforcementMode.Load() {
1111
case "strict":
1212
return true

internal/tenant/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// HasAccess returns true if the tenant ID in the context matches the
1010
// given ID. If tenant enforcement is disabled, it always returns true.
1111
func HasAccess(ctx context.Context, id int) bool {
12-
if !EnforceTenant() {
12+
if !enforceTenant() {
1313
return true
1414
}
1515
if systemtenant.Is(ctx) {

search/eval.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ func (s *typeRepoSearcher) Search(ctx context.Context, q query.Q, opts *zoekt.Se
2020
tr, ctx := trace.New(ctx, "typeRepoSearcher.Search", "")
2121
tr.LazyLog(q, true)
2222
tr.LazyPrintf("opts: %+v", opts)
23-
if tenant.EnforceTenant() {
24-
tenant.Log(ctx, tr)
25-
}
23+
tenant.Log(ctx, tr)
2624
defer func() {
2725
if sr != nil {
2826
tr.LazyPrintf("num files: %d", len(sr.Files))
@@ -47,9 +45,7 @@ func (s *typeRepoSearcher) StreamSearch(ctx context.Context, q query.Q, opts *zo
4745
tr, ctx := trace.New(ctx, "typeRepoSearcher.StreamSearch", "")
4846
tr.LazyLog(q, true)
4947
tr.LazyPrintf("opts: %+v", opts)
50-
if tenant.EnforceTenant() {
51-
tenant.Log(ctx, tr)
52-
}
48+
tenant.Log(ctx, tr)
5349
var stats zoekt.Stats
5450
defer func() {
5551
tr.LazyPrintf("stats: %+v", stats)
@@ -75,9 +71,7 @@ func (s *typeRepoSearcher) List(ctx context.Context, q query.Q, opts *zoekt.List
7571
tr, ctx := trace.New(ctx, "typeRepoSearcher.List", "")
7672
tr.LazyLog(q, true)
7773
tr.LazyPrintf("opts: %s", opts)
78-
if tenant.EnforceTenant() {
79-
tenant.Log(ctx, tr)
80-
}
74+
tenant.Log(ctx, tr)
8175
defer func() {
8276
if rl != nil {
8377
tr.LazyPrintf("repos.size=%d reposmap.size=%d crashes=%d stats=%+v", len(rl.Repos), len(rl.ReposMap), rl.Crashes, rl.Stats)

0 commit comments

Comments
 (0)