Skip to content

Commit

Permalink
chore: stat for reporting badger db size
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsikrishnakandi committed Jan 10, 2025
1 parent b282c33 commit b3ad4ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions enterprise/reporting/event_sampler/badger_event_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import (

type BadgerEventSampler struct {
db *badger.DB
dbPath string
module string
mu sync.Mutex
ttl config.ValueLoader[time.Duration]
ctx context.Context
cancel context.CancelFunc
logger badgerLogger
wg sync.WaitGroup
sc *StatsCollector
}
Expand Down Expand Up @@ -72,9 +75,12 @@ func NewBadgerEventSampler(

es := &BadgerEventSampler{
db: db,
dbPath: dbPath,
module: module,
ttl: ttl,
ctx: ctx,
cancel: cancel,
logger: badgerLogger{log},
wg: sync.WaitGroup{},
sc: NewStatsCollector(BadgerTypeEventSampler, module, stats),
}
Expand Down Expand Up @@ -152,6 +158,15 @@ func (es *BadgerEventSampler) gcLoop() {
if err == nil {
goto again
}

lsmSize, vlogSize, totSize, err := misc.GetBadgerDBUsage(es.dbPath)
if err != nil {
es.logger.Errorf("Error while getting %s BadgerDB usage: %v", es.module, err)
continue
}
es.sc.RecordBadgerDBSize("lsm", lsmSize)
es.sc.RecordBadgerDBSize("vlog", vlogSize)
es.sc.RecordBadgerDBSize("total", totSize)
}
}

Expand Down
7 changes: 7 additions & 0 deletions enterprise/reporting/event_sampler/stats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
const (
StatReportingEventSamplerRequestsTotal = "reporting_event_sampler_requests_total"
StatReportingEventSamplerRequestDuration = "reporting_event_sampler_request_duration_seconds"
StatReportingBadgerDBSize = "reporting_badger_db_size"
)

type StatsCollector struct {
module string
stats stats.Stats
getCounter stats.Measurement
putCounter stats.Measurement
Expand All @@ -24,6 +26,7 @@ func NewStatsCollector(eventSamplerType, module string, statsFactory stats.Stats
putRequestTags := getTags(eventSamplerType, module, "put")

return &StatsCollector{
module: module,
stats: statsFactory,
getCounter: statsFactory.NewTaggedStat(StatReportingEventSamplerRequestsTotal, stats.CountType, getRequestTags),
putCounter: statsFactory.NewTaggedStat(StatReportingEventSamplerRequestsTotal, stats.CountType, putRequestTags),
Expand All @@ -48,6 +51,10 @@ func (sc *StatsCollector) RecordPutDuration(start time.Time) {
sc.putDuration.SendTiming(time.Since(start))
}

func (sc *StatsCollector) RecordBadgerDBSize(usageType string, size int64) {
sc.stats.NewTaggedStat(StatReportingBadgerDBSize, stats.GaugeType, stats.Tags{"module": sc.module, "usageType": usageType}).Gauge(size)
}

func getTags(eventSamplerType, module, operation string) stats.Tags {
return stats.Tags{"type": eventSamplerType, "module": module, "operation": operation}
}

0 comments on commit b3ad4ae

Please sign in to comment.