diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c34f40aca1..1a4e137a86c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (baseapp) [#14417](https://github.com/cosmos/cosmos-sdk/pull/14417) `SetStreamingService` accepts appOptions, AppCodec and Storekeys needed to set streamers. * Store pacakge no longer has a dependency on baseapp. * (store) [#14438](https://github.com/cosmos/cosmos-sdk/pull/14438) Pass logger from baseapp to store. +* (store) [#14439](https://github.com/cosmos/cosmos-sdk/pull/14439) Remove global metric gatherer from store. + * By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`. ### State Machine Breaking diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index d1c1a61a29e5..2b7679058caa 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -16,6 +16,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" + storemetrics "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/snapshots" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -156,7 +157,7 @@ func NewBaseApp( logger: logger, name: name, db: db, - cms: store.NewCommitMultiStore(db, logger), + cms: store.NewCommitMultiStore(db, logger, storemetrics.NewNoOpMetrics()), // by default we use a no-op metric gather in store storeLoader: DefaultStoreLoader, grpcQueryRouter: NewGRPCQueryRouter(), msgServiceRouter: NewMsgServiceRouter(), diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 6e6512b3d37e..e757dd224885 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/snapshots" @@ -217,7 +218,7 @@ func TestSetLoader(t *testing.T) { } initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db, log.NewNopLogger()) + rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) key := sdk.NewKVStoreKey(storeKey) @@ -237,7 +238,7 @@ func TestSetLoader(t *testing.T) { } checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db, log.NewNopLogger()) + rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) key := sdk.NewKVStoreKey(storeKey) diff --git a/baseapp/options.go b/baseapp/options.go index 098a0360819c..e78295917c38 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" @@ -297,3 +298,12 @@ func (app *BaseApp) SetPrepareProposal(handler sdk.PrepareProposalHandler) { app.prepareProposal = handler } + +// SetStoreMetrics sets the prepare proposal function for the BaseApp. +func (app *BaseApp) SetStoreMetrics(gatherer metrics.StoreMetrics) { + if app.sealed { + panic("SetStoreMetrics() on sealed BaseApp") + } + + app.cms.SetMetrics(gatherer) +} diff --git a/server/mock/store.go b/server/mock/store.go index b8248f442c16..6233463973da 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -6,6 +6,7 @@ import ( dbm "github.com/cosmos/cosmos-db" protoio "github.com/cosmos/gogoproto/io" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -54,6 +55,10 @@ func (ms multiStore) AddListeners(key storetypes.StoreKey, listeners []storetype panic("not implemented") } +func (ms multiStore) SetMetrics(metrics.StoreMetrics) { + panic("not implemented") +} + func (ms multiStore) ListeningEnabled(key storetypes.StoreKey) bool { panic("not implemented") } diff --git a/store/cachekv/benchmark_test.go b/store/cachekv/benchmark_test.go index d61ee8bcb4aa..943a5b20254b 100644 --- a/store/cachekv/benchmark_test.go +++ b/store/cachekv/benchmark_test.go @@ -6,6 +6,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" @@ -18,7 +19,7 @@ func DoBenchmarkDeepContextStack(b *testing.B, depth int) { key := storetypes.NewKVStoreKey("test") db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db, log.NewNopLogger()) + cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) cms.LoadLatestVersion() ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/store/iavl/store.go b/store/iavl/store.go index 60757e1e7cc5..b42bf791b678 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "io" - "time" ics23 "github.com/confio/ics23/go" dbm "github.com/cosmos/cosmos-db" @@ -16,10 +15,10 @@ import ( sdkerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/internal/kv" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/tracekv" "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/telemetry" ) const ( @@ -36,22 +35,23 @@ var ( // Store Implements types.KVStore and CommitKVStore. type Store struct { - tree Tree - logger log.Logger + tree Tree + logger log.Logger + metrics metrics.StoreMetrics } // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { - return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastNode) +func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastNode, metrics) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // to the one given. Internally, it will load the store's version (id) from the // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. -func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { +func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}, disableFastNode) if err != nil { return nil, err @@ -87,8 +87,9 @@ func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKe } return &Store{ - tree: tree, - logger: logger, + tree: tree, + logger: logger, + metrics: metrics, }, nil } @@ -100,7 +101,8 @@ func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKe // passed into iavl.MutableTree func UnsafeNewStore(tree *iavl.MutableTree) *Store { return &Store{ - tree: tree, + tree: tree, + metrics: metrics.NewNoOpMetrics(), } } @@ -120,14 +122,15 @@ func (st *Store) GetImmutable(version int64) (*Store, error) { } return &Store{ - tree: &immutableTree{iTree}, + tree: &immutableTree{iTree}, + metrics: st.metrics, }, nil } // Commit commits the current store state and returns a CommitID with the new // version and hash. func (st *Store) Commit() types.CommitID { - defer telemetry.MeasureSince(time.Now(), "store", "iavl", "commit") + defer st.metrics.MeasureSince("store", "iavl", "commit") hash, version, err := st.tree.SaveVersion() if err != nil { @@ -202,7 +205,7 @@ func (st *Store) Set(key, value []byte) { // Implements types.KVStore. func (st *Store) Get(key []byte) []byte { - defer telemetry.MeasureSince(time.Now(), "store", "iavl", "get") + defer st.metrics.MeasureSince("store", "iavl", "get") value, err := st.tree.Get(key) if err != nil { panic(err) @@ -212,7 +215,7 @@ func (st *Store) Get(key []byte) []byte { // Implements types.KVStore. func (st *Store) Has(key []byte) (exists bool) { - defer telemetry.MeasureSince(time.Now(), "store", "iavl", "has") + defer st.metrics.MeasureSince("store", "iavl", "has") has, err := st.tree.Has(key) if err != nil { panic(err) @@ -222,7 +225,7 @@ func (st *Store) Has(key []byte) (exists bool) { // Implements types.KVStore. func (st *Store) Delete(key []byte) { - defer telemetry.MeasureSince(time.Now(), "store", "iavl", "delete") + defer st.metrics.MeasureSince("store", "iavl", "delete") st.tree.Remove(key) } @@ -311,7 +314,7 @@ func getHeight(tree Tree, req abci.RequestQuery) int64 { // if you care to have the latest data to see a tx results, you must // explicitly set the height you want to see func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) { - defer telemetry.MeasureSince(time.Now(), "store", "iavl", "query") + defer st.metrics.MeasureSince("store", "iavl", "query") if len(req.Data) == 0 { return types.QueryResult(sdkerrors.Wrap(types.ErrTxDecode, "query cannot be zero length"), false) diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index 1e0ef27257c7..fda6bb9e3ce8 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/cachekv" "github.com/cosmos/cosmos-sdk/store/internal/kv" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/types" ) @@ -99,17 +100,17 @@ func TestLoadStore(t *testing.T) { require.Equal(t, string(hcStore.Get([]byte("hello"))), "ciao") // Querying a new store at some previous non-pruned height H - newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, false, DefaultIAVLCacheSize, false) + newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, false, DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) require.NoError(t, err) require.Equal(t, string(newHStore.Get([]byte("hello"))), "hallo") // Querying a new store at some previous pruned height Hp - newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, false, DefaultIAVLCacheSize, false) + newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, false, DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) require.NoError(t, err) require.Equal(t, string(newHpStore.Get([]byte("hello"))), "hola") // Querying a new store at current height H - newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, false, DefaultIAVLCacheSize, false) + newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, false, DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) require.NoError(t, err) require.Equal(t, string(newHcStore.Get([]byte("hello"))), "ciao") } diff --git a/store/metrics/telemetry.go b/store/metrics/telemetry.go new file mode 100644 index 000000000000..bdea79ffd0f0 --- /dev/null +++ b/store/metrics/telemetry.go @@ -0,0 +1,56 @@ +package metrics + +import ( + "time" + + "github.com/armon/go-metrics" +) + +// StoreMetrics defines the set of metrics for the store package +type StoreMetrics interface { + MeasureSince(keys ...string) +} + +var ( + _ StoreMetrics = Metrics{} + _ StoreMetrics = NoOpMetrics{} +) + +// Metrics defines the metrics wrapper for the store package +type Metrics struct { + Labels []metrics.Label +} + +// NewMetrics returns a new instance of the Metrics with labels set by the node operator +func NewMetrics(labels [][]string) Metrics { + gatherer := Metrics{} + + if numGlobalLables := len(labels); numGlobalLables > 0 { + parsedGlobalLabels := make([]metrics.Label, numGlobalLables) + for i, gl := range labels { + parsedGlobalLabels[i] = metrics.Label{Name: gl[0], Value: gl[1]} + } + + gatherer.Labels = parsedGlobalLabels + } + + return gatherer +} + +// MeasureSince provides a wrapper functionality for emitting a a time measure +// metric with global labels (if any). +func (m Metrics) MeasureSince(keys ...string) { + start := time.Now() + 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(keys ...string) {} diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 65ce35162db5..6d21dc1fabc8 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -9,13 +9,14 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/store/iavl" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/types" ) func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false) + iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) @@ -58,7 +59,7 @@ func TestVerifyIAVLStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) @@ -113,7 +114,7 @@ func TestVerifyMultiStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProofAbsence(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) diff --git a/store/rootmulti/snapshot_test.go b/store/rootmulti/snapshot_test.go index 02735991d25c..e4f177196001 100644 --- a/store/rootmulti/snapshot_test.go +++ b/store/rootmulti/snapshot_test.go @@ -15,6 +15,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/store/iavl" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" @@ -23,7 +24,7 @@ import ( ) func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) *rootmulti.Store { - multiStore := rootmulti.NewStore(db, log.NewNopLogger()) + multiStore := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) r := rand.New(rand.NewSource(49872768940)) // Fixed seed for deterministic tests keys := []*types.KVStoreKey{} @@ -55,7 +56,7 @@ func newMultiStoreWithGeneratedData(db dbm.DB, stores uint8, storeKeys uint64) * } func newMultiStoreWithMixedMounts(db dbm.DB) *rootmulti.Store { - store := rootmulti.NewStore(db, log.NewNopLogger()) + store := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) store.MountStoreWithDB(types.NewKVStoreKey("iavl1"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl2"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl3"), types.StoreTypeIAVL, nil) @@ -235,7 +236,7 @@ func benchmarkMultistoreSnapshot(b *testing.B, stores uint8, storeKeys uint64) { b.StartTimer() for i := 0; i < b.N; i++ { - target := rootmulti.NewStore(dbm.NewMemDB(), log.NewNopLogger()) + target := rootmulti.NewStore(dbm.NewMemDB(), log.NewNopLogger(), metrics.NewNoOpMetrics()) for _, key := range source.StoreKeysByName() { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } @@ -270,7 +271,7 @@ func benchmarkMultistoreSnapshotRestore(b *testing.B, stores uint8, storeKeys ui b.StartTimer() for i := 0; i < b.N; i++ { - target := rootmulti.NewStore(dbm.NewMemDB(), log.NewNopLogger()) + target := rootmulti.NewStore(dbm.NewMemDB(), log.NewNopLogger(), metrics.NewNoOpMetrics()) for _, key := range source.StoreKeysByName() { target.MountStoreWithDB(key, types.StoreTypeIAVL, nil) } diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index f9a394b266ff..8e6ba77da2c9 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -22,6 +22,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/iavl" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/mem" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/pruning" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" @@ -74,6 +75,8 @@ type Store struct { interBlockCache types.MultiStorePersistentCache listeners map[types.StoreKey][]types.WriteListener + + metrics metrics.StoreMetrics } var ( @@ -85,7 +88,7 @@ var ( // store will be created with a PruneNothing pruning strategy by default. After // a store is created, KVStores must be mounted and finally LoadLatestVersion or // LoadVersion must be called. -func NewStore(db dbm.DB, logger log.Logger) *Store { +func NewStore(db dbm.DB, logger log.Logger, metricGatherer metrics.StoreMetrics) *Store { return &Store{ db: db, logger: logger, @@ -97,6 +100,7 @@ func NewStore(db dbm.DB, logger log.Logger) *Store { listeners: make(map[types.StoreKey][]types.WriteListener), removalMap: make(map[types.StoreKey]bool), pruningManager: pruning.NewManager(db, logger), + metrics: metricGatherer, } } @@ -112,6 +116,11 @@ func (rs *Store) SetPruning(pruningOpts pruningtypes.PruningOptions) { rs.pruningManager.SetOptions(pruningOpts) } +// SetMetrics sets the metrics gatherer for the store package +func (rs *Store) SetMetrics(metrics metrics.StoreMetrics) { + rs.metrics = metrics +} + // SetSnapshotInterval sets the interval at which the snapshots are taken. // It is used by the store to determine which heights to retain until after the snapshot is complete. func (rs *Store) SetSnapshotInterval(snapshotInterval uint64) { @@ -921,9 +930,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID var err error if params.initialVersion == 0 { - store, err = iavl.LoadStore(db, rs.logger, key, id, rs.lazyLoading, rs.iavlCacheSize, rs.iavlDisableFastNode) + store, err = iavl.LoadStore(db, rs.logger, key, id, rs.lazyLoading, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) } else { - store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode) + store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) } if err != nil { diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index 2482495bee68..84dd8189c94c 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -15,13 +15,14 @@ import ( "github.com/cosmos/cosmos-sdk/store/iavl" sdkmaps "github.com/cosmos/cosmos-sdk/store/internal/maps" "github.com/cosmos/cosmos-sdk/store/listenkv" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/types" ) func TestStoreType(t *testing.T) { db := dbm.NewMemDB() - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, db) } @@ -44,7 +45,7 @@ func TestGetCommitKVStore(t *testing.T) { func TestStoreMount(t *testing.T) { db := dbm.NewMemDB() - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") @@ -834,7 +835,7 @@ var ( ) func newMultiStoreWithMounts(db dbm.DB, pruningOpts pruningtypes.PruningOptions) *Store { - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) store.SetPruning(pruningOpts) store.MountStoreWithDB(testStoreKey1, types.StoreTypeIAVL, nil) @@ -845,7 +846,7 @@ func newMultiStoreWithMounts(db dbm.DB, pruningOpts pruningtypes.PruningOptions) } func newMultiStoreWithModifiedMounts(db dbm.DB, pruningOpts pruningtypes.PruningOptions) (*Store, *types.StoreUpgrades) { - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) store.SetPruning(pruningOpts) store.MountStoreWithDB(types.NewKVStoreKey("store1"), types.StoreTypeIAVL, nil) @@ -969,7 +970,7 @@ func (stub *commitKVStoreStub) Commit() types.CommitID { func prepareStoreMap() map[types.StoreKey]types.CommitKVStore { var db dbm.DB = dbm.NewMemDB() - store := NewStore(db, log.NewNopLogger()) + store := NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) store.MountStoreWithDB(types.NewKVStoreKey("iavl1"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewKVStoreKey("iavl2"), types.StoreTypeIAVL, nil) store.MountStoreWithDB(types.NewTransientStoreKey("trans1"), types.StoreTypeTransient, nil) diff --git a/store/store.go b/store/store.go index fd5caeb4da30..c119b76ad884 100644 --- a/store/store.go +++ b/store/store.go @@ -5,12 +5,13 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/store/cache" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/types" ) -func NewCommitMultiStore(db dbm.DB, logger log.Logger) types.CommitMultiStore { - return rootmulti.NewStore(db, logger) +func NewCommitMultiStore(db dbm.DB, logger log.Logger, metricGatherer metrics.StoreMetrics) types.CommitMultiStore { + return rootmulti.NewStore(db, logger, metricGatherer) } func NewCommitKVStoreCacheManager() types.MultiStorePersistentCache { diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 360f139a9903..06a3e3ac0119 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -8,12 +8,13 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/store/iavl" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/types" ) func newMemTestKVStore(t *testing.T) types.KVStore { db := dbm.NewMemDB() - store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false) + store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false, metrics.NewNoOpMetrics()) require.NoError(t, err) return store } diff --git a/store/types/store.go b/store/types/store.go index 6fe1d9959a06..f461a8f2c985 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -8,6 +8,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/store/internal/kv" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/store/snapshots/types" ) @@ -197,6 +198,9 @@ type CommitMultiStore interface { // AddListeners adds WriteListeners for the KVStore belonging to the provided StoreKey // It appends the listeners to a current set, if one already exists AddListeners(key StoreKey, listeners []WriteListener) + + // SetMetrics sets the metrics for the KVStore + SetMetrics(metrics metrics.StoreMetrics) } //---------subsp------------------------------- diff --git a/testutil/context.go b/testutil/context.go index 12d7f6c763a6..33e5f78879ad 100644 --- a/testutil/context.go +++ b/testutil/context.go @@ -9,6 +9,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -16,7 +17,7 @@ import ( // DefaultContext creates a sdk.Context with a fresh MemDB that can be used in tests. func DefaultContext(key storetypes.StoreKey, tkey storetypes.StoreKey) sdk.Context { db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db, log.NewNopLogger()) + cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) err := cms.LoadLatestVersion() @@ -36,7 +37,7 @@ type TestContext struct { func DefaultContextWithDB(t *testing.T, key storetypes.StoreKey, tkey storetypes.StoreKey) TestContext { db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db, log.NewNopLogger()) + cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) err := cms.LoadLatestVersion() diff --git a/types/store_test.go b/types/store_test.go index e74e5ae30424..107b349cb2ea 100644 --- a/types/store_test.go +++ b/types/store_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/store/metrics" "github.com/cosmos/cosmos-sdk/store/rootmulti" "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -109,7 +110,7 @@ func (s *storeTestSuite) TestDiffKVStores() { func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) { db := dbm.NewMemDB() - ms := rootmulti.NewStore(db, log.NewNopLogger()) + ms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) key1 := types.NewKVStoreKey("store1") key2 := types.NewKVStoreKey("store2") diff --git a/x/group/internal/orm/testsupport.go b/x/group/internal/orm/testsupport.go index db3eaf34fc66..f13ddd899e5f 100644 --- a/x/group/internal/orm/testsupport.go +++ b/x/group/internal/orm/testsupport.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/store/gaskv" + "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -21,7 +22,7 @@ func NewMockContext() *MockContext { db := dbm.NewMemDB() return &MockContext{ db: dbm.NewMemDB(), - store: store.NewCommitMultiStore(db, log.NewNopLogger()), + store: store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()), } } diff --git a/x/group/keeper/invariants_test.go b/x/group/keeper/invariants_test.go index 98456f58d70b..8e189574327e 100644 --- a/x/group/keeper/invariants_test.go +++ b/x/group/keeper/invariants_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,7 +40,7 @@ func (s *invariantTestSuite) SetupSuite() { cdc := codec.NewProtoCodec(interfaceRegistry) key := sdk.NewKVStoreKey(group.ModuleName) db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db, log.NewNopLogger()) + cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) _ = cms.LoadLatestVersion() sdkCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 20519e9cdc21..e2cc2bd190a1 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -14,6 +14,7 @@ import ( "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/store/metrics" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params/testutil" @@ -32,7 +33,7 @@ type SubspaceTestSuite struct { func (suite *SubspaceTestSuite) SetupTest() { db := dbm.NewMemDB() - ms := store.NewCommitMultiStore(db, log.NewNopLogger()) + ms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) ms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, db) ms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) suite.NoError(ms.LoadLatestVersion()) diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 62beb7525c60..c0649f1c361b 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -13,6 +13,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/store/metrics" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/store/rootmulti" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -30,7 +31,7 @@ func defaultLogger() log.Logger { } func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db, log.NewNopLogger()) + rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) @@ -47,7 +48,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { } func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) { - rs := rootmulti.NewStore(db, log.NewNopLogger()) + rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) key := sdk.NewKVStoreKey(storeKey) rs.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil)