mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-12 09:05:39 +00:00
* bugfix: change action request cnt type as Counter * bugfix: fix type of act req count and typo * bugfix: change to correct type of act req in TC --------- Co-authored-by: wushuzh <wushuzh@outlook.com>
49 lines
1005 B
Go
49 lines
1005 B
Go
package config
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"os"
|
|
"path/filepath"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
metricConfigActionCount = promauto.NewGauge(prometheus.GaugeOpts{
|
|
Name: "olivetin_config_action_count",
|
|
Help: "The number of actions in the config file",
|
|
})
|
|
|
|
metricConfigReloadedCount = promauto.NewCounter(prometheus.CounterOpts{
|
|
Name: "olivetin_config_reloaded_count",
|
|
Help: "The number of times the config has been reloaded",
|
|
})
|
|
|
|
listeners []func()
|
|
)
|
|
|
|
func AddListener(l func()) {
|
|
listeners = append(listeners, l)
|
|
}
|
|
|
|
func Reload(cfg *Config) {
|
|
if err := viper.UnmarshalExact(&cfg); err != nil {
|
|
log.Errorf("Config unmarshal error %+v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
metricConfigReloadedCount.Inc()
|
|
metricConfigActionCount.Set(float64(len(cfg.Actions)))
|
|
|
|
cfg.SetDir(filepath.Dir(viper.ConfigFileUsed()))
|
|
cfg.Sanitize()
|
|
|
|
for _, l := range listeners {
|
|
l()
|
|
}
|
|
}
|