[#1654] ir, node: Drop deprecated profiler and metrics config sections

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-03 20:50:01 +03:00 committed by Pavel Karpy
parent 713cfa5610
commit 0a60524a9c
6 changed files with 30 additions and 68 deletions

View file

@ -37,11 +37,11 @@ func newConfig(path string) (*viper.Viper, error) {
func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("logger.level", "info")
cfg.SetDefault("profiler.address", "localhost:6060")
cfg.SetDefault("profiler.shutdown_timeout", "30s")
cfg.SetDefault("pprof.address", "localhost:6060")
cfg.SetDefault("pprof.shutdown_timeout", "30s")
cfg.SetDefault("metrics.address", "localhost:9090")
cfg.SetDefault("metrics.shutdown_timeout", "30s")
cfg.SetDefault("prometheus.address", "localhost:9090")
cfg.SetDefault("prometheus.shutdown_timeout", "30s")
cfg.SetDefault("without_mainnet", false)

View file

@ -110,51 +110,31 @@ func main() {
func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server {
items := []struct {
cfgPrefix string
oldPrefix string
handler func() http.Handler
}{
{"pprof", "profiler", httputil.Handler},
{"prometheus", "metrics", promhttp.Handler},
{"pprof", httputil.Handler},
{"prometheus", promhttp.Handler},
}
httpServers := make([]*httputil.Server, 0, len(items))
for _, item := range items {
var printDeprecatedMsg bool
if !cfg.GetBool(item.cfgPrefix + ".enabled") {
if !cfg.GetBool(item.oldPrefix + ".enabled") {
log.Info(item.cfgPrefix + " is disabled, skip")
continue
}
printDeprecatedMsg = true
}
// The default value is set only for the deprecated prefix, so empty string can be returned.
addr := cfg.GetString(item.cfgPrefix + ".address")
if addr == "" {
addr = cfg.GetString(item.oldPrefix + ".address")
printDeprecatedMsg = true
}
var prm httputil.Prm
prm.Address = addr
prm.Handler = item.handler()
timeout := cfg.GetDuration(item.cfgPrefix + ".shutdown_timeout")
if timeout == 0 {
timeout = cfg.GetDuration(item.oldPrefix + ".shutdown_timeout")
printDeprecatedMsg = true
}
if printDeprecatedMsg {
log.Info(item.oldPrefix + " config section is deprecated, use " + item.cfgPrefix)
}
httpServers = append(httpServers,
httputil.New(prm,
httputil.WithShutdownTimeout(
timeout,
cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"),
),
),
)

View file

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

View file

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

View file

@ -1,12 +1,12 @@
NEOFS_LOGGER_LEVEL=debug
NEOFS_PROFILER_ENABLED=true
NEOFS_PROFILER_ADDRESS=localhost:6060
NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s
NEOFS_PPROF_ENABLED=true
NEOFS_PPROF_ADDRESS=localhost:6060
NEOFS_PPROF_SHUTDOWN_TIMEOUT=15s
NEOFS_METRICS_ENABLED=true
NEOFS_METRICS_ADDRESS=localhost:9090
NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s
NEOFS_PROMETHEUS_ENABLED=true
NEOFS_PROMETHEUS_ADDRESS=localhost:9090
NEOFS_PROMETHEUS_SHUTDOWN_TIMEOUT=15s
# Node section
NEOFS_NODE_KEY=./wallet.key

View file

@ -2,12 +2,12 @@
"logger": {
"level": "debug"
},
"profiler": {
"pprof": {
"enabled": true,
"address": "localhost:6060",
"shutdown_timeout": "15s"
},
"metrics": {
"prometheus": {
"enabled": true,
"address": "localhost:9090",
"shutdown_timeout": "15s"