Skip to content

Commit

Permalink
Merge pull request #1926 from OffchainLabs/add-metrics-wsbserver
Browse files Browse the repository at this point in the history
Add metrics to time each part of WSBroadcastServer’s StartWithHeader
  • Loading branch information
joshuacolvin0 authored Oct 26, 2023
2 parents 8febcd5 + 43e3ec8 commit cd85568
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit cd85568

Please sign in to comment.