From ea492f555f677ec48b2429463ca2e889571a4d78 Mon Sep 17 00:00:00 2001 From: Arvind Bright Date: Fri, 30 Jun 2023 13:10:52 -0700 Subject: [PATCH] xdsclient: indicate authority serverURI in authority + transport logs (#6425) --- xds/internal/xdsclient/clientimpl_authority.go | 3 ++- xds/internal/xdsclient/logging.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xds/internal/xdsclient/clientimpl_authority.go b/xds/internal/xdsclient/clientimpl_authority.go index 2531b39472f5..925566cf44f3 100644 --- a/xds/internal/xdsclient/clientimpl_authority.go +++ b/xds/internal/xdsclient/clientimpl_authority.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" + "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/grpc/xds/internal/xdsclient/xdsresource" ) @@ -109,7 +110,7 @@ func (c *clientImpl) newAuthorityLocked(config *bootstrap.ServerConfig) (_ *auth serializer: c.serializer, resourceTypeGetter: c.resourceTypes.get, watchExpiryTimeout: c.watchExpiryTimeout, - logger: c.logger, + logger: grpclog.NewPrefixLogger(logger, authorityPrefix(c, config.ServerURI)), }) if err != nil { return nil, fmt.Errorf("creating new authority for config %q: %v", config.String(), err) diff --git a/xds/internal/xdsclient/logging.go b/xds/internal/xdsclient/logging.go index e28ea0d04103..2269cb293da9 100644 --- a/xds/internal/xdsclient/logging.go +++ b/xds/internal/xdsclient/logging.go @@ -25,10 +25,16 @@ import ( internalgrpclog "google.golang.org/grpc/internal/grpclog" ) -const prefix = "[xds-client %p] " - var logger = grpclog.Component("xds") func prefixLogger(p *clientImpl) *internalgrpclog.PrefixLogger { - return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) + return internalgrpclog.NewPrefixLogger(logger, clientPrefix(p)) +} + +func clientPrefix(p *clientImpl) string { + return fmt.Sprintf("[xds-client %p] ", p) +} + +func authorityPrefix(p *clientImpl, serverURI string) string { + return fmt.Sprintf("%s[%s] ", clientPrefix(p), serverURI) }