mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 04:00:05 +00:00
Add validator bolt db metric collector (#7982)
* Validator db: add metrics collector * Use the right library * Go fmt * Fix tests
This commit is contained in:
parent
04615cb97b
commit
1b1b36497f
@ -19,6 +19,8 @@ go_library(
|
||||
"//shared/fileutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prysmaticlabs_prombbolt//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_etcd_go_bbolt//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
prombolt "github.com/prysmaticlabs/prombbolt"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
@ -23,6 +25,7 @@ type Store struct {
|
||||
|
||||
// Close closes the underlying boltdb database.
|
||||
func (store *Store) Close() error {
|
||||
prometheus.Unregister(createBoltCollector(store.db))
|
||||
return store.db.Close()
|
||||
}
|
||||
|
||||
@ -38,6 +41,7 @@ func (store *Store) ClearDB() error {
|
||||
if _, err := os.Stat(store.databasePath); os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
prometheus.Unregister(createBoltCollector(store.db))
|
||||
return os.Remove(filepath.Join(store.databasePath, ProtectionDbFileName))
|
||||
}
|
||||
|
||||
@ -103,6 +107,8 @@ func NewKVStore(dirPath string, pubKeys [][48]byte) (*Store, error) {
|
||||
}
|
||||
}
|
||||
|
||||
err = prometheus.Register(createBoltCollector(kv.db))
|
||||
|
||||
return kv, err
|
||||
}
|
||||
|
||||
@ -128,3 +134,8 @@ func (store *Store) Size() (int64, error) {
|
||||
})
|
||||
return size, err
|
||||
}
|
||||
|
||||
// createBoltCollector returns a prometheus collector specifically configured for boltdb.
|
||||
func createBoltCollector(db *bolt.DB) prometheus.Collector {
|
||||
return prombolt.New("boltDB", db)
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ func TestSaveProposalHistoryForSlot_Overwrites(t *testing.T) {
|
||||
|
||||
require.NotNil(t, signingRoot)
|
||||
require.DeepEqual(t, tt.signingRoot, signingRoot[:], "Expected DB to keep object the same")
|
||||
require.NoError(t, db.Close(), "Failed to close database")
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,6 +152,7 @@ func TestPruneProposalHistoryBySlot_OK(t *testing.T) {
|
||||
require.NoError(t, err, "Failed to get proposal history")
|
||||
require.DeepEqual(t, signedRoot, sr[:], "Unexpected difference in bytes for epoch %d", slot)
|
||||
}
|
||||
require.NoError(t, db.Close(), "Failed to close database")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user