From 49f6755d137bbc2e5830b8b92d5cd55186c653a9 Mon Sep 17 00:00:00 2001 From: Wojtek <103407812+wojtek-coreum@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:50:37 +0100 Subject: [PATCH] Report metric tracking voting time (#59) * Report metric tracking voting time * fix --- modules/actions/logging/prometheus.go | 13 +++++++++++++ modules/consensus/handle_block.go | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/actions/logging/prometheus.go b/modules/actions/logging/prometheus.go index 6b844d779..1db621249 100644 --- a/modules/actions/logging/prometheus.go +++ b/modules/actions/logging/prometheus.go @@ -66,6 +66,18 @@ var BlockRoundSummary = prometheus.NewSummaryVec( }, ) +// VoteTimeHistogram represents the Telemetry histogram used to track voting times +var VoteTimeHistogram = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Name: "bdjuno_vote_time", + Help: "Measures time required to vote.", + Buckets: []float64{250, 500, 750, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000, 7000}, + }, []string{ + "proposer", + "voter", + }, +) + func init() { for _, c := range []prometheus.Collector{ ActionResponseTime, @@ -75,6 +87,7 @@ func init() { ProposalSummary, ValidatorBlockMismatchCounter, BlockRoundSummary, + VoteTimeHistogram, } { if err := prometheus.Register(c); err != nil { panic(err) diff --git a/modules/consensus/handle_block.go b/modules/consensus/handle_block.go index df29ed64c..06b4b8cf9 100644 --- a/modules/consensus/handle_block.go +++ b/modules/consensus/handle_block.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "strconv" + "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/forbole/bdjuno/v4/modules/actions/logging" @@ -28,6 +29,8 @@ func (m *Module) HandleBlock( logging.BlockRoundSummary.WithLabelValues(strconv.Itoa(int(b.Block.LastCommit.Round))).Observe(1.0) m.countProposalsByValidator(b, vals) + m.measureVotingTimes(b) + return nil } @@ -111,3 +114,20 @@ func updateProposerMetric(expected, real tmtypes.Address) { } logging.ProposalSummary.WithLabelValues(sdk.ConsAddress(expected).String()).Observe(value) } + +func (m *Module) measureVotingTimes(block *tmctypes.ResultBlock) { + proposerAddr := block.Block.ProposerAddress.Bytes() + + var proposerVoteTime time.Time + for _, s := range block.Block.LastCommit.Signatures { + if bytes.Equal(s.ValidatorAddress.Bytes(), proposerAddr) { + proposerVoteTime = s.Timestamp + break + } + } + proposer := sdk.ConsAddress(block.Block.ProposerAddress).String() + for _, s := range block.Block.LastCommit.Signatures { + logging.VoteTimeHistogram.WithLabelValues(proposer, sdk.ConsAddress(s.ValidatorAddress).String()). + Observe(float64(s.Timestamp.Sub(proposerVoteTime)) / float64(time.Millisecond)) + } +}