From 927a760942846eed49658147adbe62a9427b449a Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Mon, 16 Oct 2023 15:43:49 -0500 Subject: [PATCH] =?UTF-8?q?Add=20metrics=20to=20time=20each=20part=20of=20?= =?UTF-8?q?WSBroadcastServer=E2=80=99s=20StartWithHeader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wsbroadcastserver/wsbroadcastserver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index cd277387a0..f3e693d5d8 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -23,6 +23,7 @@ import ( flag "github.com/spf13/pflag" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/offchainlabs/nitro/arbutil" ) @@ -32,6 +33,8 @@ var ( HTTPHeaderFeedClientVersion = textproto.CanonicalMIMEHeaderKey("Arbitrum-Feed-Client-Version") HTTPHeaderRequestedSequenceNumber = textproto.CanonicalMIMEHeaderKey("Arbitrum-Requested-Sequence-Number") HTTPHeaderChainId = textproto.CanonicalMIMEHeaderKey("Arbitrum-Chain-Id") + UpgradeToWSTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/wsupgrade/duration", nil) + StartWithHeaderTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/startwithheader/duration", nil) ) const ( @@ -205,6 +208,7 @@ func (s *WSBroadcastServer) Start(ctx context.Context) error { } func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.HandshakeHeader) error { + startTimeMain := time.Now() s.startMutex.Lock() defer s.startMutex.Unlock() if s.started { @@ -316,7 +320,10 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands } // Zero-copy upgrade to WebSocket connection. + startTime := time.Now() _, err = upgrader.Upgrade(conn) + elapsed := time.Since(startTime) + UpgradeToWSTimer.Update(elapsed) if err != nil { if err.Error() != "" { @@ -483,6 +490,9 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands s.started = true + elapsedMain := time.Since(startTimeMain) + StartWithHeaderTimer.Update(elapsedMain) + return nil }