Skip to content

Add step specific metrics #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/consensus/metrics.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions internal/consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ type Metrics struct {

// ApplyBlockLatency measures how long it takes to execute ApplyBlock in finalize commit step
ApplyBlockLatency metrics.Histogram `metrics_buckettype:"exprange" metrics_bucketsizes:"0.01, 10, 10"`

StepLatency metrics.Gauge `metrics_labels:"step"`
lastRecordedStepLatencyNano int64
StepCount metrics.Gauge `metrics_labels:"step"`
}

// RecordConsMetrics uses for recording the block related metrics during fast-sync.
Expand Down Expand Up @@ -249,6 +253,29 @@ func (m *Metrics) MarkStep(s cstypes.RoundStepType) {
stepTime := time.Since(m.stepStart).Seconds()
stepName := strings.TrimPrefix(s.String(), "RoundStep")
m.StepDuration.With("step", stepName).Observe(stepTime)
m.StepCount.With("step", s.String()).Add(1)
}
m.stepStart = time.Now()
}

func (m *Metrics) MarkStepLatency(s cstypes.RoundStepType) {
now := time.Now().UnixNano()
m.StepLatency.With("step", s.String()).Add(float64(now - m.lastRecordedStepLatencyNano))
m.lastRecordedStepLatencyNano = now
}

func (m *Metrics) ClearStepMetrics() {
for _, st := range []cstypes.RoundStepType{
cstypes.RoundStepNewHeight,
cstypes.RoundStepNewRound,
cstypes.RoundStepPropose,
cstypes.RoundStepPrevote,
cstypes.RoundStepPrevoteWait,
cstypes.RoundStepPrecommit,
cstypes.RoundStepPrecommitWait,
cstypes.RoundStepCommit,
} {
m.StepCount.With("step", st.String()).Set(0)
m.StepLatency.With("step", st.String()).Set(0)
}
}
4 changes: 4 additions & 0 deletions internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ func (cs *State) SetProposalAndBlock(

func (cs *State) updateHeight(height int64) {
cs.metrics.Height.Set(float64(height))
cs.metrics.ClearStepMetrics()
cs.roundState.SetHeight(height)
}

Expand Down Expand Up @@ -1043,6 +1044,8 @@ func (cs *State) handleMsg(ctx context.Context, mi msgInfo, fsyncUponCompletion
err error
)

cs.metrics.MarkStepLatency(cs.roundState.Step())

msg, peerID := mi.Msg, mi.PeerID

switch msg := msg.(type) {
Expand Down Expand Up @@ -1179,6 +1182,7 @@ func (cs *State) handleTimeout(
// the timeout will now cause a state transition
cs.mtx.Lock()
defer cs.mtx.Unlock()
cs.metrics.MarkStepLatency(rs.Step)

switch ti.Step {
case cstypes.RoundStepNewHeight:
Expand Down
Loading