Skip to content

Commit

Permalink
Add the service name to the log entry (cadence-workflow#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk authored Mar 15, 2021
1 parent 764500a commit 6a80bf1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/clientBean.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (p *dnsDispatcherProvider) Get(serviceName string, address string) (*yarpc.
peerListUpdater.Start()
outbound := tchanTransport.NewOutbound(peerList)

p.logger.Info("Creating RPC dispatcher outbound", tag.Service(serviceName), tag.Address(address))
p.logger.Info("Creating RPC dispatcher outbound", tag.Address(address))

// Attach the outbound to the dispatcher (this will add middleware/logging/etc)
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ func (s *server) startService() common.Daemon {
params := service.BootstrapParams{}
params.Name = "cadence-" + s.name
params.Logger = loggerimpl.NewLogger(s.cfg.Log.NewZapLogger())
params.UpdateLoggerWithServiceName(params.Name)
params.PersistenceConfig = s.cfg.Persistence

params.DynamicConfig, err = dynamicconfig.NewFileBasedClient(&s.cfg.DynamicConfigClient, params.Logger.WithTags(tag.Service(params.Name)), s.doneC)
params.DynamicConfig, err = dynamicconfig.NewFileBasedClient(&s.cfg.DynamicConfigClient, params.Logger, s.doneC)
if err != nil {
log.Printf("error creating file based dynamic config client, use no-op config client instead. error: %v", err)
params.DynamicConfig = dynamicconfig.NewNopClient()
Expand Down
2 changes: 1 addition & 1 deletion common/membership/rpServiceResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newRingpopServiceResolver(
rp: rp,
refreshChan: make(chan struct{}),
shutdownCh: make(chan struct{}),
logger: logger.WithTags(tag.ComponentServiceResolver, tag.Service(service)),
logger: logger.WithTags(tag.ComponentServiceResolver),
membersMap: make(map[string]struct{}),
listeners: make(map[string]chan<- *ChangedEvent),
}
Expand Down
2 changes: 1 addition & 1 deletion common/resource/resourceImpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func New(
visibilityManagerInitializer VisibilityManagerInitializer,
) (impl *Impl, retError error) {

logger := params.Logger.WithTags(tag.Service(serviceName))
logger := params.Logger
throttledLogger := loggerimpl.NewThrottledLogger(logger, throttledLoggerMaxRPS)

numShards := params.PersistenceConfig.NumHistoryShards
Expand Down
4 changes: 2 additions & 2 deletions common/service/config/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (d *RPCFactory) createDispatcher() *yarpc.Dispatcher {
if err != nil {
d.logger.Fatal("Failed to create transport channel", tag.Error(err))
}
d.logger.Info("Created RPC dispatcher and listening", tag.Service(d.serviceName), tag.Address(hostAddress))
d.logger.Info("Created RPC dispatcher and listening", tag.Address(hostAddress))
return yarpc.NewDispatcher(yarpc.Config{
Name: d.serviceName,
Inbounds: yarpc.Inbounds{d.ch.NewInbound()},
Expand All @@ -93,7 +93,7 @@ func (d *RPCFactory) CreateDispatcherForOutbound(
) *yarpc.Dispatcher {

// Setup dispatcher(outbound) for onebox
d.logger.Info("Created RPC dispatcher outbound", tag.Service(d.serviceName), tag.Address(hostName))
d.logger.Info("Created RPC dispatcher outbound", tag.Address(hostName))
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: callerName,
Outbounds: yarpc.Outbounds{
Expand Down
10 changes: 7 additions & 3 deletions common/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ func New(params *BootstrapParams) Service {

// UpdateLoggerWithServiceName tag logging with service name from the top level
func (params *BootstrapParams) UpdateLoggerWithServiceName(name string) {
params.Logger = params.Logger.WithTags(tag.Service(name))
params.ThrottledLogger = params.ThrottledLogger.WithTags(tag.Service(name))
if params.Logger != nil {
params.Logger = params.Logger.WithTags(tag.Service(name))
}
if params.ThrottledLogger != nil {
params.ThrottledLogger = params.ThrottledLogger.WithTags(tag.Service(name))
}
}

// GetHostName returns the name of host running the service
Expand Down Expand Up @@ -308,7 +312,7 @@ func GetMetricsServiceIdx(serviceName string, logger log.Logger) metrics.Service
case common.WorkerServiceName:
return metrics.Worker
default:
logger.Fatal("Unknown service name for metrics!", tag.Service(serviceName))
logger.Fatal("Unknown service name for metrics!")
}

// this should never happen!
Expand Down
4 changes: 4 additions & 0 deletions host/onebox.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func (c *cadenceImpl) startFrontend(hosts map[string][]string, startWG *sync.Wai
params.Name = common.FrontendServiceName
params.Logger = c.logger
params.ThrottledLogger = c.logger
params.UpdateLoggerWithServiceName(common.FrontendServiceName)
params.PProfInitializer = newPProfInitializerImpl(c.logger, c.FrontendPProfPort())
params.RPCFactory = newRPCFactoryImpl(common.FrontendServiceName, c.FrontendAddress(), c.logger)
params.MetricScope = tally.NewTestScope(common.FrontendServiceName, make(map[string]string))
Expand Down Expand Up @@ -461,6 +462,7 @@ func (c *cadenceImpl) startHistory(
params.Name = common.HistoryServiceName
params.Logger = c.logger
params.ThrottledLogger = c.logger
params.UpdateLoggerWithServiceName(common.HistoryServiceName)
params.PProfInitializer = newPProfInitializerImpl(c.logger, pprofPorts[i])
params.RPCFactory = newRPCFactoryImpl(common.HistoryServiceName, hostport, c.logger)
params.MetricScope = tally.NewTestScope(common.HistoryServiceName, make(map[string]string))
Expand Down Expand Up @@ -530,6 +532,7 @@ func (c *cadenceImpl) startMatching(hosts map[string][]string, startWG *sync.Wai
params.Name = common.MatchingServiceName
params.Logger = c.logger
params.ThrottledLogger = c.logger
params.UpdateLoggerWithServiceName(common.MatchingServiceName)
params.PProfInitializer = newPProfInitializerImpl(c.logger, c.MatchingPProfPort())
params.RPCFactory = newRPCFactoryImpl(common.MatchingServiceName, c.MatchingServiceAddress(), c.logger)
params.MetricScope = tally.NewTestScope(common.MatchingServiceName, make(map[string]string))
Expand Down Expand Up @@ -572,6 +575,7 @@ func (c *cadenceImpl) startWorker(hosts map[string][]string, startWG *sync.WaitG
params.Name = common.WorkerServiceName
params.Logger = c.logger
params.ThrottledLogger = c.logger
params.UpdateLoggerWithServiceName(common.WorkerServiceName)
params.PProfInitializer = newPProfInitializerImpl(c.logger, c.WorkerPProfPort())
params.RPCFactory = newRPCFactoryImpl(common.WorkerServiceName, c.WorkerServiceAddress(), c.logger)
params.MetricScope = tally.NewTestScope(common.WorkerServiceName, make(map[string]string))
Expand Down

0 comments on commit 6a80bf1

Please sign in to comment.