From 06a96814f3010211d67a84842e773bcde6c01980 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 10 May 2022 12:19:33 -0400 Subject: [PATCH] add metrics for late vote --- internal/consensus/metrics.go | 17 +++++++++++++++++ internal/consensus/state.go | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/internal/consensus/metrics.go b/internal/consensus/metrics.go index b93730857..e5c0162f4 100644 --- a/internal/consensus/metrics.go +++ b/internal/consensus/metrics.go @@ -126,6 +126,11 @@ type Metrics struct { // with a round. The value begins at 0 for each round and approaches 1.0 as // additional voting power is observed. The metric is labeled by vote type. RoundVotingPowerPercent metrics.Gauge + + // LateVotes stores the number of votes that were received by this node that + // correspond to earlier heights and rounds than this node is currently + // in. + LateVotes metrics.Counter } // PrometheusMetrics returns Metrics build using Prometheus client library. @@ -334,6 +339,12 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { "The value begins at 0 for each round and approaches 1.0 as additional " + "voting power is observed.", }, append(labels, "vote_type")).With(labelsAndValues...), + LateVotes: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "late_votes", + Help: "Number of votes received by the node since process start that correspond to earlier heights and rounds than this node is currently in.", + }, append(labels, "vote_type")).With(labelsAndValues...), } } @@ -375,6 +386,7 @@ func NopMetrics() *Metrics { ProposalReceiveCount: discard.NewCounter(), ProposalCreateCount: discard.NewCounter(), RoundVotingPowerPercent: discard.NewGauge(), + LateVotes: discard.NewCounter(), } } @@ -430,6 +442,11 @@ func (m *Metrics) MarkRound(r int32, st time.Time) { m.RoundVotingPowerPercent.With("vote_type", pcn).Set(0) } +func (m *Metrics) MarkLateVote(vt tmproto.SignedMsgType) { + n := strings.ToLower(strings.TrimPrefix(vt.String(), "SIGNED_MSG_TYPE_")) + m.LateVotes.With("vote_type", n).Add(1) +} + func (m *Metrics) MarkStep(s cstypes.RoundStepType) { if !m.stepStart.IsZero() { stepTime := time.Since(m.stepStart).Seconds() diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 91738c2c1..90efbab77 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -2299,6 +2299,10 @@ func (cs *State) addVote( "cs_height", cs.Height, ) + if vote.Height < cs.Height || (vote.Height == cs.Height && vote.Round < cs.Round) { + cs.metrics.MarkLateVote(vote.Type) + } + // A precommit for the previous height? // These come in while we wait timeoutCommit if vote.Height+1 == cs.Height && vote.Type == tmproto.PrecommitType {