Expose DB Metrics (#3663)

* add in bolt metrics

* unregister in db teardown

* unregister in Close()

* fix clear db case

* fix test error

* gaz

* remove unregister

* remove gaz
This commit is contained in:
Nishant Das
2019-09-30 23:24:47 +08:00
committed by Raul Jordan
parent 22ddcb253d
commit 8ece8fb44b
4 changed files with 21 additions and 0 deletions

View File

@@ -1231,3 +1231,10 @@ go_repository(
sum = "h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=",
version = "v0.0.4",
)
go_repository(
name = "com_github_mdlayher_prombolt",
importpath = "github.com/mdlayher/prombolt",
sum = "h1:N257g6TTx0LxYoskSDFxvkSJ3NOZpy9IF1xQ7Gu+K8I=",
version = "v0.0.0-20161005185022-dfcf01d20ee9",
)

View File

@@ -134,5 +134,7 @@ func TestGetHeadFromYaml(t *testing.T) {
}
helpers.ClearAllCaches()
testDB.TeardownDB(t, db)
}
}

View File

@@ -27,7 +27,9 @@ go_library(
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_karlseguin_ccache//:go_default_library",
"@com_github_mdlayher_prombolt//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],

View File

@@ -7,7 +7,9 @@ import (
"github.com/boltdb/bolt"
"github.com/karlseguin/ccache"
"github.com/mdlayher/prombolt"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)
// BlockCacheSize specifies 4 epochs worth of blocks cached.
@@ -76,6 +78,7 @@ func NewKVStore(dirPath string) (*Store, error) {
}); err != nil {
return nil, err
}
err = prometheus.Register(createBoltCollector(kv.db))
return kv, err
}
@@ -85,11 +88,13 @@ func (k *Store) ClearDB() error {
if _, err := os.Stat(k.databasePath); os.IsNotExist(err) {
return nil
}
prometheus.Unregister(createBoltCollector(k.db))
return os.RemoveAll(k.databasePath)
}
// Close closes the underlying BoltDB database.
func (k *Store) Close() error {
prometheus.Unregister(createBoltCollector(k.db))
return k.db.Close()
}
@@ -106,3 +111,8 @@ func createBuckets(tx *bolt.Tx, buckets ...[]byte) error {
}
return nil
}
// createBoltCollector returns a prometheus collector specifically configured for boltdb.
func createBoltCollector(db *bolt.DB) prometheus.Collector {
return prombolt.New("boltDB", db)
}