mirror of
https://github.com/safing/portbase
synced 2025-04-23 02:39:09 +00:00
Fix enabling metric persistence
This commit is contained in:
parent
3b22f8497d
commit
be48ba38c8
2 changed files with 6 additions and 15 deletions
metrics
|
@ -6,7 +6,6 @@ import (
|
|||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/modules"
|
||||
)
|
||||
|
||||
|
@ -36,7 +35,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
module = modules.Register("metrics", prep, start, stop, "config", "database", "api", "base")
|
||||
module = modules.Register("metrics", prep, start, stop, "config", "database", "api")
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
|
@ -71,10 +70,6 @@ func start() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := loadPersistentMetrics(); err != nil {
|
||||
log.Errorf("metrics: failed to load persistent metrics: %s", err)
|
||||
}
|
||||
|
||||
if pushOption() != "" {
|
||||
module.StartServiceWorker("metric pusher", 0, metricsWriter)
|
||||
}
|
||||
|
@ -121,6 +116,10 @@ func register(m Metric) error {
|
|||
// Set flag that first metric is now registered.
|
||||
firstMetricRegistered = true
|
||||
|
||||
if module.Status() < modules.StatusStarting {
|
||||
return fmt.Errorf("registering metric %q too early", m.ID())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ var (
|
|||
})
|
||||
|
||||
// ErrAlreadyInitialized is returned when trying to initialize an option
|
||||
// more than once.
|
||||
// more than once or if the time window for initializing is over.
|
||||
ErrAlreadyInitialized = errors.New("already initialized")
|
||||
)
|
||||
|
||||
|
@ -52,14 +52,6 @@ func EnableMetricPersistence(key string) error {
|
|||
|
||||
// Set storage key.
|
||||
storageKey = key
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadPersistentMetrics() error {
|
||||
// Abort if storage is not enabled.
|
||||
if storageInit.SetToIf(false, true) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Load metrics from storage.
|
||||
var err error
|
||||
|
|
Loading…
Add table
Reference in a new issue