[#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>
support/v0.30
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

@ -109,8 +109,8 @@ 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 {
msg string
cfgPrefix string cfgPrefix string
oldPrefix string
handler func() http.Handler handler func() http.Handler
}{ }{
{"pprof", "profiler", httputil.Handler}, {"pprof", "profiler", httputil.Handler},
@ -120,22 +120,41 @@ func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server {
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") {
log.Info(item.msg + " is disabled, skip") if !cfg.GetBool(item.oldPrefix + ".enabled") {
continue 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") 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(
cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"), timeout,
), ),
), ),
) )

View File

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

View File

@ -7,7 +7,8 @@ import (
) )
const ( const (
subsection = "metrics" 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
@ -21,7 +22,10 @@ const (
// //
// 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 {
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 // 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. // Returns ShutdownTimeoutDefault if the value is not positive duration.
func ShutdownTimeout(c *config.Config) time.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 { if v > 0 {
return v return v
} }
@ -42,7 +49,10 @@ func ShutdownTimeout(c *config.Config) time.Duration {
// //
// 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 {
v := config.StringSafe(c.Sub(subsection), "address") s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.StringSafe(s, "address")
if v != "" { if v != "" {
return v return v
} }

View File

@ -7,7 +7,8 @@ import (
) )
const ( const (
subsection = "profiler" 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
@ -21,7 +22,10 @@ const (
// //
// 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 {
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 // 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. // Returns ShutdownTimeoutDefault if the value is not positive duration.
func ShutdownTimeout(c *config.Config) time.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 { if v > 0 {
return v return v
} }
@ -42,7 +49,10 @@ func ShutdownTimeout(c *config.Config) time.Duration {
// //
// 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 {
v := config.StringSafe(c.Sub(subsection), "address") s := c.Sub(subsection)
s.SetDefault(c.Sub(subsectionOld))
v := config.StringSafe(s, "address")
if v != "" { if v != "" {
return v return v
} }

View File

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

View File

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

View File

@ -82,13 +82,13 @@ NEOFS_IR_CONTRACTS_ALPHABET_DOBRO=e6122b65d45c8feeb04455d67814394c147ed4d1
NEOFS_IR_CONTRACTS_ALPHABET_YEST=cdbca5cb5d48a4472923844d0e3ee6328cf86d38 NEOFS_IR_CONTRACTS_ALPHABET_YEST=cdbca5cb5d48a4472923844d0e3ee6328cf86d38
NEOFS_IR_CONTRACTS_ALPHABET_ZHIVETE=f584699bc2ff457d339fb09f16217042c1a42101 NEOFS_IR_CONTRACTS_ALPHABET_ZHIVETE=f584699bc2ff457d339fb09f16217042c1a42101
NEOFS_IR_PROFILER_ENABLED=true NEOFS_IR_PPROF_ENABLED=true
NEOFS_IR_PROFILER_ADDRESS=localhost:6060 NEOFS_IR_PPROF_ADDRESS=localhost:6060
NEOFS_IR_PROFILER_SHUTDOWN_TIMEOUT=30s NEOFS_IR_PPROF_SHUTDOWN_TIMEOUT=30s
NEOFS_IR_METRICS_ENABLED=true NEOFS_IR_PROMETHEUS_ENABLED=true
NEOFS_IR_METRICS_ADDRESS=localhost:9090 NEOFS_IR_PROMETHEUS_ADDRESS=localhost:9090
NEOFS_IR_METRICS_SHUTDOWN_TIMEOUT=30s NEOFS_IR_PROMETHEUS_SHUTDOWN_TIMEOUT=30s
NEOFS_IR_SETTLEMENT_BASIC_INCOME_RATE=100 NEOFS_IR_SETTLEMENT_BASIC_INCOME_RATE=100
NEOFS_IR_SETTLEMENT_AUDIT_FEE=100 NEOFS_IR_SETTLEMENT_AUDIT_FEE=100

View File

@ -123,12 +123,12 @@ contracts:
yest: cdbca5cb5d48a4472923844d0e3ee6328cf86d38 # Optional: override address of yest contract in sidechain yest: cdbca5cb5d48a4472923844d0e3ee6328cf86d38 # Optional: override address of yest contract in sidechain
zhivete: f584699bc2ff457d339fb09f16217042c1a42101 # Optional: override address of zhivete contract in sidechain zhivete: f584699bc2ff457d339fb09f16217042c1a42101 # Optional: override address of zhivete contract in sidechain
profiler: pprof:
enabled: true enabled: true
address: localhost:6060 # Endpoint for application pprof profiling; disabled by default address: localhost:6060 # Endpoint for application pprof profiling; disabled by default
shutdown_timeout: 30s # Timeout for profiling HTTP server graceful shutdown shutdown_timeout: 30s # Timeout for profiling HTTP server graceful shutdown
metrics: prometheus:
enabled: true enabled: true
address: localhost:9090 # Endpoint for application prometheus metrics; disabled by default address: localhost:9090 # Endpoint for application prometheus metrics; disabled by default
shutdown_timeout: 30s # Timeout for metrics HTTP server graceful shutdown shutdown_timeout: 30s # Timeout for metrics HTTP server graceful shutdown

View File

@ -1,12 +1,12 @@
logger: logger:
level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal" level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"
profiler: pprof:
enabled: true enabled: true
address: localhost:6060 # endpoint for Node profiling address: localhost:6060 # endpoint for Node profiling
shutdown_timeout: 15s # timeout for profiling HTTP server graceful shutdown shutdown_timeout: 15s # timeout for profiling HTTP server graceful shutdown
metrics: prometheus:
enabled: true enabled: true
address: localhost:9090 # endpoint for Node metrics address: localhost:9090 # endpoint for Node metrics
shutdown_timeout: 15s # timeout for metrics HTTP server graceful shutdown shutdown_timeout: 15s # timeout for metrics HTTP server graceful shutdown

View File

@ -39,7 +39,7 @@ storage:
logger: logger:
level: info level: info
metrics: prometheus:
enabled: true enabled: true
address: localhost:9090 address: localhost:9090
shutdown_timeout: 15s shutdown_timeout: 15s

View File

@ -23,7 +23,7 @@ node:
attribute_0: Deployed:SelfHosted attribute_0: Deployed:SelfHosted
attribute_1: User-Agent:NeoFS\/0.27 attribute_1: User-Agent:NeoFS\/0.27
metrics: prometheus:
enabled: true enabled: true
address: localhost:9090 address: localhost:9090
shutdown_timeout: 15s shutdown_timeout: 15s