Skip to content

Commit 094e4d3

Browse files
committed
metrics: report converge participation
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 85feac0 commit 094e4d3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

gpbft/gpbft.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ type roundState struct {
286286
func newRoundState(roundNumber uint64, powerTable *PowerTable) *roundState {
287287
roundAttr := attrKeyRound.Int(int(roundNumber))
288288
return &roundState{
289-
converged: newConvergeState(),
289+
converged: newConvergeState(roundAttr),
290290
prepared: newQuorumState(powerTable, attrPreparePhase, roundAttr),
291291
committed: newQuorumState(powerTable, attrCommitPhase, roundAttr),
292292
}
@@ -1323,6 +1323,10 @@ type convergeState struct {
13231323
senders map[ActorID]struct{}
13241324
// Chains indexed by key.
13251325
values map[ECChainKey]ConvergeValue
1326+
1327+
// sendersTotalPower is only used for metrics reporting
1328+
sendersTotalPower int64
1329+
attributes []attribute.KeyValue
13261330
}
13271331

13281332
// ConvergeValue is valid when the Chain is non-zero and Justification is non-nil
@@ -1341,10 +1345,11 @@ func (cv *ConvergeValue) IsValid() bool {
13411345
return !cv.Chain.IsZero() && cv.Justification != nil
13421346
}
13431347

1344-
func newConvergeState() *convergeState {
1348+
func newConvergeState(attributes ...attribute.KeyValue) *convergeState {
13451349
return &convergeState{
1346-
senders: map[ActorID]struct{}{},
1347-
values: map[ECChainKey]ConvergeValue{},
1350+
senders: map[ActorID]struct{}{},
1351+
values: map[ECChainKey]ConvergeValue{},
1352+
attributes: append([]attribute.KeyValue{attrConvergePhase}, attributes...),
13481353
}
13491354
}
13501355

@@ -1379,6 +1384,11 @@ func (c *convergeState) Receive(sender ActorID, table *PowerTable, value *ECChai
13791384
}
13801385
c.senders[sender] = struct{}{}
13811386
senderPower, _ := table.Get(sender)
1387+
c.sendersTotalPower += senderPower
1388+
1389+
metrics.quorumParticipation.Record(context.Background(),
1390+
float64(c.sendersTotalPower)/float64(table.ScaledTotal),
1391+
metric.WithAttributes(c.attributes...))
13821392

13831393
key := value.Key()
13841394
// Keep only the first justification and best ticket.

0 commit comments

Comments
 (0)