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

feat: ping time metric #2498

Merged
merged 5 commits into from
Sep 14, 2021
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
4 changes: 4 additions & 0 deletions pkg/hive/hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,16 @@ func (s *Service) checkAndAddPeers(ctx context.Context, peers pb.Peers) {
ctx, cancel := context.WithTimeout(ctx, pingTimeout)
defer cancel()

start := time.Now()

// check if the underlay is usable by doing a raw ping using libp2p
if _, err = s.streamer.Ping(ctx, multiUnderlay); err != nil {
s.metrics.PingFailureTime.Observe(time.Since(start).Seconds())
s.metrics.UnreachablePeers.Inc()
s.logger.Debugf("hive: peer %s: underlay %s not reachable", hex.EncodeToString(newPeer.Overlay), multiUnderlay)
return
}
s.metrics.PingTime.Observe(time.Since(start).Seconds())

s.metrics.ReachablePeers.Inc()

Expand Down
17 changes: 16 additions & 1 deletion pkg/hive/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ type metrics struct {
PeersHandlerPeers prometheus.Counter
UnreachablePeers prometheus.Counter

PeerConnectAttempts prometheus.Counter
PingTime prometheus.Histogram
PingFailureTime prometheus.Histogram

PeerConnectAttempts prometheus.Counter
PeerUnderlayErr prometheus.Counter
StorePeerErr prometheus.Counter
ReachablePeers prometheus.Counter
Expand Down Expand Up @@ -64,6 +67,18 @@ func newMetrics() metrics {
Name: "unreachable_peers_count",
Help: "Number of peers that are unreachable.",
}),
PingTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "ping_time",
Help: "The time spent for pings.",
acud marked this conversation as resolved.
Show resolved Hide resolved
}),
PingFailureTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "fail_ping_time",
Help: "The time spent for unsuccessful pings.",
}),
PeerConnectAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Expand Down