Skip to content

Commit

Permalink
add metrics for connect/disconnect events
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Aug 27, 2024
1 parent 9068345 commit 2a92347
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var (
type AppRequestNetworkMetrics struct {
infoAPICallLatencyMS prometheus.Histogram
pChainAPICallLatencyMS prometheus.Histogram
connects prometheus.Counter
disconnects prometheus.Counter
}

func newAppRequestNetworkMetrics(registerer prometheus.Registerer) (*AppRequestNetworkMetrics, error) {
Expand Down Expand Up @@ -40,8 +42,32 @@ func newAppRequestNetworkMetrics(registerer prometheus.Registerer) (*AppRequestN
}
registerer.MustRegister(pChainAPICallLatencyMS)

connects := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "connects",
Help: "Number of connected events",
},
)
if connects == nil {
return nil, ErrFailedToCreateAppRequestNetworkMetrics
}
registerer.MustRegister(connects)

disconnects := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "disconnects",
Help: "Number of disconnected events",
},
)
if disconnects == nil {
return nil, ErrFailedToCreateAppRequestNetworkMetrics
}
registerer.MustRegister(disconnects)

return &AppRequestNetworkMetrics{
infoAPICallLatencyMS: infoAPICallLatencyMS,
pChainAPICallLatencyMS: pChainAPICallLatencyMS,
connects: connects,
disconnects: disconnects,
}, nil
}
5 changes: 5 additions & 0 deletions peers/external_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type RelayerExternalHandler struct {
responseChans map[uint32]chan message.InboundMessage
responsesCount map[uint32]expectedResponses
timeoutManager timer.AdaptiveTimeoutManager
metrics *AppRequestNetworkMetrics
}

// expectedResponses counts the number of responses and compares against the expected number of responses
Expand All @@ -41,6 +42,7 @@ type expectedResponses struct {
// Teleporter application relayer, as well as handle timeouts.
func NewRelayerExternalHandler(
logger logging.Logger,
metrics *AppRequestNetworkMetrics,
registerer prometheus.Registerer,
) (*RelayerExternalHandler, error) {
// TODO: Leaving this static for now, but we may want to have this as a config option
Expand Down Expand Up @@ -69,6 +71,7 @@ func NewRelayerExternalHandler(
responseChans: make(map[uint32]chan message.InboundMessage),
responsesCount: make(map[uint32]expectedResponses),
timeoutManager: timeoutManager,
metrics: metrics,
}, nil
}

Expand Down Expand Up @@ -102,13 +105,15 @@ func (h *RelayerExternalHandler) Connected(nodeID ids.NodeID, version *version.A
zap.Stringer("version", version),
zap.Stringer("subnetID", subnetID),
)
h.metrics.connects.Inc()
}

func (h *RelayerExternalHandler) Disconnected(nodeID ids.NodeID) {
h.log.Debug(
"Disconnected",
zap.Stringer("nodeID", nodeID),
)
h.metrics.disconnects.Inc()
}

// RegisterRequestID registers an AppRequest by requestID, and marks the number of
Expand Down

0 comments on commit 2a92347

Please sign in to comment.