Skip to content
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

Add Metric to Track Greatest Epoch Final View #698

Merged
merged 30 commits into from Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a708758
Add Gauge metric committed_epoch_final_view
danuio May 10, 2021
f706418
Amend metric type
danuio May 10, 2021
95f5f18
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 11, 2021
0a849a3
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 12, 2021
b1a7da6
Update committed_epoch_final_view metric for the final view
danuio May 12, 2021
4a4ba39
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 12, 2021
99de8b5
Update state/protocol/badger/mutator.go
danuio May 12, 2021
d590170
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 12, 2021
876eac5
Address PR comments
danuio May 12, 2021
02c2da3
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 12, 2021
78b473e
Update state/protocol/badger/state.go
danuio May 13, 2021
ad2e12e
Update state/protocol/badger/state.go
danuio May 13, 2021
63e8f00
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 14, 2021
861c833
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 14, 2021
7e54d4d
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 19, 2021
0c361f6
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio May 25, 2021
9e2a2b6
Address PR comments
danuio May 25, 2021
b85a3ec
Address PR comments
danuio Jun 2, 2021
ccc7b1c
Add test for metric
danuio Jun 7, 2021
02fce6d
Fix linting
danuio Jun 7, 2021
6a60ee3
Merge branch 'master' into danu/5373/add-metric-epoch-failure
jordanschalm Jun 8, 2021
bb3b659
Update state/protocol/badger/mutator.go
danuio Jun 9, 2021
72317d0
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio Jun 9, 2021
8a929c9
Merge branch 'master' into danu/5373/add-metric-epoch-failure
danuio Jun 10, 2021
c8af7ef
Update tests
danuio Jun 10, 2021
af9e42b
Merge branch 'master' into danu/5373/add-metric-epoch-failure
jordanschalm Jun 14, 2021
2096de9
add tests for open/bootstrap epoch committed metric
jordanschalm Jun 15, 2021
6ab55ca
update committed final view metric when transitioning to committed phase
jordanschalm Jun 15, 2021
0f7041d
rm debug logs & make metric test assertions more strict
jordanschalm Jun 15, 2021
b136f9b
Merge branch 'master' into danu/5373/add-metric-epoch-failure
jordanschalm Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions module/metrics.go
Expand Up @@ -48,6 +48,7 @@ type EngineMetrics interface {

type ComplianceMetrics interface {
FinalizedHeight(height uint64)
CommittedEpochFinalView(view uint64)
SealedHeight(height uint64)
BlockFinalized(*flow.Block)
BlockSealed(*flow.Block)
Expand Down
12 changes: 12 additions & 0 deletions module/metrics/compliance.go
Expand Up @@ -19,12 +19,20 @@ type ComplianceCollector struct {
sealedPayload *prometheus.CounterVec
lastBlockFinalizedAt time.Time
finalizedBlocksPerSecond prometheus.Summary
committedEpochFinalView prometheus.Gauge
}

func NewComplianceCollector() *ComplianceCollector {

cc := &ComplianceCollector{

committedEpochFinalView: promauto.NewGauge(prometheus.GaugeOpts{
Name: "committed_epoch_final_view",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "the final view of the committed epoch with the greatest counter",
}),

finalizedHeight: promauto.NewGauge(prometheus.GaugeOpts{
Name: "finalized_height",
Namespace: namespaceConsensus,
Expand Down Expand Up @@ -128,3 +136,7 @@ func (cc *ComplianceCollector) BlockSealed(block *flow.Block) {
func (cc *ComplianceCollector) BlockProposalDuration(duration time.Duration) {
cc.blockProposalDuration.Add(duration.Seconds())
}

func (cc *ComplianceCollector) CommittedEpochFinalView(view uint64) {
cc.committedEpochFinalView.Set(float64(view))
}
1 change: 1 addition & 0 deletions module/metrics/noop.go
Expand Up @@ -44,6 +44,7 @@ func (nc *NoopCollector) BlockProposed(*flow.Block)
func (nc *NoopCollector) BlockFinalized(*flow.Block) {}
func (nc *NoopCollector) BlockSealed(*flow.Block) {}
func (nc *NoopCollector) BlockProposalDuration(duration time.Duration) {}
func (nc *NoopCollector) CommittedEpochFinalView(view uint64) {}
func (nc *NoopCollector) CacheEntries(resource string, entries uint) {}
func (nc *NoopCollector) CacheHit(resource string) {}
func (nc *NoopCollector) CacheNotFound(resource string) {}
Expand Down
29 changes: 18 additions & 11 deletions state/protocol/badger/mutator.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/onflow/flow-go/engine"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/module/trace"
"github.com/onflow/flow-go/state"
"github.com/onflow/flow-go/state/protocol"
Expand All @@ -32,11 +33,13 @@ import (
// the non-consensus nodes have to perform.
type FollowerState struct {
*State
index storage.Index
payloads storage.Payloads
tracer module.Tracer
consumer protocol.Consumer
cfg Config

index storage.Index
payloads storage.Payloads
tracer module.Tracer
consumer protocol.Consumer
cfg Config
complianceMetrics module.ComplianceMetrics
danuio marked this conversation as resolved.
Show resolved Hide resolved
}

// MutableState implements a mutable protocol state. When extending the
Expand All @@ -57,12 +60,13 @@ func NewFollowerState(
consumer protocol.Consumer,
) (*FollowerState, error) {
followerState := &FollowerState{
State: state,
index: index,
payloads: payloads,
tracer: tracer,
consumer: consumer,
cfg: DefaultConfig(),
State: state,
index: index,
payloads: payloads,
tracer: tracer,
consumer: consumer,
cfg: DefaultConfig(),
complianceMetrics: metrics.NewComplianceCollector(),
danuio marked this conversation as resolved.
Show resolved Hide resolved
}
return followerState, nil
}
Expand Down Expand Up @@ -774,6 +778,9 @@ func (m *FollowerState) handleServiceEvents(block *flow.Block) ([]func(*transact
return nil, state.NewInvalidExtensionErrorf("invalid epoch commit: %s", err)
}

// update `committed_epoch_final_view` metric with new final view
m.complianceMetrics.CommittedEpochFinalView(setup.FinalView)
danuio marked this conversation as resolved.
Show resolved Hide resolved

// prevents multiple setup events for same Epoch (including multiple setup events in payload of same block)
epochStatus.NextEpoch.CommitID = ev.ID()

Expand Down
26 changes: 26 additions & 0 deletions state/protocol/badger/state.go
Expand Up @@ -51,6 +51,32 @@ func Bootstrap(
}
state := newState(metrics, db, headers, seals, results, blocks, setups, commits, statuses)

phase, err := state.Final().Phase()
if err != nil {
return nil, fmt.Errorf("could not get epoch phase from state: %w", err)
}
AlexHentschel marked this conversation as resolved.
Show resolved Hide resolved

// update metric based of epoch phase
switch phase {
case flow.EpochPhaseStaking:
case flow.EpochPhaseSetup:
danuio marked this conversation as resolved.
Show resolved Hide resolved

// if we are in Staking or Setup phase, then set the metric value to the current epoch's final view
finalView, err := state.Final().Epochs().Current().FinalView()
if err != nil {
return nil, fmt.Errorf("could not get current epoch final view from state: %w", err)
}
state.metrics.CommittedEpochFinalView(finalView)
case flow.EpochPhaseCommitted:

// if we are in Committed phase, then set the metric value to the next epoch's final view
finalView, err := state.Final().Epochs().Next().FinalView()
if err != nil {
return nil, fmt.Errorf("could not get next epoch final view from state: %w", err)
}
state.metrics.CommittedEpochFinalView(finalView)
}
danuio marked this conversation as resolved.
Show resolved Hide resolved

if err := isValidRootSnapshot(root); err != nil {
return nil, fmt.Errorf("cannot bootstrap invalid root snapshot: %w", err)
}
Expand Down