Skip to content

Commit

Permalink
multiple: add verbosity checks to logs that use pretty.JSON (#7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars authored Oct 28, 2024
1 parent e7435d6 commit 192ee33
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion balancer/rls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion balancer/rls/control_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion balancer/weightedtarget/weightedtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion xds/internal/balancer/clustermanager/clustermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion xds/internal/balancer/clusterresolver/clusterresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion xds/internal/balancer/ringhash/ringhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 192ee33

Please sign in to comment.