Skip to content

Commit

Permalink
Create logger hierarchy for config and incoming / outgoing loggers (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbotros authored Aug 9, 2024
1 parent 7f9aefa commit c56178e
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions config/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func CreateNewGRPCClient(ctx context.Context, cloudCfg *Cloud, logger logging.Lo
dialOpts = append(dialOpts, rpc.WithInsecure())
}

return rpc.DialDirectGRPC(ctx, u.Host, logger, dialOpts...)
return rpc.DialDirectGRPC(ctx, u.Host, logging.GetOrNewLogger("rdk.networking"), dialOpts...)
}

// CreateNewGRPCClientWithAPIKey creates a new grpc cloud configured to communicate with the robot service
Expand All @@ -765,5 +765,5 @@ func CreateNewGRPCClientWithAPIKey(ctx context.Context, cloudCfg *Cloud,
dialOpts = append(dialOpts, rpc.WithInsecure())
}

return rpc.DialDirectGRPC(ctx, u.Host, logger, dialOpts...)
return rpc.DialDirectGRPC(ctx, u.Host, logging.GetOrNewLogger("rdk.networking"), dialOpts...)
}
2 changes: 1 addition & 1 deletion grpc/shared_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (sc *SharedConn) ResetConn(conn rpc.ClientConn, moduleLogger logging.Logger
// The first call to `ResetConn` happens before anything can access `sc.logger`. So long as
// we never write to the member variable, everything can continue to access this without
// locks.
sc.logger = moduleLogger.Sublogger("conn")
sc.logger = moduleLogger.Sublogger("networking.conn")
}

if sc.resOnTrackCBs == nil {
Expand Down
4 changes: 2 additions & 2 deletions logging/net_appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newNetAppender(config *CloudConfig, conn rpc.ClientConn, sharedConn, startB
cancel: cancel,
remoteWriter: logWriter,
maxQueueSize: defaultMaxQueueSize,
loggerWithoutNet: NewLogger("netlogger"),
loggerWithoutNet: GetOrNewLogger("rdk.networking").Sublogger("netlogger"),
}

nl.SetConn(conn, sharedConn)
Expand Down Expand Up @@ -439,7 +439,7 @@ func CreateNewGRPCClient(ctx context.Context, cloudCfg *CloudConfig) (rpc.Client
dialOpts = append(dialOpts, rpc.WithInsecure())
}

return rpc.DialDirectGRPC(ctx, grpcURL.Host, NewLogger("netlogger"), dialOpts...)
return rpc.DialDirectGRPC(ctx, grpcURL.Host, GetOrNewLogger("rdk.networking.netlogger"), dialOpts...)
}

// A NetAppender must implement a zapcore such that it gets copied when downconverting on
Expand Down
2 changes: 1 addition & 1 deletion module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (m *Module) connectParent(ctx context.Context) error {
// moduleLoggers may be creating the client connection below, so use a
// different logger here to avoid a deadlock where the client connection
// tries to recursively connect to the parent.
clientLogger := logging.NewLogger("module-connection")
clientLogger := logging.NewLogger("networking.module-connection")
clientLogger.SetLevel(m.logger.GetLevel())
// TODO(PRODUCT-343): add session support to modules
rc, err := client.New(ctx, "unix://"+m.parentAddr, clientLogger, client.WithDisableSessions())
Expand Down
10 changes: 9 additions & 1 deletion robot/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,15 @@ func (rc *RobotClient) connectWithLock(ctx context.Context) error {
if err := rc.conn.Close(); err != nil {
return err
}
conn, err := grpc.Dial(ctx, rc.address, rc.logger, rc.dialOptions...)

var dialLogger logging.Logger
if l, ok := logging.LoggerNamed("rdk.networking"); ok {
dialLogger = l
} else {
dialLogger = rc.logger.Sublogger("networking")
}

conn, err := grpc.Dial(ctx, rc.address, dialLogger, rc.dialOptions...)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion robot/impl/local_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ func dialRobotClient(
robotClient, err := client.New(
ctx,
config.Address,
logger,
logger.Sublogger("networking"),
rOpts...,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion robot/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewSessionManager(robot Robot, heartbeatWindow time.Duration) *SessionManag
m := &SessionManager{
robot: robot,
heartbeatWindow: heartbeatWindow,
logger: robot.Logger().Sublogger("session_manager"),
logger: robot.Logger().Sublogger("networking.session_manager"),
sessions: map[uuid.UUID]*session.Session{},
resourceToSession: map[resource.Name]uuid.UUID{},
}
Expand Down
2 changes: 1 addition & 1 deletion robot/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (svc *webService) runWeb(ctx context.Context, options weboptions.Options) (
return err
}

svc.rpcServer, err = rpc.NewServer(svc.logger, rpcOpts...)
svc.rpcServer, err = rpc.NewServer(logging.GetOrNewLogger("rdk.networking"), rpcOpts...)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions robot/web/web_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (svc *webService) makeStreamServer(ctx context.Context) (*StreamServer, err
if len(svc.videoSources) != 0 || len(svc.audioSources) != 0 {
svc.logger.Debug("not starting streams due to no stream config being set")
}
noopServer, err := webstream.NewServer(streams, svc.r, svc.logger)
noopServer, err := webstream.NewServer(streams, svc.r, logging.GetOrNewLogger("rdk.networking"))
return &StreamServer{noopServer, false}, err
}

Expand Down Expand Up @@ -215,7 +215,7 @@ func (svc *webService) makeStreamServer(ctx context.Context) (*StreamServer, err
streamTypes = append(streamTypes, false)
}

streamServer, err := webstream.NewServer(streams, svc.r, svc.logger)
streamServer, err := webstream.NewServer(streams, svc.r, logging.GetOrNewLogger("rdk.networking"))
if err != nil {
return nil, err
}
Expand Down
9 changes: 7 additions & 2 deletions web/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)
logger := logging.NewLogger("")
logging.ReplaceGlobal(logger)
logger = logger.Sublogger("rdk")

// create logging logger here for access later
logger.Sublogger("logging")

// create networking logger here for access later
logger.Sublogger("networking")

config.InitLoggingSettings(logger, argsParsed.Debug)

// Always log the version, return early if the '-version' flag was provided
Expand Down Expand Up @@ -125,7 +130,7 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)

// Read the config from disk and use it to initialize the remote logger.
initialReadCtx, cancel := context.WithTimeout(ctx, time.Second*5)
cfgFromDisk, err := config.ReadLocalConfig(initialReadCtx, argsParsed.ConfigFile, logger)
cfgFromDisk, err := config.ReadLocalConfig(initialReadCtx, argsParsed.ConfigFile, logger.Sublogger("config"))
if err != nil {
cancel()
return err
Expand Down Expand Up @@ -368,7 +373,7 @@ func (s *robotServer) serveWeb(ctx context.Context, cfg *config.Config) (err err
}()

// watch for and deliver changes to the robot
watcher, err := config.NewWatcher(ctx, cfg, s.logger)
watcher, err := config.NewWatcher(ctx, cfg, logging.GetOrNewLogger("rdk.config"))
if err != nil {
cancel()
return err
Expand Down

0 comments on commit c56178e

Please sign in to comment.