Skip to content

Commit

Permalink
create noop metrics system
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Dec 10, 2024
1 parent 6f129ae commit 3f643dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions store/v2/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ func NewMetrics(labels [][]string) (Metrics, error) {
func (m Metrics) MeasureSince(start time.Time, keys ...string) {
metrics.MeasureSinceWithLabels(keys, start.UTC(), m.Labels)
}

// NoOpMetrics is a no-op implementation of the StoreMetrics interface
type NoOpMetrics struct{}

// NewNoOpMetrics returns a new instance of the NoOpMetrics
func NewNoOpMetrics() NoOpMetrics {
return NoOpMetrics{}
}

// MeasureSince is a no-op implementation of the StoreMetrics interface to avoid time.Now() calls
func (m NoOpMetrics) MeasureSince(start time.Time, keys ...string) {}
3 changes: 2 additions & 1 deletion store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"cosmossdk.io/store/v2/commitment/mem"
"cosmossdk.io/store/v2/db"
"cosmossdk.io/store/v2/internal"
"cosmossdk.io/store/v2/metrics"
"cosmossdk.io/store/v2/pruning"
)

Expand Down Expand Up @@ -127,5 +128,5 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) {
}

pm := pruning.NewManager(sc, storeOpts.SCPruningOption)
return New(opts.SCRawDB, opts.Logger, sc, pm, nil, nil)
return New(opts.SCRawDB, opts.Logger, sc, pm, nil, metrics.NoOpMetrics{})
}

0 comments on commit 3f643dd

Please sign in to comment.