[#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) { func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("logger.level", "info") cfg.SetDefault("logger.level", "info")
cfg.SetDefault("profiler.address", "localhost:6060") cfg.SetDefault("pprof.address", "localhost:6060")
cfg.SetDefault("profiler.shutdown_timeout", "30s") cfg.SetDefault("pprof.shutdown_timeout", "30s")
cfg.SetDefault("metrics.address", "localhost:9090") cfg.SetDefault("prometheus.address", "localhost:9090")
cfg.SetDefault("metrics.shutdown_timeout", "30s") cfg.SetDefault("prometheus.shutdown_timeout", "30s")
cfg.SetDefault("without_mainnet", false) cfg.SetDefault("without_mainnet", false)

View file

@ -110,51 +110,31 @@ func main() {
func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server { func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server {
items := []struct { items := []struct {
cfgPrefix string cfgPrefix string
oldPrefix string
handler func() http.Handler handler func() http.Handler
}{ }{
{"pprof", "profiler", httputil.Handler}, {"pprof", httputil.Handler},
{"prometheus", "metrics", promhttp.Handler}, {"prometheus", promhttp.Handler},
} }
httpServers := make([]*httputil.Server, 0, len(items)) httpServers := make([]*httputil.Server, 0, len(items))
for _, item := range items { for _, item := range items {
var printDeprecatedMsg bool
if !cfg.GetBool(item.cfgPrefix + ".enabled") { if !cfg.GetBool(item.cfgPrefix + ".enabled") {
if !cfg.GetBool(item.oldPrefix + ".enabled") { log.Info(item.cfgPrefix + " is disabled, skip")
log.Info(item.cfgPrefix + " is disabled, skip") continue
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") addr := cfg.GetString(item.cfgPrefix + ".address")
if addr == "" {
addr = cfg.GetString(item.oldPrefix + ".address")
printDeprecatedMsg = true
}
var prm httputil.Prm var prm httputil.Prm
prm.Address = addr prm.Address = addr
prm.Handler = item.handler() 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, httpServers = append(httpServers,
httputil.New(prm, httputil.New(prm,
httputil.WithShutdownTimeout( httputil.WithShutdownTimeout(
timeout, cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"),
), ),
), ),
) )

View file

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

View file

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

View file

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

View file

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