Skip to content

Commit

Permalink
Add NopMetrics
Browse files Browse the repository at this point in the history
No-op metrics implementation for benchmarking etc.

Signed-off-by: Jussi Maki <[email protected]>
  • Loading branch information
joamaki committed Mar 25, 2024
1 parent 0bf81f7 commit 1cf3205
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
12 changes: 8 additions & 4 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ var logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
}))

func newTestDB(t testing.TB, secondaryIndexers ...Indexer[testObject]) (*DB, RWTable[testObject], *ExpVarMetrics) {
metrics := NewExpVarMetrics(false)
db, table := newTestDBWithMetrics(t, metrics, secondaryIndexers...)
return db, table, metrics
}

func newTestDBWithMetrics(t testing.TB, metrics Metrics, secondaryIndexers ...Indexer[testObject]) (*DB, RWTable[testObject]) {
var (
db *DB
)
Expand All @@ -79,8 +85,6 @@ func newTestDB(t testing.TB, secondaryIndexers ...Indexer[testObject]) (*DB, RWT
)
require.NoError(t, err, "NewTable[testObject]")

metrics := NewExpVarMetrics(false)

h := hive.NewWithOptions(
hive.Options{Logger: logger},

Expand All @@ -100,7 +104,7 @@ func newTestDB(t testing.TB, secondaryIndexers ...Indexer[testObject]) (*DB, RWT
t.Cleanup(func() {
assert.NoError(t, h.Stop(context.TODO()))
})
return db, table, metrics
return db, table
}

func TestDB_Insert_SamePointer(t *testing.T) {
Expand Down Expand Up @@ -136,7 +140,7 @@ func TestDB_Insert_SamePointer(t *testing.T) {
func TestDB_LowerBound_ByRevision(t *testing.T) {
t.Parallel()

db, table, _ := newTestDB(t, tagsIndex)
db, table := newTestDBWithMetrics(t, &NopMetrics{}, tagsIndex)

{
txn := db.WriteTxn(table)
Expand Down
40 changes: 40 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,43 @@ func (m *ExpVarMetrics) WriteTxnTableAcquisition(name string, acquire time.Durat
}

var _ Metrics = &ExpVarMetrics{}

type NopMetrics struct{}

// DeleteTrackerCount implements Metrics.
func (*NopMetrics) DeleteTrackerCount(tableName string, numTrackers int) {
}

// GraveyardCleaningDuration implements Metrics.
func (*NopMetrics) GraveyardCleaningDuration(tableName string, duration time.Duration) {
}

// GraveyardLowWatermark implements Metrics.
func (*NopMetrics) GraveyardLowWatermark(tableName string, lowWatermark uint64) {
}

// GraveyardObjectCount implements Metrics.
func (*NopMetrics) GraveyardObjectCount(tableName string, numDeletedObjects int) {
}

// ObjectCount implements Metrics.
func (*NopMetrics) ObjectCount(tableName string, numObjects int) {
}

// Revision implements Metrics.
func (*NopMetrics) Revision(tableName string, revision uint64) {
}

// WriteTxnDuration implements Metrics.
func (*NopMetrics) WriteTxnDuration(goPackage string, s []string, acquire time.Duration) {
}

// WriteTxnTableAcquisition implements Metrics.
func (*NopMetrics) WriteTxnTableAcquisition(tableName string, acquire time.Duration) {
}

// WriteTxnTotalAcquisition implements Metrics.
func (*NopMetrics) WriteTxnTotalAcquisition(goPackage string, tables []string, acquire time.Duration) {
}

var _ Metrics = &NopMetrics{}

0 comments on commit 1cf3205

Please sign in to comment.