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

chore(v2): add example of setting store metrics #22819

Merged
merged 3 commits into from
Dec 10, 2024
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
10 changes: 9 additions & 1 deletion simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,19 @@ func NewSimApp[T transaction.Tx](
return nil, fmt.Errorf("store builder did not return a db")
}

/**** Store Metrics ****/
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
/*
// In order to set store metrics uncomment the below
storeMetrics, err := metrics.NewMetrics([][]string{{"module", "store"}})
if err != nil {
return nil, err
}
app.store.SetMetrics(storeMetrics)
*/
/**** Module Options ****/

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
app.RegisterUpgradeHandlers()

if err = app.LoadLatest(); err != nil {
return nil, err
}
Expand Down
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{})
}
Loading