fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

tenant: unexport EnforceTenant (#957)

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

+9 -11
+4
internal/tenant/context.go
··· 27 27 // Log logs the tenant ID to the trace. If tenant logging is enabled, it also 28 28 // logs a stack trace to a pprof profile. 29 29 func Log(ctx context.Context, tr *trace.Trace) { 30 + if !enforceTenant() { 31 + return 32 + } 33 + 30 34 if systemtenant.Is(ctx) { 31 35 tr.LazyPrintf("tenant: system") 32 36 return
+1 -1
internal/tenant/enforcement.go
··· 6 6 "github.com/sourcegraph/zoekt/internal/tenant/internal/enforcement" 7 7 ) 8 8 9 - func EnforceTenant() bool { 9 + func enforceTenant() bool { 10 10 switch enforcement.EnforcementMode.Load() { 11 11 case "strict": 12 12 return true
+1 -1
internal/tenant/query.go
··· 9 9 // HasAccess returns true if the tenant ID in the context matches the 10 10 // given ID. If tenant enforcement is disabled, it always returns true. 11 11 func HasAccess(ctx context.Context, id int) bool { 12 - if !EnforceTenant() { 12 + if !enforceTenant() { 13 13 return true 14 14 } 15 15 if systemtenant.Is(ctx) {
+3 -9
search/eval.go
··· 20 20 tr, ctx := trace.New(ctx, "typeRepoSearcher.Search", "") 21 21 tr.LazyLog(q, true) 22 22 tr.LazyPrintf("opts: %+v", opts) 23 - if tenant.EnforceTenant() { 24 - tenant.Log(ctx, tr) 25 - } 23 + tenant.Log(ctx, tr) 26 24 defer func() { 27 25 if sr != nil { 28 26 tr.LazyPrintf("num files: %d", len(sr.Files)) ··· 47 45 tr, ctx := trace.New(ctx, "typeRepoSearcher.StreamSearch", "") 48 46 tr.LazyLog(q, true) 49 47 tr.LazyPrintf("opts: %+v", opts) 50 - if tenant.EnforceTenant() { 51 - tenant.Log(ctx, tr) 52 - } 48 + tenant.Log(ctx, tr) 53 49 var stats zoekt.Stats 54 50 defer func() { 55 51 tr.LazyPrintf("stats: %+v", stats) ··· 75 71 tr, ctx := trace.New(ctx, "typeRepoSearcher.List", "") 76 72 tr.LazyLog(q, true) 77 73 tr.LazyPrintf("opts: %s", opts) 78 - if tenant.EnforceTenant() { 79 - tenant.Log(ctx, tr) 80 - } 74 + tenant.Log(ctx, tr) 81 75 defer func() { 82 76 if rl != nil { 83 77 tr.LazyPrintf("repos.size=%d reposmap.size=%d crashes=%d stats=%+v", len(rl.Repos), len(rl.ReposMap), rl.Crashes, rl.Stats)