Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: stat for reporting badger db size #5423

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@

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 @@
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

Check warning on line 165 in enterprise/reporting/event_sampler/badger_event_sampler.go

View check run for this annotation

Codecov / codecov/patch

enterprise/reporting/event_sampler/badger_event_sampler.go#L162-L165

Added lines #L162 - L165 were not covered by tests
}
es.sc.RecordBadgerDBSize("lsm", lsmSize)
es.sc.RecordBadgerDBSize("vlog", vlogSize)
es.sc.RecordBadgerDBSize("total", totSize)

Check warning on line 169 in enterprise/reporting/event_sampler/badger_event_sampler.go

View check run for this annotation

Codecov / codecov/patch

enterprise/reporting/event_sampler/badger_event_sampler.go#L167-L169

Added lines #L167 - L169 were not covered by tests
}
}

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 @@
const (
StatReportingEventSamplerRequestsTotal = "reporting_event_sampler_requests_total"
StatReportingEventSamplerRequestDuration = "reporting_event_sampler_request_duration_seconds"
StatReportingBadgerDBSize = "reporting_badger_db_size_bytes"
)

type StatsCollector struct {
module string
stats stats.Stats
getCounter stats.Measurement
putCounter stats.Measurement
Expand All @@ -24,6 +26,7 @@
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 @@
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)

Check warning on line 55 in enterprise/reporting/event_sampler/stats_collector.go

View check run for this annotation

Codecov / codecov/patch

enterprise/reporting/event_sampler/stats_collector.go#L54-L55

Added lines #L54 - L55 were not covered by tests
}

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