Skip to content

Commit ff8a2fd

Browse files
committed
metrics: report chain lengths, cleanup metrics a bit
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 8dc2f7e commit ff8a2fd

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

gpbft/gpbft.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ func newInstance(
243243
if input.IsZero() {
244244
return nil, fmt.Errorf("input is empty")
245245
}
246+
246247
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrInitialPhase))
247248
metrics.currentInstance.Record(context.TODO(), int64(instanceID))
248249
metrics.currentPhase.Record(context.TODO(), int64(INITIAL_PHASE))
249-
metrics.currentRound.Record(context.TODO(), 0)
250250

251251
return &instance{
252252
participant: participant,
@@ -500,6 +500,14 @@ func (i *instance) tryCurrentPhase() error {
500500
}
501501
}
502502

503+
func (i *instance) reportPhaseMetrics() {
504+
attr := metric.WithAttributes(attrPhase[i.current.Phase])
505+
506+
metrics.phaseCounter.Add(context.TODO(), 1, attr)
507+
metrics.currentPhase.Record(context.TODO(), int64(i.current.Phase))
508+
metrics.proposalLength.Record(context.TODO(), int64(i.proposal.Len()-1), attr)
509+
}
510+
503511
// Sends this node's QUALITY message and begins the QUALITY phase.
504512
func (i *instance) beginQuality() error {
505513
if i.current.Phase != INITIAL_PHASE {
@@ -511,8 +519,7 @@ func (i *instance) beginQuality() error {
511519
i.phaseTimeout = i.alarmAfterSynchronyWithMulti(i.participant.qualityDeltaMulti)
512520
i.resetRebroadcastParams()
513521
i.broadcast(i.current.Round, QUALITY_PHASE, i.proposal, false, nil)
514-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrQualityPhase))
515-
metrics.currentPhase.Record(context.TODO(), int64(QUALITY_PHASE))
522+
i.reportPhaseMetrics()
516523
return nil
517524
}
518525

@@ -572,8 +579,7 @@ func (i *instance) beginConverge(justification *Justification) {
572579
i.getRound(i.current.Round).converged.SetSelfValue(i.proposal, justification)
573580

574581
i.broadcast(i.current.Round, CONVERGE_PHASE, i.proposal, true, justification)
575-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrConvergePhase))
576-
metrics.currentPhase.Record(context.TODO(), int64(CONVERGE_PHASE))
582+
i.reportPhaseMetrics()
577583
}
578584

579585
// Attempts to end the CONVERGE phase and begin PREPARE based on current state.
@@ -630,8 +636,7 @@ func (i *instance) beginPrepare(justification *Justification) {
630636
i.resetRebroadcastParams()
631637

632638
i.broadcast(i.current.Round, PREPARE_PHASE, i.value, false, justification)
633-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrPreparePhase))
634-
metrics.currentPhase.Record(context.TODO(), int64(PREPARE_PHASE))
639+
i.reportPhaseMetrics()
635640
}
636641

637642
// Attempts to end the PREPARE phase and begin COMMIT based on current state.
@@ -681,8 +686,7 @@ func (i *instance) beginCommit() {
681686
}
682687

683688
i.broadcast(i.current.Round, COMMIT_PHASE, i.value, false, justification)
684-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrCommitPhase))
685-
metrics.currentPhase.Record(context.TODO(), int64(COMMIT_PHASE))
689+
i.reportPhaseMetrics()
686690
}
687691

688692
func (i *instance) tryCommit(round uint64) error {
@@ -755,8 +759,7 @@ func (i *instance) beginDecide(round uint64) {
755759
// Since each node sends only one DECIDE message, they must share the same vote
756760
// in order to be aggregated.
757761
i.broadcast(0, DECIDE_PHASE, i.value, false, justification)
758-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrDecidePhase))
759-
metrics.currentPhase.Record(context.TODO(), int64(DECIDE_PHASE))
762+
i.reportPhaseMetrics()
760763
}
761764

762765
// Skips immediately to the DECIDE phase and sends a DECIDE message
@@ -770,9 +773,8 @@ func (i *instance) skipToDecide(value *ECChain, justification *Justification) {
770773
i.resetRebroadcastParams()
771774
i.broadcast(0, DECIDE_PHASE, i.value, false, justification)
772775

773-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrDecidePhase))
774-
metrics.currentPhase.Record(context.TODO(), int64(DECIDE_PHASE))
775776
metrics.skipCounter.Add(context.TODO(), 1, metric.WithAttributes(attrSkipToDecide))
777+
i.reportPhaseMetrics()
776778
}
777779

778780
func (i *instance) tryDecide() error {
@@ -874,9 +876,8 @@ func (i *instance) terminate(decision *Justification) {
874876
i.terminationValue = decision
875877
i.resetRebroadcastParams()
876878

877-
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrTerminatedPhase))
878879
metrics.roundHistogram.Record(context.TODO(), int64(i.current.Round))
879-
metrics.currentPhase.Record(context.TODO(), int64(TERMINATED_PHASE))
880+
i.reportPhaseMetrics()
880881
}
881882

882883
func (i *instance) terminated() bool {

gpbft/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var (
5151
currentInstance metric.Int64Gauge
5252
currentRound metric.Int64Gauge
5353
currentPhase metric.Int64Gauge
54+
proposalLength metric.Int64Gauge
5455
skipCounter metric.Int64Counter
5556
validationCache metric.Int64Counter
5657
quorumParticipation metric.Float64Gauge
@@ -68,6 +69,8 @@ var (
6869
currentPhase: measurements.Must(meter.Int64Gauge("f3_gpbft_current_phase",
6970
metric.WithDescription("The current phase represented as numeric value of gpbft.Phase: "+
7071
"0=INITIAL, 1=QUALITY, 2=CONVERGE, 3=PREPARE, 4=COMMIT, 5=DECIDE, and 6=TERMINATED"))),
72+
proposalLength: measurements.Must(meter.Int64Gauge("f3_gpbft_current_proposal_len",
73+
metric.WithDescription("Length of active proposal"))),
7174
skipCounter: measurements.Must(meter.Int64Counter("f3_gpbft_skip_counter", metric.WithDescription("The number of times GPBFT skip either round or phase"))),
7275
validationCache: measurements.Must(meter.Int64Counter("f3_gpbft_validation_cache", metric.WithDescription("The number of times GPBFT validation cache resulted in hit or miss."))),
7376
quorumParticipation: measurements.Must(meter.Float64Gauge("f3_gpbft_participation",

0 commit comments

Comments
 (0)