From 2a923474b3a32e16384f1c28858095feca99f6e0 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Tue, 27 Aug 2024 07:41:27 -0400 Subject: [PATCH] add metrics for connect/disconnect events --- ...rics.go => app_request_network_metrics.go} | 26 +++++++++++++++++++ peers/external_handler.go | 5 ++++ 2 files changed, 31 insertions(+) rename peers/{app_request_netrwork_metrics.go => app_request_network_metrics.go} (67%) diff --git a/peers/app_request_netrwork_metrics.go b/peers/app_request_network_metrics.go similarity index 67% rename from peers/app_request_netrwork_metrics.go rename to peers/app_request_network_metrics.go index 12c5ea6b..b585533e 100644 --- a/peers/app_request_netrwork_metrics.go +++ b/peers/app_request_network_metrics.go @@ -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) { @@ -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 } diff --git a/peers/external_handler.go b/peers/external_handler.go index d34d352a..5e9689af 100644 --- a/peers/external_handler.go +++ b/peers/external_handler.go @@ -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 @@ -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 @@ -69,6 +71,7 @@ func NewRelayerExternalHandler( responseChans: make(map[uint32]chan message.InboundMessage), responsesCount: make(map[uint32]expectedResponses), timeoutManager: timeoutManager, + metrics: metrics, }, nil } @@ -102,6 +105,7 @@ 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) { @@ -109,6 +113,7 @@ func (h *RelayerExternalHandler) Disconnected(nodeID ids.NodeID) { "Disconnected", zap.Stringer("nodeID", nodeID), ) + h.metrics.disconnects.Inc() } // RegisterRequestID registers an AppRequest by requestID, and marks the number of