x/ref: make use of ctx arg to Lookup.
Change-Id: Ia6649ef0d5469a22843728fc5e350e8c891f2e72
diff --git a/runtime/factories/roaming/roaming.go b/runtime/factories/roaming/roaming.go
index 9dd781e..f42d786 100644
--- a/runtime/factories/roaming/roaming.go
+++ b/runtime/factories/roaming/roaming.go
@@ -62,7 +62,7 @@
Addrs: rpc.ListenAddrs(lf.Addrs),
Proxy: lf.ListenProxy,
}
- reservedDispatcher := debuglib.NewDispatcher(logger.Manager(logger.Global()).LogDir, securityflag.NewAuthorizerOrDie())
+ reservedDispatcher := debuglib.NewDispatcher(securityflag.NewAuthorizerOrDie())
ac := appcycle.New()
diff --git a/runtime/factories/static/static.go b/runtime/factories/static/static.go
index c92732b..76ab113 100644
--- a/runtime/factories/static/static.go
+++ b/runtime/factories/static/static.go
@@ -44,7 +44,7 @@
Addrs: rpc.ListenAddrs(lf.Addrs),
Proxy: lf.ListenProxy,
}
- reservedDispatcher := debuglib.NewDispatcher(logger.Manager(logger.Global()).LogDir, securityflag.NewAuthorizerOrDie())
+ reservedDispatcher := debuglib.NewDispatcher(securityflag.NewAuthorizerOrDie())
ac := appcycle.New()
diff --git a/runtime/internal/rpc/debug_test.go b/runtime/internal/rpc/debug_test.go
index 98dac91..26aabf6 100644
--- a/runtime/internal/rpc/debug_test.go
+++ b/runtime/internal/rpc/debug_test.go
@@ -16,7 +16,6 @@
"v.io/v23/options"
"v.io/v23/rpc"
- "v.io/x/ref/internal/logger"
"v.io/x/ref/lib/stats"
"v.io/x/ref/runtime/internal/rpc/stream/manager"
tnaming "v.io/x/ref/runtime/internal/testing/mocks/naming"
@@ -39,7 +38,7 @@
pclient.AddToRoots(bclient) // Client recognizes "server" as a root of blessings.
pclient.BlessingStore().Set(bclient, "server") // Client presents bclient to server
- debugDisp := debuglib.NewDispatcher(logger.Manager(ctx).LogDir, nil)
+ debugDisp := debuglib.NewDispatcher(nil)
sm := manager.InternalNew(ctx, naming.FixedRoutingID(0x555555555))
defer sm.Shutdown()
diff --git a/runtime/internal/rt/runtime_test.go b/runtime/internal/rt/runtime_test.go
index 27ae0d9..44cb603 100644
--- a/runtime/internal/rt/runtime_test.go
+++ b/runtime/internal/rt/runtime_test.go
@@ -12,7 +12,6 @@
"v.io/v23/naming"
"v.io/v23/options"
- "v.io/x/ref/internal/logger"
"v.io/x/ref/lib/flags"
"v.io/x/ref/runtime/internal/rt"
"v.io/x/ref/services/debug/debuglib"
@@ -143,7 +142,7 @@
defer shutdown()
oldDebugDisp := r.GetReservedNameDispatcher(ctx)
- newDebugDisp := debuglib.NewDispatcher(logger.Manager(ctx).LogDir, nil)
+ newDebugDisp := debuglib.NewDispatcher(nil)
nctx := r.WithReservedNameDispatcher(ctx, newDebugDisp)
debugDisp := r.GetReservedNameDispatcher(nctx)
diff --git a/services/debug/debuglib/dispatcher.go b/services/debug/debuglib/dispatcher.go
index 81c09b5..7c3557a 100644
--- a/services/debug/debuglib/dispatcher.go
+++ b/services/debug/debuglib/dispatcher.go
@@ -12,6 +12,7 @@
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/security"
+ "v.io/x/ref/internal/logger"
"v.io/x/ref/services/internal/logreaderlib"
"v.io/x/ref/services/internal/pproflib"
"v.io/x/ref/services/internal/statslib"
@@ -20,20 +21,19 @@
// dispatcher holds the state of the debug dispatcher.
type dispatcher struct {
- logsDirFunc func() string // The function returns the root of the logs directory.
- auth security.Authorizer
+ auth security.Authorizer
}
var _ rpc.Dispatcher = (*dispatcher)(nil)
-func NewDispatcher(logsDirFunc func() string, authorizer security.Authorizer) rpc.Dispatcher {
- return &dispatcher{logsDirFunc, authorizer}
+func NewDispatcher(authorizer security.Authorizer) rpc.Dispatcher {
+ return &dispatcher{authorizer}
}
// The first part of the names of the objects served by this dispatcher.
var rootName = "__debug"
-func (d *dispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
+func (d *dispatcher) Lookup(ctx *context.T, suffix string) (interface{}, security.Authorizer, error) {
if suffix == "" {
return rpc.ChildrenGlobberInvoker(rootName), d.auth, nil
}
@@ -54,7 +54,7 @@
}
switch parts[0] {
case "logs":
- return logreaderlib.NewLogFileService(d.logsDirFunc(), suffix), d.auth, nil
+ return logreaderlib.NewLogFileService(logger.Manager(ctx).LogDir(), suffix), d.auth, nil
case "pprof":
return pproflib.NewPProfService(), d.auth, nil
case "stats":
diff --git a/services/debug/debuglib/dispatcher_test.go b/services/debug/debuglib/dispatcher_test.go
index 441f20a..1dcd3b6 100644
--- a/services/debug/debuglib/dispatcher_test.go
+++ b/services/debug/debuglib/dispatcher_test.go
@@ -24,7 +24,7 @@
"v.io/v23/vdl"
"v.io/v23/verror"
"v.io/v23/vtrace"
-
+ "v.io/x/lib/vlog"
libstats "v.io/x/ref/lib/stats"
"v.io/x/ref/lib/xrpc"
_ "v.io/x/ref/runtime/factories/generic"
@@ -54,7 +54,12 @@
t.Fatalf("ioutil.WriteFile failed: %v", err)
}
- disp := NewDispatcher(func() string { return workdir }, nil)
+ // Use logger configured with the directory that we want to use for this test.
+ testLogger := vlog.NewLogger("TestDebugServer")
+ testLogger.Configure(vlog.LogDir(workdir))
+ ctx = context.WithLogger(ctx, testLogger)
+
+ disp := NewDispatcher(nil)
server, err := xrpc.NewDispatchingServer(ctx, "", disp)
if err != nil {
t.Fatalf("failed to start debug server: %v", err)
diff --git a/services/device/deviced/internal/impl/dispatcher.go b/services/device/deviced/internal/impl/dispatcher.go
index ddf37f5..975b641 100644
--- a/services/device/deviced/internal/impl/dispatcher.go
+++ b/services/device/deviced/internal/impl/dispatcher.go
@@ -60,9 +60,6 @@
permsStore *pathperms.PathStore
// Namespace
mtAddress string // The address of the local mounttable.
- // TODO(cnicolaou): remove this when Lookup takes a context.T parameter directly,
- // see v.io/i/572.
- ctx *context.T
}
var _ rpc.Dispatcher = (*dispatcher)(nil)
@@ -131,7 +128,6 @@
uat: uat,
permsStore: permStore,
mtAddress: mtAddress,
- ctx: ctx,
}
// If we're in 'security agent mode', set up the key manager agent.
@@ -166,25 +162,24 @@
// Logging invoker that logs any error messages before returning.
func newLoggingInvoker(ctx *context.T, obj interface{}) (rpc.Invoker, error) {
if invoker, ok := obj.(rpc.Invoker); ok {
- return &loggingInvoker{invoker: invoker, ctx: ctx}, nil
+ return &loggingInvoker{invoker: invoker}, nil
}
invoker, err := rpc.ReflectInvoker(obj)
if err != nil {
ctx.Errorf("rpc.ReflectInvoker returned error: %v", err)
return nil, err
}
- return &loggingInvoker{invoker: invoker, ctx: ctx}, nil
+ return &loggingInvoker{invoker: invoker}, nil
}
type loggingInvoker struct {
invoker rpc.Invoker
- ctx *context.T
}
func (l *loggingInvoker) Prepare(ctx *context.T, method string, numArgs int) (argptrs []interface{}, tags []*vdl.Value, err error) {
argptrs, tags, err = l.invoker.Prepare(ctx, method, numArgs)
if err != nil {
- l.ctx.Errorf("Prepare(%s %d) returned error: %v", method, numArgs, err)
+ ctx.Errorf("Prepare(%s %d) returned error: %v", method, numArgs, err)
}
return
}
@@ -218,12 +213,12 @@
}
// DISPATCHER INTERFACE IMPLEMENTATION
-func (d *dispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
+func (d *dispatcher) Lookup(ctx *context.T, suffix string) (interface{}, security.Authorizer, error) {
invoker, auth, err := d.internalLookup(suffix)
if err != nil {
return nil, nil, err
}
- loggingInvoker, err := newLoggingInvoker(d.ctx, invoker)
+ loggingInvoker, err := newLoggingInvoker(ctx, invoker)
if err != nil {
return nil, nil, err
}
diff --git a/services/device/deviced/internal/impl/proxy_invoker_test.go b/services/device/deviced/internal/impl/proxy_invoker_test.go
index c39c410..4b9a16c 100644
--- a/services/device/deviced/internal/impl/proxy_invoker_test.go
+++ b/services/device/deviced/internal/impl/proxy_invoker_test.go
@@ -33,7 +33,6 @@
// server2 proxies requests to <suffix> to server1/__debug/stats/<suffix>
disp := &proxyDispatcher{
- ctx: ctx,
remote: naming.JoinAddressName(server1.Status().Endpoints[0].String(), "__debug/stats"),
desc: stats.StatsServer(nil).Describe__(),
}
@@ -69,12 +68,11 @@
func (*dummy) Method(*context.T, rpc.ServerCall) error { return nil }
type proxyDispatcher struct {
- ctx *context.T
remote string
desc []rpc.InterfaceDesc
}
-func (d *proxyDispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
- d.ctx.Infof("LOOKUP(%s): remote .... %s", suffix, d.remote)
+func (d *proxyDispatcher) Lookup(ctx *context.T, suffix string) (interface{}, security.Authorizer, error) {
+ ctx.Infof("LOOKUP(%s): remote .... %s", suffix, d.remote)
return newProxyInvoker(naming.Join(d.remote, suffix), access.Debug, d.desc), nil, nil
}
diff --git a/services/device/deviced/internal/starter/starter.go b/services/device/deviced/internal/starter/starter.go
index c6c972a..511998d 100644
--- a/services/device/deviced/internal/starter/starter.go
+++ b/services/device/deviced/internal/starter/starter.go
@@ -20,7 +20,6 @@
"v.io/v23/rpc"
"v.io/v23/security"
"v.io/v23/verror"
- "v.io/x/ref/internal/logger"
"v.io/x/ref/lib/xrpc"
"v.io/x/ref/runtime/factories/roaming"
"v.io/x/ref/services/debug/debuglib"
@@ -223,7 +222,7 @@
return nil, err
}
- debugDisp := debuglib.NewDispatcher(logger.Manager(ctx).LogDir, debugAuth)
+ debugDisp := debuglib.NewDispatcher(debugAuth)
ctx = v23.WithReservedNameDispatcher(ctx, debugDisp)
diff --git a/services/mounttable/mounttablelib/mounttable.go b/services/mounttable/mounttablelib/mounttable.go
index 303fa8c..7dbb898 100644
--- a/services/mounttable/mounttablelib/mounttable.go
+++ b/services/mounttable/mounttablelib/mounttable.go
@@ -60,7 +60,6 @@
// mountTable represents a namespace. One exists per server instance.
type mountTable struct {
sync.Mutex
- ctx *context.T
root *node
superUsers access.AccessList
persisting bool
@@ -115,7 +114,6 @@
// statsPrefix is the prefix for for exported statistics objects.
func NewMountTableDispatcher(ctx *context.T, permsFile, persistDir, statsPrefix string) (rpc.Dispatcher, error) {
mt := &mountTable{
- ctx: ctx,
root: new(node),
nodeCounter: stats.NewInteger(naming.Join(statsPrefix, "num-nodes")),
serverCounter: stats.NewInteger(naming.Join(statsPrefix, "num-mounted-servers")),
@@ -178,7 +176,7 @@
// Lookup implements rpc.Dispatcher.Lookup.
func (mt *mountTable) Lookup(ctx *context.T, name string) (interface{}, security.Authorizer, error) {
- mt.ctx.VI(2).Infof("*********************Lookup %s", name)
+ ctx.VI(2).Infof("*********************Lookup %s", name)
ms := &mountContext{
name: name,
mt: mt,
diff --git a/services/mounttable/mounttablelib/mounttable_test.go b/services/mounttable/mounttablelib/mounttable_test.go
index 9afb038..e54e977 100644
--- a/services/mounttable/mounttablelib/mounttable_test.go
+++ b/services/mounttable/mounttablelib/mounttable_test.go
@@ -26,7 +26,6 @@
"v.io/v23/services/stats"
"v.io/v23/vdl"
- "v.io/x/ref/internal/logger"
libstats "v.io/x/ref/lib/stats"
"v.io/x/ref/lib/xrpc"
"v.io/x/ref/services/debug/debuglib"
@@ -187,7 +186,7 @@
}
func newMT(t *testing.T, permsFile, persistDir, statsDir string, rootCtx *context.T) (func() error, string) {
- reservedDisp := debuglib.NewDispatcher(logger.Manager(logger.Global()).LogDir, nil)
+ reservedDisp := debuglib.NewDispatcher(nil)
ctx := v23.WithReservedNameDispatcher(rootCtx, reservedDisp)
// Add mount table service.
diff --git a/services/wspr/internal/rpc/server/dispatcher.go b/services/wspr/internal/rpc/server/dispatcher.go
index afdd2fa..03a974d 100644
--- a/services/wspr/internal/rpc/server/dispatcher.go
+++ b/services/wspr/internal/rpc/server/dispatcher.go
@@ -71,12 +71,12 @@
}
// Lookup implements dispatcher interface Lookup.
-func (d *dispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
+func (d *dispatcher) Lookup(ctx *context.T, suffix string) (interface{}, security.Authorizer, error) {
// If the server has been closed, we immediately return a retryable error.
d.mu.Lock()
if d.closed {
d.mu.Unlock()
- return nil, nil, NewErrServerStopped(nil)
+ return nil, nil, NewErrServerStopped(ctx)
}
flow := d.flowFactory.createFlow()
ch := make(chan LookupReply, 1)
@@ -88,7 +88,7 @@
Suffix: suffix,
}
if err := flow.Writer.Send(lib.ResponseDispatcherLookup, message); err != nil {
- verr := verror.Convert(verror.ErrInternal, nil, err).(verror.E)
+ verr := verror.Convert(verror.ErrInternal, ctx, err).(verror.E)
ch <- LookupReply{Err: &verr}
}
reply := <-ch
@@ -103,7 +103,7 @@
return nil, nil, reply.Err
}
if reply.Handle < 0 {
- return nil, nil, verror.New(verror.ErrNoExist, nil, "Dispatcher", suffix)
+ return nil, nil, verror.New(verror.ErrNoExist, ctx, "Dispatcher", suffix)
}
invoker, err := d.invokerFactory.createInvoker(reply.Handle, reply.Signature, reply.HasGlobber)