metrics: Init -> Enable

This commit is contained in:
Martin Holst Swende 2024-11-27 05:18:53 +01:00
parent 9e22de7c47
commit df9fdbc58a
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
5 changed files with 11 additions and 13 deletions

View file

@ -1973,7 +1973,7 @@ func SetupMetrics(cfg *metrics.Config) {
if !cfg.Enabled {
return
}
metrics.Init(true)
metrics.Enable()
log.Info("Enabling metrics collection")
var (
enableExport = cfg.EnableInfluxDB

View file

@ -33,7 +33,7 @@ import (
)
func TestMain(m *testing.M) {
metrics.Init(true)
metrics.Enable()
os.Exit(m.Run())
}

View file

@ -22,17 +22,12 @@ func Enabled() bool {
return metricsEnabled
}
// Init enables the metrics system.
// Enable enables the metrics system.
// The Enabled-flag is expected to be set, once, during startup, but toggling off and on
// is not supported: YMMV.
// Init is not safe to call concurrently. It has no effect if it was already called.
func Init(enabled bool) {
metricsEnabled = enabled
if initRan {
return
}
initRan = true
// TODO: Maybe start the ticker for exp delays, and things like that.
// is not supported,
// Enable is not safe to call concurrently. It has no effect if it was already called.
func Enable() {
metricsEnabled = true
}
var threadCreateProfile = pprof.Lookup("threadcreate")

View file

@ -27,7 +27,7 @@ import (
)
func TestMain(m *testing.M) {
metrics.Init(true)
metrics.Enable()
os.Exit(m.Run())
}

View file

@ -62,6 +62,9 @@ func (t *ResettingTimer) Time(f func()) {
// Record the duration of an event.
func (t *ResettingTimer) Update(d time.Duration) {
if !metricsEnabled {
return
}
t.mutex.Lock()
defer t.mutex.Unlock()
t.values = append(t.values, int64(d))