From 192ee33f6fc0f07070eeaaa1d34e41746740e64c Mon Sep 17 00:00:00 2001 From: Easwar Swaminathan Date: Mon, 28 Oct 2024 14:58:42 -0700 Subject: [PATCH] multiple: add verbosity checks to logs that use pretty.JSON (#7785) --- balancer/rls/config.go | 5 ++++- balancer/rls/control_channel.go | 4 +++- balancer/weightedtarget/weightedtarget.go | 5 ++++- xds/internal/balancer/clustermanager/clustermanager.go | 5 ++++- xds/internal/balancer/clusterresolver/clusterresolver.go | 5 ++++- xds/internal/balancer/ringhash/ringhash.go | 5 ++++- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/balancer/rls/config.go b/balancer/rls/config.go index 439581c78bc1..ff540aa058b8 100644 --- a/balancer/rls/config.go +++ b/balancer/rls/config.go @@ -143,7 +143,10 @@ type lbConfigJSON struct { // - childPolicyConfigTargetFieldName: // - must be set and non-empty func (rlsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { - logger.Infof("Received JSON service config: %v", pretty.ToJSON(c)) + if logger.V(2) { + logger.Infof("Received JSON service config: %v", pretty.ToJSON(c)) + } + cfgJSON := &lbConfigJSON{} if err := json.Unmarshal(c, cfgJSON); err != nil { return nil, fmt.Errorf("rls: json unmarshal failed for service config %+v: %v", string(c), err) diff --git a/balancer/rls/control_channel.go b/balancer/rls/control_channel.go index 4acc11d90e94..f2ad8bc720e4 100644 --- a/balancer/rls/control_channel.go +++ b/balancer/rls/control_channel.go @@ -209,7 +209,9 @@ func (cc *controlChannel) lookup(reqKeys map[string]string, reason rlspb.RouteLo Reason: reason, StaleHeaderData: staleHeaders, } - cc.logger.Infof("Sending RLS request %+v", pretty.ToJSON(req)) + if cc.logger.V(2) { + cc.logger.Infof("Sending RLS request %+v", pretty.ToJSON(req)) + } ctx, cancel := context.WithTimeout(context.Background(), cc.rpcTimeout) defer cancel() diff --git a/balancer/weightedtarget/weightedtarget.go b/balancer/weightedtarget/weightedtarget.go index dfd1ef26dcb0..c004e112c40a 100644 --- a/balancer/weightedtarget/weightedtarget.go +++ b/balancer/weightedtarget/weightedtarget.go @@ -99,7 +99,10 @@ func LocalityFromResolverState(state resolver.State) string { // creates/deletes sub-balancers and sends them update. addresses are split into // groups based on hierarchy path. func (b *weightedTargetBalancer) UpdateClientConnState(s balancer.ClientConnState) error { - b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + if b.logger.V(2) { + b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + } + newConfig, ok := s.BalancerConfig.(*LBConfig) if !ok { return fmt.Errorf("unexpected balancer config with type: %T", s.BalancerConfig) diff --git a/xds/internal/balancer/clustermanager/clustermanager.go b/xds/internal/balancer/clustermanager/clustermanager.go index e6d751ecbee4..ef5b34ea4451 100644 --- a/xds/internal/balancer/clustermanager/clustermanager.go +++ b/xds/internal/balancer/clustermanager/clustermanager.go @@ -167,11 +167,14 @@ func (b *bal) updateChildren(s balancer.ClientConnState, newConfig *lbConfig) er } func (b *bal) UpdateClientConnState(s balancer.ClientConnState) error { + if b.logger.V(2) { + b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + } + newConfig, ok := s.BalancerConfig.(*lbConfig) if !ok { return fmt.Errorf("unexpected balancer config with type: %T", s.BalancerConfig) } - b.logger.Infof("Update with config %+v, resolver state %+v", pretty.ToJSON(s.BalancerConfig), s.ResolverState) b.stateAggregator.pauseStateUpdates() defer b.stateAggregator.resumeStateUpdates() diff --git a/xds/internal/balancer/clusterresolver/clusterresolver.go b/xds/internal/balancer/clusterresolver/clusterresolver.go index 3f0c54e8f389..3b996989689e 100644 --- a/xds/internal/balancer/clusterresolver/clusterresolver.go +++ b/xds/internal/balancer/clusterresolver/clusterresolver.go @@ -184,7 +184,10 @@ func (b *clusterResolverBalancer) handleClientConnUpdate(update *ccUpdate) { return } - b.logger.Infof("Received new balancer config: %v", pretty.ToJSON(update.state.BalancerConfig)) + if b.logger.V(2) { + b.logger.Infof("Received new balancer config: %v", pretty.ToJSON(update.state.BalancerConfig)) + } + cfg, _ := update.state.BalancerConfig.(*LBConfig) if cfg == nil { b.logger.Warningf("Ignoring unsupported balancer configuration of type: %T", update.state.BalancerConfig) diff --git a/xds/internal/balancer/ringhash/ringhash.go b/xds/internal/balancer/ringhash/ringhash.go index ef054d48aa4e..8c44f19c3b14 100644 --- a/xds/internal/balancer/ringhash/ringhash.go +++ b/xds/internal/balancer/ringhash/ringhash.go @@ -285,7 +285,10 @@ func (b *ringhashBalancer) updateAddresses(addrs []resolver.Address) bool { } func (b *ringhashBalancer) UpdateClientConnState(s balancer.ClientConnState) error { - b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + if b.logger.V(2) { + b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + } + newConfig, ok := s.BalancerConfig.(*LBConfig) if !ok { return fmt.Errorf("unexpected balancer config with type: %T", s.BalancerConfig)