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 for connect/disconnect events #461

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewNetwork(
}

// Create the handler for handling inbound app responses
handler, err := NewRelayerExternalHandler(logger, prometheus.DefaultRegisterer)
handler, err := NewRelayerExternalHandler(logger, metrics)
if err != nil {
logger.Error(
"Failed to create p2p network handler",
Expand Down
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
}
8 changes: 6 additions & 2 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,7 +42,7 @@ type expectedResponses struct {
// Teleporter application relayer, as well as handle timeouts.
func NewRelayerExternalHandler(
logger logging.Logger,
registerer prometheus.Registerer,
metrics *AppRequestNetworkMetrics,
) (*RelayerExternalHandler, error) {
// TODO: Leaving this static for now, but we may want to have this as a config option
cfg := timer.AdaptiveTimeoutConfig{
Expand All @@ -52,7 +53,7 @@ func NewRelayerExternalHandler(
TimeoutHalflife: constants.DefaultNetworkTimeoutHalflife,
}

timeoutManager, err := timer.NewAdaptiveTimeoutManager(&cfg, registerer)
timeoutManager, err := timer.NewAdaptiveTimeoutManager(&cfg, prometheus.DefaultRegisterer)
if err != nil {
logger.Error(
"Failed to create timeout manager",
Expand All @@ -69,6 +70,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 +104,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