Skip to content
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

Create logger hierarchy for config and incoming / outgoing loggers #4240

Conversation

danielbotros
Copy link
Contributor

@danielbotros danielbotros commented Jul 29, 2024

Description

RSDK-8084: Add config sublogger for all config related log lines

  • This sublogger will allow users to configure log lines around config processing and watching.

RSDK-8091: Create and organize outgoing network logger and subloggers

  • This sublogger will allow users to configure log lines related to outgoing network events, such as dialing GRPC connections

RSDK-8092: Create and organize incoming network logger and subloggers

  • This sublogger will allow users to configure log lines related to incoming network events, such as sessions and signaling. NOTE: There exists no loggers for grpc_requests, so that node currently does not exist.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 29, 2024
@danielbotros danielbotros marked this pull request as draft July 30, 2024 17:32
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 30, 2024
@@ -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("network_outgoing.conn")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, this is where sc.logger gets initialized. I think it is valuable to keep using the moduleLogger for the module logger name prefix, but since this logger deals with outgoing network connections, we want to be able to configure this using the network_outgoing string as well. This deviates from the logging.GetOrNewLogger("rdk.network_outgoing") pattern slightly in order to keep the module name and still be configurable using e.g. *.network_outgoing.*. I am open to suggestions or reverting this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling this out. So, logs from the shared conn to a module from the module manager will have the logger name: rdk.modmanager.[modulename].network_outgoing.conn? I think that's fine. I can't really think of a better option: rdk.network_outgoing.modmanager.module.conn would also be slightly inconvenient, as if a user tried to set rdk.modmanager.*, they'd miss this logger. Also tagging @dgottlieb for visibility on our changes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, I also agree this is probably the best we can do for now

@@ -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.network_outgoing.netlogger"), dialOpts...)
Copy link
Contributor Author

@danielbotros danielbotros Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logger is guaranteed to exist from the diff above, but this was the most straightforward way to retrieve it.

Comment on lines 152 to 158
func GetOrNewLogger(name string) (logger Logger) {
logger, ok := globalLoggerRegistry.loggerNamed(name)
if !ok {
return NewLogger(name)
}
return logger
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a clear natural place to initialize a e.g. rdk.network_outgoing logger so this helper lets us safely retrieve and use the same logger object globally without fear of overwriting a map entry to a new logger with the same name.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 30, 2024
@danielbotros danielbotros marked this pull request as ready for review July 30, 2024 19:55
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jul 31, 2024
@danielbotros danielbotros changed the title RSDK-8084: Add config sublogger for all config related log lines Create logger hierarchy for config and incoming / outgoing loggers Jul 31, 2024
module/module.go Outdated
@@ -236,7 +236,7 @@ func NewModule(ctx context.Context, address string, logger logging.Logger) (*Mod
}

// attempt to configure PeerConnection
pcReady, pcClosed, err := rpc.ConfigureForRenegotiation(pc, rpc.PeerRoleServer, logger)
pcReady, pcClosed, err := rpc.ConfigureForRenegotiation(pc, rpc.PeerRoleServer, logging.GetOrNewLogger("rdk.network_outgoing"))
Copy link
Contributor Author

@danielbotros danielbotros Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these are a bit dubious as to whether or not they are incoming or outgoing network events in my opinion. we may want to consider renaming / reorganizing things but this PR tries to follow the topology as close as possible to the scope doc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we put this logger under rdk.network_outgoing? From what I can tell it's a logger used as part of connection establishment from a Go module back to the RDK. I think we should continue to use logger; that's the module's author's logger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed off PR, we are changing all network_outgoing / network_incoming to networking

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 1, 2024
Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@danielbotros danielbotros force-pushed the RSDK-8084-create-sublogger-for-config-logs branch from 7def9f1 to 92f30ea Compare August 6, 2024 20:58
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 6, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Aug 6, 2024
@benjirewis benjirewis removed the request for review from dgottlieb August 9, 2024 16:07
@danielbotros danielbotros merged commit c56178e into viamrobotics:main Aug 9, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants