Skip to content

Commit

Permalink
Remove db namespace (#3068)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored May 31, 2024
1 parent cb2a177 commit 0e9ab78
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 68 deletions.
4 changes: 2 additions & 2 deletions database/leveldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type config struct {
}

// New returns a wrapped LevelDB object.
func New(file string, configBytes []byte, log logging.Logger, namespace string, reg prometheus.Registerer) (database.Database, error) {
func New(file string, configBytes []byte, log logging.Logger, reg prometheus.Registerer) (database.Database, error) {
parsedConfig := config{
BlockCacheCapacity: DefaultBlockCacheSize,
DisableSeeksCompaction: true,
Expand Down Expand Up @@ -236,7 +236,7 @@ func New(file string, configBytes []byte, log logging.Logger, namespace string,
closeCh: make(chan struct{}),
}
if parsedConfig.MetricUpdateFrequency > 0 {
metrics, err := newMetrics(namespace, reg)
metrics, err := newMetrics(reg)
if err != nil {
// Drop any close error to report the original error
_ = db.Close()
Expand Down
4 changes: 2 additions & 2 deletions database/leveldb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestInterface(t *testing.T) {
for name, test := range database.Tests {
t.Run(name, func(t *testing.T) {
folder := t.TempDir()
db, err := New(folder, nil, logging.NoLog{}, "", prometheus.NewRegistry())
db, err := New(folder, nil, logging.NoLog{}, prometheus.NewRegistry())
require.NoError(t, err)

test(t, db)
Expand All @@ -30,7 +30,7 @@ func TestInterface(t *testing.T) {

func newDB(t testing.TB) database.Database {
folder := t.TempDir()
db, err := New(folder, nil, logging.NoLog{}, "", prometheus.NewRegistry())
db, err := New(folder, nil, logging.NoLog{}, prometheus.NewRegistry())
require.NoError(t, err)
return db
}
Expand Down
92 changes: 37 additions & 55 deletions database/leveldb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,117 +62,99 @@ type metrics struct {
priorStats, currentStats *leveldb.DBStats
}

func newMetrics(namespace string, reg prometheus.Registerer) (metrics, error) {
func newMetrics(reg prometheus.Registerer) (metrics, error) {
m := metrics{
writesDelayedCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "writes_delayed",
Help: "number of cumulative writes that have been delayed due to compaction",
Name: "writes_delayed",
Help: "number of cumulative writes that have been delayed due to compaction",
}),
writesDelayedDuration: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "writes_delayed_duration",
Help: "amount of time (in ns) that writes have been delayed due to compaction",
Name: "writes_delayed_duration",
Help: "amount of time (in ns) that writes have been delayed due to compaction",
}),
writeIsDelayed: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "write_delayed",
Help: "1 if there is currently a write that is being delayed due to compaction",
Name: "write_delayed",
Help: "1 if there is currently a write that is being delayed due to compaction",
}),

aliveSnapshots: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "alive_snapshots",
Help: "number of currently alive snapshots",
Name: "alive_snapshots",
Help: "number of currently alive snapshots",
}),
aliveIterators: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "alive_iterators",
Help: "number of currently alive iterators",
Name: "alive_iterators",
Help: "number of currently alive iterators",
}),

ioWrite: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "io_write",
Help: "cumulative amount of io write during compaction",
Name: "io_write",
Help: "cumulative amount of io write during compaction",
}),
ioRead: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "io_read",
Help: "cumulative amount of io read during compaction",
Name: "io_read",
Help: "cumulative amount of io read during compaction",
}),

blockCacheSize: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "block_cache_size",
Help: "total size of cached blocks",
Name: "block_cache_size",
Help: "total size of cached blocks",
}),
openTables: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "open_tables",
Help: "number of currently opened tables",
Name: "open_tables",
Help: "number of currently opened tables",
}),

levelTableCount: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "table_count",
Help: "number of tables allocated by level",
Name: "table_count",
Help: "number of tables allocated by level",
},
levelLabels,
),
levelSize: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "size",
Help: "amount of bytes allocated by level",
Name: "size",
Help: "amount of bytes allocated by level",
},
levelLabels,
),
levelDuration: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "duration",
Help: "amount of time (in ns) spent in compaction by level",
Name: "duration",
Help: "amount of time (in ns) spent in compaction by level",
},
levelLabels,
),
levelReads: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "reads",
Help: "amount of bytes read during compaction by level",
Name: "reads",
Help: "amount of bytes read during compaction by level",
},
levelLabels,
),
levelWrites: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "writes",
Help: "amount of bytes written during compaction by level",
Name: "writes",
Help: "amount of bytes written during compaction by level",
},
levelLabels,
),

memCompactions: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "mem_comps",
Help: "total number of memory compactions performed",
Name: "mem_comps",
Help: "total number of memory compactions performed",
}),
level0Compactions: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "level_0_comps",
Help: "total number of level 0 compactions performed",
Name: "level_0_comps",
Help: "total number of level 0 compactions performed",
}),
nonLevel0Compactions: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "non_level_0_comps",
Help: "total number of non-level 0 compactions performed",
Name: "non_level_0_comps",
Help: "total number of non-level 0 compactions performed",
}),
seekCompactions: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "seek_comps",
Help: "total number of seek compactions performed",
Name: "seek_comps",
Help: "total number of seek compactions performed",
}),

priorStats: &leveldb.DBStats{},
Expand Down
2 changes: 1 addition & 1 deletion database/pebbledb/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestBatch(t *testing.T) {
require := require.New(t)
dirName := t.TempDir()

db, err := New(dirName, nil, logging.NoLog{}, "", prometheus.NewRegistry())
db, err := New(dirName, nil, logging.NoLog{}, prometheus.NewRegistry())
require.NoError(err)

batchIntf := db.NewBatch()
Expand Down
2 changes: 1 addition & 1 deletion database/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Config struct {
}

// TODO: Add metrics
func New(file string, configBytes []byte, log logging.Logger, _ string, _ prometheus.Registerer) (database.Database, error) {
func New(file string, configBytes []byte, log logging.Logger, _ prometheus.Registerer) (database.Database, error) {
cfg := DefaultConfig
if len(configBytes) > 0 {
if err := json.Unmarshal(configBytes, &cfg); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion database/pebbledb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func newDB(t testing.TB) *Database {
folder := t.TempDir()
db, err := New(folder, nil, logging.NoLog{}, "pebble", prometheus.NewRegistry())
db, err := New(folder, nil, logging.NoLog{}, prometheus.NewRegistry())
require.NoError(t, err)
return db.(*Database)
}
Expand Down
16 changes: 11 additions & 5 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const (
ipResolutionTimeout = 30 * time.Second

apiNamespace = constants.PlatformName + metric.NamespaceSeparator + "api"
dbNamespace = constants.PlatformName + metric.NamespaceSeparator + "db_internal"
networkNamespace = constants.PlatformName + metric.NamespaceSeparator + "network"
)

Expand Down Expand Up @@ -729,23 +730,29 @@ func (n *Node) Dispatch() error {
*/

func (n *Node) initDatabase() error {
dbRegisterer, err := metrics.MakeAndRegister(
n.MetricsGatherer,
dbNamespace,
)
if err != nil {
return err
}

// start the db
switch n.Config.DatabaseConfig.Name {
case leveldb.Name:
// Prior to v1.10.15, the only on-disk database was leveldb, and its
// files went to [dbPath]/[networkID]/v1.4.5.
dbPath := filepath.Join(n.Config.DatabaseConfig.Path, version.CurrentDatabase.String())
var err error
n.DB, err = leveldb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, "db_internal", n.MetricsRegisterer)
n.DB, err = leveldb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, dbRegisterer)
if err != nil {
return fmt.Errorf("couldn't create %s at %s: %w", leveldb.Name, dbPath, err)
}
case memdb.Name:
n.DB = memdb.New()
case pebbledb.Name:
dbPath := filepath.Join(n.Config.DatabaseConfig.Path, "pebble")
var err error
n.DB, err = pebbledb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, "db_internal", n.MetricsRegisterer)
n.DB, err = pebbledb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, dbRegisterer)
if err != nil {
return fmt.Errorf("couldn't create %s at %s: %w", pebbledb.Name, dbPath, err)
}
Expand All @@ -763,7 +770,6 @@ func (n *Node) initDatabase() error {
n.DB = versiondb.New(n.DB)
}

var err error
n.DB, err = meterdb.New("db", n.MetricsRegisterer, n.DB)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion vms/platformvm/validators/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func BenchmarkGetValidatorSet(b *testing.B) {
b.TempDir(),
nil,
logging.NoLog{},
"",
prometheus.NewRegistry(),
)
require.NoError(err)
Expand Down

0 comments on commit 0e9ab78

Please sign in to comment.