From 2464ab560e1a199920e6f9881782fd869b150f71 Mon Sep 17 00:00:00 2001 From: Deepthi Sigireddi Date: Mon, 27 Nov 2023 13:15:29 -0800 Subject: [PATCH] logging: log time taken for tablet initialization only once (#14597) Signed-off-by: deepthi --- go/vt/vttablet/tabletserver/state_manager.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/go/vt/vttablet/tabletserver/state_manager.go b/go/vt/vttablet/tabletserver/state_manager.go index 7203174449e..75d1a7c7c3b 100644 --- a/go/vt/vttablet/tabletserver/state_manager.go +++ b/go/vt/vttablet/tabletserver/state_manager.go @@ -64,6 +64,7 @@ func (state servingState) String() string { // transitionRetryInterval is for tests. var transitionRetryInterval = 1 * time.Second +var logInitTime sync.Once // stateManager manages state transition for all the TabletServer // subcomponents. @@ -611,9 +612,9 @@ func (sm *stateManager) setTimeBomb() chan struct{} { // setState changes the state and logs the event. func (sm *stateManager) setState(tabletType topodatapb.TabletType, state servingState) { - defer func() { + defer logInitTime.Do(func() { log.Infof("Tablet Init took %d ms", time.Since(servenv.GetInitStartTime()).Milliseconds()) - }() + }) sm.mu.Lock() defer sm.mu.Unlock() if tabletType == topodatapb.TabletType_UNKNOWN {