[#1602] config: Rename metrics and profiler sections

Depracate old names and remove them in the next release.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-13 12:26:40 +03:00 committed by fyrchik
parent ac46d1a11f
commit 3a0b06d5da
11 changed files with 66 additions and 28 deletions

View file

@ -324,8 +324,6 @@ func initCfg(path string) *cfg {
if metricsconfig.Enabled(c.appCfg) {
c.metricsCollector = metrics.NewStorageMetrics()
netState.metrics = c.metricsCollector
} else {
c.log.Info("prometheus metrics are disabled")
}
c.onShutdown(c.clientCache.CloseAll) // clean up connections

View file

@ -7,7 +7,8 @@ import (
)
const (
subsection = "metrics"
subsection = "prometheus"
subsectionOld = "metrics"
// ShutdownTimeoutDefault is a default value for metrics HTTP service timeout.
ShutdownTimeoutDefault = 30 * time.Second
@ -21,7 +22,10 @@ const (
//
// Returns false if the value is missing or invalid.
func Enabled(c *config.Config) bool {
return config.BoolSafe(c.Sub(subsection), "enabled")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
return config.BoolSafe(s, "enabled")
}
// ShutdownTimeout returns the value of "shutdown_timeout" config parameter
@ -29,7 +33,10 @@ func Enabled(c *config.Config) bool {
//
// Returns ShutdownTimeoutDefault if the value is not positive duration.
func ShutdownTimeout(c *config.Config) time.Duration {
v := config.DurationSafe(c.Sub(subsection), "shutdown_timeout")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.DurationSafe(s, "shutdown_timeout")
if v > 0 {
return v
}
@ -42,7 +49,10 @@ func ShutdownTimeout(c *config.Config) time.Duration {
//
// Returns AddressDefault if the value is not set.
func Address(c *config.Config) string {
v := config.StringSafe(c.Sub(subsection), "address")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.StringSafe(s, "address")
if v != "" {
return v
}

View file

@ -7,7 +7,8 @@ import (
)
const (
subsection = "profiler"
subsection = "pprof"
subsectionOld = "profiler"
// ShutdownTimeoutDefault is a default value for profiler HTTP service timeout.
ShutdownTimeoutDefault = 30 * time.Second
@ -21,7 +22,10 @@ const (
//
// Returns false if the value is missing or invalid.
func Enabled(c *config.Config) bool {
return config.BoolSafe(c.Sub(subsection), "enabled")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
return config.BoolSafe(s, "enabled")
}
// ShutdownTimeout returns the value of "shutdown_timeout" config parameter
@ -29,7 +33,10 @@ func Enabled(c *config.Config) bool {
//
// Returns ShutdownTimeoutDefault if the value is not positive duration.
func ShutdownTimeout(c *config.Config) time.Duration {
v := config.DurationSafe(c.Sub(subsection), "shutdown_timeout")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.DurationSafe(s, "shutdown_timeout")
if v > 0 {
return v
}
@ -42,7 +49,10 @@ func ShutdownTimeout(c *config.Config) time.Duration {
//
// Returns AddressDefault if the value is not set.
func Address(c *config.Config) string {
v := config.StringSafe(c.Sub(subsection), "address")
s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.StringSafe(s, "address")
if v != "" {
return v
}

View file

@ -78,8 +78,8 @@ func initApp(c *cfg) {
initAndLog(c, "reputation", initReputationService)
initAndLog(c, "notification", initNotifications)
initAndLog(c, "object", initObjectService)
initAndLog(c, "profiler", initProfiler)
initAndLog(c, "metrics", initMetrics)
initAndLog(c, "pprof", initProfiler)
initAndLog(c, "prometheus", initMetrics)
initAndLog(c, "control", initControlService)
initAndLog(c, "storage engine", func(c *cfg) {

View file

@ -11,6 +11,7 @@ import (
func initMetrics(c *cfg) {
if !metricsconfig.Enabled(c.appCfg) {
c.log.Info("prometheus is disabled")
return
}