mirror of https://github.com/grpc/grpc-go.git
grpclog: remove Debugf method to avoid unnecessary evaluation (#7330)
This commit is contained in:
parent
c8568c99b8
commit
8c80220523
|
|
@ -61,24 +61,6 @@ func (pl *PrefixLogger) Errorf(format string, args ...any) {
|
||||||
ErrorDepth(1, fmt.Sprintf(format, args...))
|
ErrorDepth(1, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf does info logging at verbose level 2.
|
|
||||||
func (pl *PrefixLogger) Debugf(format string, args ...any) {
|
|
||||||
// TODO(6044): Refactor interfaces LoggerV2 and DepthLogger, and maybe
|
|
||||||
// rewrite PrefixLogger a little to ensure that we don't use the global
|
|
||||||
// `Logger` here, and instead use the `logger` field.
|
|
||||||
if !Logger.V(2) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pl != nil {
|
|
||||||
// Handle nil, so the tests can pass in a nil logger.
|
|
||||||
format = pl.prefix + format
|
|
||||||
pl.logger.InfoDepth(1, fmt.Sprintf(format, args...))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
InfoDepth(1, fmt.Sprintf(format, args...))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// V reports whether verbosity level l is at least the requested verbose level.
|
// V reports whether verbosity level l is at least the requested verbose level.
|
||||||
func (pl *PrefixLogger) V(l int) bool {
|
func (pl *PrefixLogger) V(l int) bool {
|
||||||
// TODO(6044): Refactor interfaces LoggerV2 and DepthLogger, and maybe
|
// TODO(6044): Refactor interfaces LoggerV2 and DepthLogger, and maybe
|
||||||
|
|
|
||||||
|
|
@ -509,7 +509,9 @@ func bootstrapConfigFromEnvVariable() ([]byte, error) {
|
||||||
fContent := envconfig.XDSBootstrapFileContent
|
fContent := envconfig.XDSBootstrapFileContent
|
||||||
|
|
||||||
if fName != "" {
|
if fName != "" {
|
||||||
logger.Debugf("Using bootstrap file with name %q", fName)
|
if logger.V(2) {
|
||||||
|
logger.Infof("Using bootstrap file with name %q", fName)
|
||||||
|
}
|
||||||
return bootstrapFileReadFunc(fName)
|
return bootstrapFileReadFunc(fName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,9 @@ var (
|
||||||
// Caller must hold b.mu.
|
// Caller must hold b.mu.
|
||||||
func (b *priorityBalancer) syncPriority(childUpdating string) {
|
func (b *priorityBalancer) syncPriority(childUpdating string) {
|
||||||
if b.inhibitPickerUpdates {
|
if b.inhibitPickerUpdates {
|
||||||
b.logger.Debugf("Skipping update from child policy %q", childUpdating)
|
if b.logger.V(2) {
|
||||||
|
b.logger.Infof("Skipping update from child policy %q", childUpdating)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for p, name := range b.priorities {
|
for p, name := range b.priorities {
|
||||||
|
|
@ -99,12 +101,16 @@ func (b *priorityBalancer) syncPriority(childUpdating string) {
|
||||||
(child.state.ConnectivityState == connectivity.Connecting && child.initTimer != nil) ||
|
(child.state.ConnectivityState == connectivity.Connecting && child.initTimer != nil) ||
|
||||||
p == len(b.priorities)-1 {
|
p == len(b.priorities)-1 {
|
||||||
if b.childInUse != child.name || child.name == childUpdating {
|
if b.childInUse != child.name || child.name == childUpdating {
|
||||||
b.logger.Debugf("childInUse, childUpdating: %q, %q", b.childInUse, child.name)
|
if b.logger.V(2) {
|
||||||
|
b.logger.Infof("childInUse, childUpdating: %q, %q", b.childInUse, child.name)
|
||||||
|
}
|
||||||
// If we switch children or the child in use just updated its
|
// If we switch children or the child in use just updated its
|
||||||
// picker, push the child's picker to the parent.
|
// picker, push the child's picker to the parent.
|
||||||
b.cc.UpdateState(child.state)
|
b.cc.UpdateState(child.state)
|
||||||
}
|
}
|
||||||
b.logger.Debugf("Switching to (%q, %v) in syncPriority", child.name, p)
|
if b.logger.V(2) {
|
||||||
|
b.logger.Infof("Switching to (%q, %v) in syncPriority", child.name, p)
|
||||||
|
}
|
||||||
b.switchToChild(child, p)
|
b.switchToChild(child, p)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,15 @@ type ringEntry struct {
|
||||||
//
|
//
|
||||||
// Must be called with a non-empty subConns map.
|
// Must be called with a non-empty subConns map.
|
||||||
func newRing(subConns *resolver.AddressMap, minRingSize, maxRingSize uint64, logger *grpclog.PrefixLogger) *ring {
|
func newRing(subConns *resolver.AddressMap, minRingSize, maxRingSize uint64, logger *grpclog.PrefixLogger) *ring {
|
||||||
logger.Debugf("newRing: number of subConns is %d, minRingSize is %d, maxRingSize is %d", subConns.Len(), minRingSize, maxRingSize)
|
if logger.V(2) {
|
||||||
|
logger.Infof("newRing: number of subConns is %d, minRingSize is %d, maxRingSize is %d", subConns.Len(), minRingSize, maxRingSize)
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/envoyproxy/envoy/blob/765c970f06a4c962961a0e03a467e165b276d50f/source/common/upstream/ring_hash_lb.cc#L114
|
// https://github.com/envoyproxy/envoy/blob/765c970f06a4c962961a0e03a467e165b276d50f/source/common/upstream/ring_hash_lb.cc#L114
|
||||||
normalizedWeights, minWeight := normalizeWeights(subConns)
|
normalizedWeights, minWeight := normalizeWeights(subConns)
|
||||||
logger.Debugf("newRing: normalized subConn weights is %v", normalizedWeights)
|
if logger.V(2) {
|
||||||
|
logger.Infof("newRing: normalized subConn weights is %v", normalizedWeights)
|
||||||
|
}
|
||||||
|
|
||||||
// Normalized weights for {3,3,4} is {0.3,0.3,0.4}.
|
// Normalized weights for {3,3,4} is {0.3,0.3,0.4}.
|
||||||
|
|
||||||
|
|
@ -82,7 +86,9 @@ func newRing(subConns *resolver.AddressMap, minRingSize, maxRingSize uint64, log
|
||||||
scale := math.Min(math.Ceil(minWeight*float64(minRingSize))/minWeight, float64(maxRingSize))
|
scale := math.Min(math.Ceil(minWeight*float64(minRingSize))/minWeight, float64(maxRingSize))
|
||||||
ringSize := math.Ceil(scale)
|
ringSize := math.Ceil(scale)
|
||||||
items := make([]*ringEntry, 0, int(ringSize))
|
items := make([]*ringEntry, 0, int(ringSize))
|
||||||
logger.Debugf("newRing: creating new ring of size %v", ringSize)
|
if logger.V(2) {
|
||||||
|
logger.Infof("newRing: creating new ring of size %v", ringSize)
|
||||||
|
}
|
||||||
|
|
||||||
// For each entry, scale*weight nodes are generated in the ring.
|
// For each entry, scale*weight nodes are generated in the ring.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,9 @@ func (a *authority) updateResourceStateAndScheduleCallbacks(rType xdsresource.Ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sync cache.
|
// Sync cache.
|
||||||
a.logger.Debugf("Resource type %q with name %q added to cache", rType.TypeName(), name)
|
if a.logger.V(2) {
|
||||||
|
a.logger.Infof("Resource type %q with name %q added to cache", rType.TypeName(), name)
|
||||||
|
}
|
||||||
state.cache = uErr.resource
|
state.cache = uErr.resource
|
||||||
// Set status to ACK, and clear error state. The metadata might be a
|
// Set status to ACK, and clear error state. The metadata might be a
|
||||||
// NACK metadata because some other resources in the same response
|
// NACK metadata because some other resources in the same response
|
||||||
|
|
@ -454,7 +456,9 @@ func (a *authority) close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *authority) watchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) func() {
|
func (a *authority) watchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) func() {
|
||||||
a.logger.Debugf("New watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
if a.logger.V(2) {
|
||||||
|
a.logger.Infof("New watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
||||||
|
}
|
||||||
a.resourcesMu.Lock()
|
a.resourcesMu.Lock()
|
||||||
defer a.resourcesMu.Unlock()
|
defer a.resourcesMu.Unlock()
|
||||||
|
|
||||||
|
|
@ -471,7 +475,9 @@ func (a *authority) watchResource(rType xdsresource.Type, resourceName string, w
|
||||||
// instruct the transport layer to send a DiscoveryRequest for the same.
|
// instruct the transport layer to send a DiscoveryRequest for the same.
|
||||||
state := resources[resourceName]
|
state := resources[resourceName]
|
||||||
if state == nil {
|
if state == nil {
|
||||||
a.logger.Debugf("First watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
if a.logger.V(2) {
|
||||||
|
a.logger.Infof("First watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
||||||
|
}
|
||||||
state = &resourceState{
|
state = &resourceState{
|
||||||
watchers: make(map[xdsresource.ResourceWatcher]bool),
|
watchers: make(map[xdsresource.ResourceWatcher]bool),
|
||||||
md: xdsresource.UpdateMetadata{Status: xdsresource.ServiceStatusRequested},
|
md: xdsresource.UpdateMetadata{Status: xdsresource.ServiceStatusRequested},
|
||||||
|
|
@ -510,7 +516,9 @@ func (a *authority) watchResource(rType xdsresource.Type, resourceName string, w
|
||||||
// There are no more watchers for this resource, delete the state
|
// There are no more watchers for this resource, delete the state
|
||||||
// associated with it, and instruct the transport to send a request
|
// associated with it, and instruct the transport to send a request
|
||||||
// which does not include this resource name.
|
// which does not include this resource name.
|
||||||
a.logger.Debugf("Removing last watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
if a.logger.V(2) {
|
||||||
|
a.logger.Infof("Removing last watch for type %q, resource name %q", rType.TypeName(), resourceName)
|
||||||
|
}
|
||||||
delete(resources, resourceName)
|
delete(resources, resourceName)
|
||||||
a.sendDiscoveryRequestLocked(rType, resources)
|
a.sendDiscoveryRequestLocked(rType, resources)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,7 @@ import (
|
||||||
|
|
||||||
// Any per-RPC level logs which print complete request or response messages
|
// Any per-RPC level logs which print complete request or response messages
|
||||||
// should be gated at this verbosity level. Other per-RPC level logs which print
|
// should be gated at this verbosity level. Other per-RPC level logs which print
|
||||||
// terse output should be at `INFO` and verbosity 2, which corresponds to using
|
// terse output should be at `INFO` and verbosity 2.
|
||||||
// the `Debugf` method on the logger.
|
|
||||||
const perRPCVerbosityLevel = 9
|
const perRPCVerbosityLevel = 9
|
||||||
|
|
||||||
type adsStream = v3adsgrpc.AggregatedDiscoveryService_StreamAggregatedResourcesClient
|
type adsStream = v3adsgrpc.AggregatedDiscoveryService_StreamAggregatedResourcesClient
|
||||||
|
|
@ -298,7 +297,9 @@ func (t *Transport) sendAggregatedDiscoveryServiceRequest(stream adsStream, send
|
||||||
if t.logger.V(perRPCVerbosityLevel) {
|
if t.logger.V(perRPCVerbosityLevel) {
|
||||||
t.logger.Infof("ADS request sent: %v", pretty.ToJSON(req))
|
t.logger.Infof("ADS request sent: %v", pretty.ToJSON(req))
|
||||||
} else {
|
} else {
|
||||||
t.logger.Debugf("ADS request sent for type %q, resources: %v, version %q, nonce %q", resourceURL, resourceNames, version, nonce)
|
if t.logger.V(2) {
|
||||||
|
t.logger.Infof("ADS request sent for type %q, resources: %v, version %q, nonce %q", resourceURL, resourceNames, version, nonce)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t.onSendHandler(&ResourceSendInfo{URL: resourceURL, ResourceNames: resourceNames})
|
t.onSendHandler(&ResourceSendInfo{URL: resourceURL, ResourceNames: resourceNames})
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -311,8 +312,8 @@ func (t *Transport) recvAggregatedDiscoveryServiceResponse(stream adsStream) (re
|
||||||
}
|
}
|
||||||
if t.logger.V(perRPCVerbosityLevel) {
|
if t.logger.V(perRPCVerbosityLevel) {
|
||||||
t.logger.Infof("ADS response received: %v", pretty.ToJSON(resp))
|
t.logger.Infof("ADS response received: %v", pretty.ToJSON(resp))
|
||||||
} else {
|
} else if t.logger.V(2) {
|
||||||
t.logger.Debugf("ADS response received for type %q, version %q, nonce %q", resp.GetTypeUrl(), resp.GetVersionInfo(), resp.GetNonce())
|
t.logger.Infof("ADS response received for type %q, version %q, nonce %q", resp.GetTypeUrl(), resp.GetVersionInfo(), resp.GetNonce())
|
||||||
}
|
}
|
||||||
return resp.GetResources(), resp.GetTypeUrl(), resp.GetVersionInfo(), resp.GetNonce(), nil
|
return resp.GetResources(), resp.GetTypeUrl(), resp.GetVersionInfo(), resp.GetNonce(), nil
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +513,9 @@ func (t *Transport) recv(stream adsStream) bool {
|
||||||
stream: stream,
|
stream: stream,
|
||||||
version: rVersion,
|
version: rVersion,
|
||||||
})
|
})
|
||||||
t.logger.Debugf("Sending ACK for resource type: %q, version: %q, nonce: %q", url, rVersion, nonce)
|
if t.logger.V(2) {
|
||||||
|
t.logger.Infof("Sending ACK for resource type: %q, version: %q, nonce: %q", url, rVersion, nonce)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue