Skip to content
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
26 changes: 18 additions & 8 deletions gpbft/gpbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/ipfs/go-cid"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)

Expand Down Expand Up @@ -267,11 +268,11 @@ func newInstance(
candidates: map[ECChainKey]struct{}{
input.BaseChain().Key(): {},
},
quality: newQuorumState(powerTable),
quality: newQuorumState(powerTable, attrQualityPhase),
rounds: map[uint64]*roundState{
0: newRoundState(powerTable),
0: newRoundState(0, powerTable),
},
decision: newQuorumState(powerTable),
decision: newQuorumState(powerTable, attrDecidePhase),
tracer: participant.tracer,
}, nil
}
Expand All @@ -282,11 +283,12 @@ type roundState struct {
committed *quorumState
}

func newRoundState(powerTable *PowerTable) *roundState {
func newRoundState(roundNumber uint64, powerTable *PowerTable) *roundState {
roundAttr := attrKeyRound.Int(int(roundNumber))
return &roundState{
converged: newConvergeState(),
prepared: newQuorumState(powerTable),
committed: newQuorumState(powerTable),
prepared: newQuorumState(powerTable, attrPreparePhase, roundAttr),
committed: newQuorumState(powerTable, attrCommitPhase, roundAttr),
}
}

Expand Down Expand Up @@ -791,7 +793,7 @@ func (i *instance) tryDecide() error {
func (i *instance) getRound(r uint64) *roundState {
round, ok := i.rounds[r]
if !ok {
round = newRoundState(i.powerTable)
round = newRoundState(r, i.powerTable)
i.rounds[r] = round
}
return round
Expand Down Expand Up @@ -1063,6 +1065,8 @@ type quorumState struct {
powerTable *PowerTable
// Stores justifications received for some value.
receivedJustification map[ECChainKey]*Justification
// attributes for metrics
attributes []attribute.KeyValue
}

// A chain value and the total power supporting it
Expand All @@ -1074,12 +1078,13 @@ type chainSupport struct {
}

// Creates a new, empty quorum state.
func newQuorumState(powerTable *PowerTable) *quorumState {
func newQuorumState(powerTable *PowerTable, attributes ...attribute.KeyValue) *quorumState {
return &quorumState{
senders: map[ActorID]struct{}{},
chainSupport: map[ECChainKey]chainSupport{},
powerTable: powerTable,
receivedJustification: map[ECChainKey]*Justification{},
attributes: attributes,
}
}

Expand Down Expand Up @@ -1118,6 +1123,11 @@ func (q *quorumState) receiveSender(sender ActorID) (int64, bool) {
q.senders[sender] = struct{}{}
senderPower, _ := q.powerTable.Get(sender)
q.sendersTotalPower += senderPower
if len(q.attributes) != 0 {
metrics.quorumParticipation.Record(context.Background(),
float64(q.sendersTotalPower)/float64(q.powerTable.ScaledTotal),
metric.WithAttributes(q.attributes...))
}
return senderPower, true
}

Expand Down
30 changes: 16 additions & 14 deletions gpbft/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ var (
attrCacheMiss = attribute.String("cache", "miss")
attrCacheKindMessage = attribute.String("kind", "message")
attrCacheKindJustification = attribute.String("kind", "justification")
attrKeyRound = attribute.Key("round")

metrics = struct {
phaseCounter metric.Int64Counter
roundHistogram metric.Int64Histogram
broadcastCounter metric.Int64Counter
reBroadcastCounter metric.Int64Counter
errorCounter metric.Int64Counter
currentInstance metric.Int64Gauge
currentRound metric.Int64Gauge
currentPhase metric.Int64Gauge
skipCounter metric.Int64Counter
validationCache metric.Int64Counter
phaseCounter metric.Int64Counter
roundHistogram metric.Int64Histogram
broadcastCounter metric.Int64Counter
reBroadcastCounter metric.Int64Counter
errorCounter metric.Int64Counter
currentInstance metric.Int64Gauge
currentRound metric.Int64Gauge
currentPhase metric.Int64Gauge
skipCounter metric.Int64Counter
validationCache metric.Int64Counter
quorumParticipation metric.Float64Gauge
}{
phaseCounter: measurements.Must(meter.Int64Counter("f3_gpbft_phase_counter", metric.WithDescription("Number of times phases change"))),
roundHistogram: measurements.Must(meter.Int64Histogram("f3_gpbft_round_histogram",
Expand All @@ -66,10 +68,10 @@ var (
currentPhase: measurements.Must(meter.Int64Gauge("f3_gpbft_current_phase",
metric.WithDescription("The current phase represented as numeric value of gpbft.Phase: "+
"0=INITIAL, 1=QUALITY, 2=CONVERGE, 3=PREPARE, 4=COMMIT, 5=DECIDE, and 6=TERMINATED"))),
skipCounter: measurements.Must(meter.Int64Counter("f3_gpbft_skip_counter",
metric.WithDescription("The number of times GPBFT skip either round or phase"))),
validationCache: measurements.Must(meter.Int64Counter("f3_gpbft_validation_cache",
metric.WithDescription("The number of times GPBFT validation cache resulted in hit or miss."))),
skipCounter: measurements.Must(meter.Int64Counter("f3_gpbft_skip_counter", metric.WithDescription("The number of times GPBFT skip either round or phase"))),
validationCache: measurements.Must(meter.Int64Counter("f3_gpbft_validation_cache", metric.WithDescription("The number of times GPBFT validation cache resulted in hit or miss."))),
quorumParticipation: measurements.Must(meter.Float64Gauge("f3_gpbft_participation",
metric.WithDescription("The current ratio of participation at a given round and phase (converge not tracked)."))),
}
)

Expand Down
Loading