Skip to content

Commit

Permalink
Report metric tracking voting time
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojtek committed Feb 16, 2024
1 parent 21435cd commit 5dcb161
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/actions/logging/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,6 +87,7 @@ func init() {
ProposalSummary,
ValidatorBlockMismatchCounter,
BlockRoundSummary,
VoteTimeHistogram,
} {
if err := prometheus.Register(c); err != nil {
panic(err)
Expand Down
37 changes: 37 additions & 0 deletions modules/consensus/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/forbole/bdjuno/v4/modules/actions/logging"
Expand All @@ -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
}

Expand Down Expand Up @@ -111,3 +114,37 @@ 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))
}
}

func (m *Module) measureVotedVotingPower(block *tmctypes.ResultBlock, vals *tmctypes.ResultValidators) {
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))
}
}

0 comments on commit 5dcb161

Please sign in to comment.