Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics to time each part of WSBroadcastServer’s StartWithHeader #1926

Merged
merged 9 commits into from
Oct 26, 2023
12 changes: 11 additions & 1 deletion wsbroadcastserver/wsbroadcastserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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/feed/clients/upgrade/duration", nil)
startWithHeaderTimer = metrics.NewRegisteredTimer("arb/feed/clients/start/duration", nil)
)

const (
Expand Down Expand Up @@ -201,7 +204,11 @@ func (s *WSBroadcastServer) Start(ctx context.Context) error {
HTTPHeaderChainId: []string{strconv.FormatUint(s.chainId, 10)},
})

return s.StartWithHeader(ctx, header)
startTime := time.Now()
err := s.StartWithHeader(ctx, header)
elapsed := time.Since(startTime)
startWithHeaderTimer.Update(elapsed)
return err
}

func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.HandshakeHeader) error {
Expand Down Expand Up @@ -316,7 +323,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() != "" {
Expand Down
Loading