Skip to content

Commit

Permalink
add metric for current kvstore version
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Jan 29, 2025
1 parent 0ac15d0 commit a1a312d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions module/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ type ComplianceMetrics interface {
EpochFallbackModeTriggered()
// EpochFallbackModeExited reports that EFM is no longer triggered.
EpochFallbackModeExited()
// ProtocolKVStoreVersion reports the latest finalized protocol state KVStore version.
ProtocolKVStoreVersion(version uint64)
}

type CleanerMetrics interface {
Expand Down
12 changes: 12 additions & 0 deletions module/metrics/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ComplianceCollector struct {
currentDKGPhase2FinalView prometheus.Gauge
currentDKGPhase3FinalView prometheus.Gauge
epochFallbackModeTriggered prometheus.Gauge
protocolKVStoreVersion prometheus.Gauge
}

var _ module.ComplianceMetrics = (*ComplianceCollector)(nil)
Expand Down Expand Up @@ -148,6 +149,13 @@ func NewComplianceCollector() *ComplianceCollector {
Subsystem: subsystemCompliance,
Help: "indicates whether epoch fallback mode is triggered; if >0, the fallback is triggered",
}),

protocolKVStoreVersion: promauto.NewGauge(prometheus.GaugeOpts{
Name: "protocol_kv_store_version",
Namespace: namespaceConsensus,
Subsystem: subsystemCompliance,
Help: "reports the protocol state version of the latest finalized block",
}),
}

return cc
Expand Down Expand Up @@ -214,3 +222,7 @@ func (cc *ComplianceCollector) EpochFallbackModeTriggered() {
func (cc *ComplianceCollector) EpochFallbackModeExited() {
cc.epochFallbackModeTriggered.Set(float64(0))
}

func (cc *ComplianceCollector) ProtocolKVStoreVersion(version uint64) {
cc.protocolKVStoreVersion.Set(float64(version))
}
1 change: 1 addition & 0 deletions module/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (nc *NoopCollector) CurrentDKGPhaseViews(phase1FinalView, phase2FinalView,
}
func (nc *NoopCollector) EpochFallbackModeTriggered() {}
func (nc *NoopCollector) EpochFallbackModeExited() {}
func (nc *NoopCollector) ProtocolKVStoreVersion(version uint64) {}
func (nc *NoopCollector) CacheEntries(resource string, entries uint) {}
func (nc *NoopCollector) CacheHit(resource string) {}
func (nc *NoopCollector) CacheNotFound(resource string) {}
Expand Down
5 changes: 5 additions & 0 deletions module/mock/compliance_metrics.go

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

5 changes: 5 additions & 0 deletions state/protocol/badger/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,11 @@ func (m *FollowerState) Finalize(ctx context.Context, blockID flow.Identifier) e
}
m.metrics.BlockSealed(sealedBlock)
}
protocolSnapshot, err := m.protocolKVStoreSnapshotsDB.ByID(block.Payload.ProtocolStateID)
if err != nil {
return fmt.Errorf("could not retrieve protocol snapshot for block (%x): %w", blockID, err)
}
m.metrics.ProtocolKVStoreVersion(protocolSnapshot.Version)

// apply all queued metrics
for _, updateMetric := range metrics {
Expand Down
2 changes: 2 additions & 0 deletions state/protocol/badger/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ func TestExtendEpochTransitionValid(t *testing.T) {
metrics.On("SealedHeight", mock.Anything)
metrics.On("FinalizedHeight", mock.Anything)
metrics.On("BlockFinalized", mock.Anything)
metrics.On("ProtocolKVStoreVersion", mock.Anything)

// expect epoch metric calls on bootstrap
initialCurrentEpoch := rootSnapshot.Epochs().Current()
Expand Down Expand Up @@ -3222,6 +3223,7 @@ func mockMetricsForRootSnapshot(metricsMock *mockmodule.ComplianceMetrics, rootS
metricsMock.On("CurrentDKGPhaseViews", epochSetup.DKGPhase1FinalView, epochSetup.DKGPhase2FinalView, epochSetup.DKGPhase3FinalView)
metricsMock.On("BlockSealed", mock.Anything)
metricsMock.On("BlockFinalized", mock.Anything)
metricsMock.On("ProtocolKVStoreVersion", mock.Anything)
metricsMock.On("FinalizedHeight", mock.Anything)
metricsMock.On("SealedHeight", mock.Anything)
}
Expand Down

0 comments on commit a1a312d

Please sign in to comment.