feat(store/v2): basic metrics (#18529)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"cosmossdk.io/store/v2"
|
||||
"cosmossdk.io/store/v2/kv/branch"
|
||||
"cosmossdk.io/store/v2/kv/trace"
|
||||
"cosmossdk.io/store/v2/metrics"
|
||||
"cosmossdk.io/store/v2/pruning"
|
||||
)
|
||||
|
||||
@@ -57,6 +59,9 @@ type Store struct {
|
||||
|
||||
// pruningManager manages pruning of the SS and SC backends
|
||||
pruningManager *pruning.Manager
|
||||
|
||||
// telemetry reflects a telemetry agent responsible for emitting metrics (if any)
|
||||
telemetry metrics.StoreMetrics
|
||||
}
|
||||
|
||||
func New(
|
||||
@@ -64,6 +69,7 @@ func New(
|
||||
initVersion uint64,
|
||||
ss store.VersionedDatabase,
|
||||
sc store.Committer,
|
||||
m metrics.StoreMetrics,
|
||||
) (store.RootStore, error) {
|
||||
rootKVStore, err := branch.New(defaultStoreKey, ss)
|
||||
if err != nil {
|
||||
@@ -79,6 +85,7 @@ func New(
|
||||
stateCommitment: sc,
|
||||
rootKVStore: rootKVStore,
|
||||
pruningManager: pruningManager,
|
||||
telemetry: m,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -162,6 +169,11 @@ func (s *Store) GetLatestVersion() (uint64, error) {
|
||||
}
|
||||
|
||||
func (s *Store) Query(storeKey string, version uint64, key []byte, prove bool) (store.QueryResult, error) {
|
||||
if s.telemetry != nil {
|
||||
now := time.Now()
|
||||
s.telemetry.MeasureSince(now, "root_store", "query")
|
||||
}
|
||||
|
||||
val, err := s.stateStore.Get(storeKey, version, key)
|
||||
if err != nil {
|
||||
return store.QueryResult{}, err
|
||||
@@ -206,6 +218,11 @@ func (s *Store) GetBranchedKVStore(_ string) store.BranchedKVStore {
|
||||
}
|
||||
|
||||
func (s *Store) LoadLatestVersion() error {
|
||||
if s.telemetry != nil {
|
||||
now := time.Now()
|
||||
s.telemetry.MeasureSince(now, "root_store", "load_latest_version")
|
||||
}
|
||||
|
||||
lv, err := s.GetLatestVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -215,6 +232,11 @@ func (s *Store) LoadLatestVersion() error {
|
||||
}
|
||||
|
||||
func (s *Store) LoadVersion(version uint64) error {
|
||||
if s.telemetry != nil {
|
||||
now := time.Now()
|
||||
s.telemetry.MeasureSince(now, "root_store", "load_version")
|
||||
}
|
||||
|
||||
return s.loadVersion(version)
|
||||
}
|
||||
|
||||
@@ -282,6 +304,11 @@ func (s *Store) Branch() store.BranchedRootStore {
|
||||
// by constructing a CommitInfo object, which in turn creates and writes a batch
|
||||
// of the current changeset to the SC tree.
|
||||
func (s *Store) WorkingHash() ([]byte, error) {
|
||||
if s.telemetry != nil {
|
||||
now := time.Now()
|
||||
s.telemetry.MeasureSince(now, "root_store", "working_hash")
|
||||
}
|
||||
|
||||
if s.workingHash == nil {
|
||||
if err := s.writeSC(); err != nil {
|
||||
return nil, err
|
||||
@@ -306,6 +333,11 @@ func (s *Store) Write() {
|
||||
//
|
||||
// Note, Commit() commits SC and SC synchronously.
|
||||
func (s *Store) Commit() ([]byte, error) {
|
||||
if s.telemetry != nil {
|
||||
now := time.Now()
|
||||
s.telemetry.MeasureSince(now, "root_store", "commit")
|
||||
}
|
||||
|
||||
if s.workingHash == nil {
|
||||
return nil, fmt.Errorf("working hash is nil; must call WorkingHash() before Commit()")
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *RootStoreTestSuite) SetupTest() {
|
||||
sc, err := commitment.NewCommitStore(map[string]commitment.Tree{"default": tree}, noopLog)
|
||||
s.Require().NoError(err)
|
||||
|
||||
rs, err := New(noopLog, 1, ss, sc)
|
||||
rs, err := New(noopLog, 1, ss, sc, nil)
|
||||
s.Require().NoError(err)
|
||||
|
||||
rs.SetTracer(io.Discard)
|
||||
|
||||
Reference in New Issue
Block a user