From 4d663d57d663a342f05e690acb3f012e46010908 Mon Sep 17 00:00:00 2001 From: gary rong Date: Wed, 8 Jan 2020 21:08:56 +0800 Subject: [PATCH] les: fix request serving metrics (#20507) --- les/server_handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/les/server_handler.go b/les/server_handler.go index 4b505c2bc..38aeac4e8 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -273,7 +273,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInHeaderPacketsMeter.Mark(1) miscInHeaderTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeHeaderTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -377,6 +376,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutHeaderPacketsMeter.Mark(1) miscOutHeaderTrafficMeter.Mark(int64(reply.size())) + miscServingTimeHeaderTimer.Update(time.Duration(task.servingTime)) } }() } @@ -386,7 +386,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInBodyPacketsMeter.Mark(1) miscInBodyTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeBodyTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -426,6 +425,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutBodyPacketsMeter.Mark(1) miscOutBodyTrafficMeter.Mark(int64(reply.size())) + miscServingTimeBodyTimer.Update(time.Duration(task.servingTime)) } }() } @@ -435,7 +435,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInCodePacketsMeter.Mark(1) miscInCodeTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeCodeTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -498,6 +497,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutCodePacketsMeter.Mark(1) miscOutCodeTrafficMeter.Mark(int64(reply.size())) + miscServingTimeCodeTimer.Update(time.Duration(task.servingTime)) } }() } @@ -507,7 +507,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInReceiptPacketsMeter.Mark(1) miscInReceiptTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeReceiptTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -555,6 +554,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutReceiptPacketsMeter.Mark(1) miscOutReceiptTrafficMeter.Mark(int64(reply.size())) + miscServingTimeReceiptTimer.Update(time.Duration(task.servingTime)) } }() } @@ -564,7 +564,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInTrieProofPacketsMeter.Mark(1) miscInTrieProofTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeTrieProofTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -658,6 +657,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutTrieProofPacketsMeter.Mark(1) miscOutTrieProofTrafficMeter.Mark(int64(reply.size())) + miscServingTimeTrieProofTimer.Update(time.Duration(task.servingTime)) } }() } @@ -667,7 +667,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInHelperTriePacketsMeter.Mark(1) miscInHelperTrieTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeHelperTrieTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -733,6 +732,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutHelperTriePacketsMeter.Mark(1) miscOutHelperTrieTrafficMeter.Mark(int64(reply.size())) + miscServingTimeHelperTrieTimer.Update(time.Duration(task.servingTime)) } }() } @@ -742,7 +742,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInTxsPacketsMeter.Mark(1) miscInTxsTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeTxTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -782,6 +781,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutTxsPacketsMeter.Mark(1) miscOutTxsTrafficMeter.Mark(int64(reply.size())) + miscServingTimeTxTimer.Update(time.Duration(task.servingTime)) } }() } @@ -791,7 +791,6 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscInTxStatusPacketsMeter.Mark(1) miscInTxStatusTrafficMeter.Mark(int64(msg.Size)) - defer func(start time.Time) { miscServingTimeTxStatusTimer.UpdateSince(start) }(time.Now()) } var req struct { ReqID uint64 @@ -819,6 +818,7 @@ func (h *serverHandler) handleMsg(p *peer, wg *sync.WaitGroup) error { if metrics.EnabledExpensive { miscOutTxStatusPacketsMeter.Mark(1) miscOutTxStatusTrafficMeter.Mark(int64(reply.size())) + miscServingTimeTxStatusTimer.Update(time.Duration(task.servingTime)) } }() }