From 6f129aec5b1a94e660c7d6913f2d488be71d43c1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 10 Dec 2024 11:25:43 -0800 Subject: [PATCH 1/3] add example of how to set metrics for store --- simapp/v2/app_di.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index bd0a39472a1c..c2718eb244f1 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -171,7 +171,15 @@ func NewSimApp[T transaction.Tx]( // RegisterUpgradeHandlers is used for registering any on-chain upgrades. app.RegisterUpgradeHandlers() - + /**** 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) + */ if err = app.LoadLatest(); err != nil { return nil, err } From 3f643ddaab035d1a7af769c607dd658606187567 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 10 Dec 2024 11:28:05 -0800 Subject: [PATCH 2/3] create noop metrics system --- store/v2/metrics/metrics.go | 11 +++++++++++ store/v2/root/factory.go | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/store/v2/metrics/metrics.go b/store/v2/metrics/metrics.go index bea5eda8a4d2..a964c89dbf2c 100644 --- a/store/v2/metrics/metrics.go +++ b/store/v2/metrics/metrics.go @@ -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) {} diff --git a/store/v2/root/factory.go b/store/v2/root/factory.go index 36eadf2382bc..c908432c9a29 100644 --- a/store/v2/root/factory.go +++ b/store/v2/root/factory.go @@ -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{}) } From e7df892016b76d994d56aa548aaa023aa9d06b1f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 10 Dec 2024 12:12:22 -0800 Subject: [PATCH 3/3] adress comment --- simapp/v2/app_di.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index c2718eb244f1..e78708807b33 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -167,10 +167,6 @@ func NewSimApp[T transaction.Tx]( return nil, fmt.Errorf("store builder did not return a db") } - /**** Module Options ****/ - - // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - app.RegisterUpgradeHandlers() /**** Store Metrics ****/ /* // In order to set store metrics uncomment the below @@ -180,6 +176,10 @@ func NewSimApp[T transaction.Tx]( } 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 }