chore(v2): add example of setting store metrics (#22819)
This commit is contained in:
parent
57b4d3003b
commit
19fbd0b855
@ -167,11 +167,19 @@ func NewSimApp[T transaction.Tx](
|
||||
return nil, fmt.Errorf("store builder did not return a db")
|
||||
}
|
||||
|
||||
/**** Store Metrics ****/
|
||||
/*
|
||||
// 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
|
||||
}
|
||||
|
||||
@ -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) {}
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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…
Reference in New Issue
Block a user