Skip to content

Commit

Permalink
include BytesIngested in write metric
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Oct 7, 2024
1 parent d111100 commit a915ecf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions db/pebble/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type DB struct {
listener db.EventListener

// Operational Counters for Compaction (Atomic Variables and Others)
activeComp int // Current number of active compactions
compStartTime time.Time // The start time of the earliest currently-active compaction
compTime atomic.Int64 // Total time spent in compaction in ns
level0Comp atomic.Uint32 // Total number of level-zero compactions
nonLevel0Comp atomic.Uint32 // Total number of non level-zero compactions
numActiveComps int // Current number of active compactions
compStartTime time.Time // The start time of the earliest currently-active compaction
compTime atomic.Int64 // Total time spent in compaction in ns
level0Comp atomic.Uint32 // Total number of level-zero compactions
nonLevel0Comp atomic.Uint32 // Total number of non level-zero compactions

// Write Delay Operational Counters (Atomic Variables)
writeDelayStartTime time.Time // The start time of the latest write stall
Expand All @@ -53,7 +53,7 @@ type DB struct {
compTimeMeter prometheus.Counter // Total time spent in database compaction
compReadMeter prometheus.Counter // Total bytes read during compaction
compWriteMeter prometheus.Counter // Total bytes written during compaction
memCompGauge prometheus.Gauge // Tracks the amount of memory allocated for compaction
memCompGauge prometheus.Gauge // Tracks the number of memory allocations
level0CompGauge prometheus.Gauge // Tracks the number of level-zero compactions
nonlevel0CompGauge prometheus.Gauge // Tracks the number of non level-zero compactions
seekCompGauge prometheus.Gauge // Tracks the number of table compaction caused by read opt
Expand Down Expand Up @@ -246,7 +246,7 @@ func (d *DB) enableMetrics() db.DB {
}

func (d *DB) onCompactionBegin(info pebble.CompactionInfo) { //nolint:gocritic // Used by pebble's event listener
if d.activeComp == 0 {
if d.numActiveComps == 0 {
d.compStartTime = time.Now()

Check warning on line 250 in db/pebble/db.go

View check run for this annotation

Codecov / codecov/patch

db/pebble/db.go#L248-L250

Added lines #L248 - L250 were not covered by tests
}
l0 := info.Input[0]
Expand All @@ -255,16 +255,16 @@ func (d *DB) onCompactionBegin(info pebble.CompactionInfo) { //nolint:gocritic /
} else {
d.nonLevel0Comp.Add(1)

Check warning on line 256 in db/pebble/db.go

View check run for this annotation

Codecov / codecov/patch

db/pebble/db.go#L252-L256

Added lines #L252 - L256 were not covered by tests
}
d.activeComp++
d.numActiveComps++

Check warning on line 258 in db/pebble/db.go

View check run for this annotation

Codecov / codecov/patch

db/pebble/db.go#L258

Added line #L258 was not covered by tests
}

func (d *DB) onCompactionEnd(info pebble.CompactionInfo) { //nolint:gocritic // Used by pebble's event listener
if d.activeComp == 1 {
if d.numActiveComps == 1 {
d.compTime.Add(int64(time.Since(d.compStartTime)))
} else if d.activeComp == 0 {
} else if d.numActiveComps == 0 {
panic("should not happen")

Check warning on line 265 in db/pebble/db.go

View check run for this annotation

Codecov / codecov/patch

db/pebble/db.go#L261-L265

Added lines #L261 - L265 were not covered by tests
}
d.activeComp--
d.numActiveComps--

Check warning on line 267 in db/pebble/db.go

View check run for this annotation

Codecov / codecov/patch

db/pebble/db.go#L267

Added line #L267 was not covered by tests
}

func (d *DB) onWriteStallBegin(b pebble.WriteStallBeginInfo) {
Expand Down Expand Up @@ -314,6 +314,7 @@ func (d *DB) StartMetricsCollection(ctx context.Context, refresh time.Duration)
levelMetrics := metrics.Levels[j]
nWrite += int64(levelMetrics.BytesCompacted)
nWrite += int64(levelMetrics.BytesFlushed)
nWrite += int64(levelMetrics.BytesIngested)
compWrite += int64(levelMetrics.BytesCompacted)
compRead += int64(levelMetrics.BytesRead)
}
Expand Down

0 comments on commit a915ecf

Please sign in to comment.