Skip to content

Commit

Permalink
fix: observe the latency metric in a better place
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Nov 15, 2023
1 parent 05a8a81 commit 05cab59
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ReceiveMessages(channel chan *vaa.VAA, heartbeat *Heartbeat, networkID, boo
messageLatencyMetric := promauto.NewHistogram(prometheus.HistogramOpts{
Name: "beacon_message_latency",
Help: "Latency of messages received from the p2p network",
Buckets: []float64{0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 1, 1.3, 1.7, 2, 3, 5, 10, 20},
Buckets: []float64{0.3, 0.7, 1, 1.3, 1.7, 2, 2.3, 2.7, 3, 3.5, 4, 5, 10, 20},
})

observationsMetric := promauto.NewCounterVec(prometheus.CounterOpts{
Expand Down Expand Up @@ -99,10 +99,16 @@ func ReceiveMessages(channel chan *vaa.VAA, heartbeat *Heartbeat, networkID, boo
// Send message on channel, increment counter, and update heartbeat
channel <- vaa
messagesMetric.Inc()
messageLatencyMetric.Observe(time.Since(time.Unix(vaa.Timestamp.Unix(), 0)).Seconds())

if vaa.Timestamp.Unix() > heartbeat.Timestamp {
heartbeat.Timestamp = vaa.Timestamp.Unix()

// Only count the latency for the newer messages. This will
// give a better indication of the lag in the network.
//
// Also, we might receive a single message multiple times and doing the check
// here is that we only count the latency once.
messageLatencyMetric.Observe(time.Since(time.Unix(vaa.Timestamp.Unix(), 0)).Seconds())
}

log.Debug().Str("id", vaa.MessageID()).Msg("Received message")
Expand Down

0 comments on commit 05cab59

Please sign in to comment.