Skip to content

Commit

Permalink
Add peer clock skew metrics (ava-labs#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
najeal authored Jul 12, 2023
1 parent 2da0c25 commit aa06de0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions network/peer/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewMessageMetrics(

type Metrics struct {
Log logging.Logger
ClockSkew metric.Averager
FailedToParse prometheus.Counter
MessageMetrics map[message.Op]*MessageMetrics
}
Expand All @@ -107,6 +108,14 @@ func NewMetrics(
for _, op := range message.ExternalOps {
m.MessageMetrics[op] = NewMessageMetrics(op, namespace, registerer, &errs)
}

m.ClockSkew = metric.NewAveragerWithErrs(
namespace,
"clock_skew",
"clock skew during peer handshake",
registerer,
&errs,
)
return m, errs.Err
}

Expand Down
6 changes: 5 additions & 1 deletion network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,11 @@ func (p *peer) handleVersion(msg *p2p.Version) {
}

myTime := p.Clock.Unix()
if math.Abs(float64(msg.MyTime)-float64(myTime)) > p.MaxClockDifference.Seconds() {
clockDifference := math.Abs(float64(msg.MyTime) - float64(myTime))

p.Metrics.ClockSkew.Observe(clockDifference)

if clockDifference > p.MaxClockDifference.Seconds() {
if p.Beacons.Contains(p.id) {
p.Log.Warn("beacon reports out of sync time",
zap.Stringer("nodeID", p.id),
Expand Down

0 comments on commit aa06de0

Please sign in to comment.