[#1602] config: Enable metrics
and profiler
services with a flag
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
12dc5c3395
commit
ac46d1a11f
16 changed files with 53 additions and 15 deletions
|
@ -5,6 +5,8 @@ Changelog for NeoFS Node
|
|||
|
||||
### Added
|
||||
|
||||
- Profiler and metrics services now should be enabled with a separate flag
|
||||
|
||||
### Changed
|
||||
|
||||
- Require SG members to be unique (#1490)
|
||||
|
|
|
@ -62,7 +62,7 @@ func main() {
|
|||
|
||||
intErr := make(chan error) // internal inner ring errors
|
||||
|
||||
httpServers := initHTTPServers(cfg)
|
||||
httpServers := initHTTPServers(cfg, log)
|
||||
|
||||
innerRing, err := innerring.New(ctx, log, cfg, intErr)
|
||||
exitErr(err)
|
||||
|
@ -107,23 +107,26 @@ func main() {
|
|||
log.Info("application stopped")
|
||||
}
|
||||
|
||||
func initHTTPServers(cfg *viper.Viper) []*httputil.Server {
|
||||
func initHTTPServers(cfg *viper.Viper, log *logger.Logger) []*httputil.Server {
|
||||
items := []struct {
|
||||
msg string
|
||||
cfgPrefix string
|
||||
handler func() http.Handler
|
||||
}{
|
||||
{"profiler", httputil.Handler},
|
||||
{"metrics", promhttp.Handler},
|
||||
{"pprof", "profiler", httputil.Handler},
|
||||
{"prometheus", "metrics", promhttp.Handler},
|
||||
}
|
||||
|
||||
httpServers := make([]*httputil.Server, 0, len(items))
|
||||
|
||||
for _, item := range items {
|
||||
addr := cfg.GetString(item.cfgPrefix + ".address")
|
||||
if addr == "" {
|
||||
if !cfg.GetBool(item.cfgPrefix + ".enabled") {
|
||||
log.Info(item.msg + " is disabled, skip")
|
||||
continue
|
||||
}
|
||||
|
||||
addr := cfg.GetString(item.cfgPrefix + ".address")
|
||||
|
||||
var prm httputil.Prm
|
||||
|
||||
prm.Address = addr
|
||||
|
|
|
@ -321,9 +321,11 @@ func initCfg(path string) *cfg {
|
|||
|
||||
user.IDFromKey(&c.ownerIDFromKey, key.PrivateKey.PublicKey)
|
||||
|
||||
if metricsconfig.Address(c.appCfg) != "" {
|
||||
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
|
||||
|
|
|
@ -13,9 +13,17 @@ const (
|
|||
ShutdownTimeoutDefault = 30 * time.Second
|
||||
|
||||
// AddressDefault is a default value for metrics HTTP service endpoint.
|
||||
AddressDefault = ""
|
||||
AddressDefault = "localhost:9090"
|
||||
)
|
||||
|
||||
// Enabled returns the value of "enabled" config parameter
|
||||
// from "metrics" section.
|
||||
//
|
||||
// Returns false if the value is missing or invalid.
|
||||
func Enabled(c *config.Config) bool {
|
||||
return config.BoolSafe(c.Sub(subsection), "enabled")
|
||||
}
|
||||
|
||||
// ShutdownTimeout returns the value of "shutdown_timeout" config parameter
|
||||
// from "metrics" section.
|
||||
//
|
||||
|
|
|
@ -17,6 +17,7 @@ func TestMetricsSection(t *testing.T) {
|
|||
|
||||
require.Equal(t, metricsconfig.ShutdownTimeoutDefault, to)
|
||||
require.Equal(t, metricsconfig.AddressDefault, addr)
|
||||
require.False(t, metricsconfig.Enabled(configtest.EmptyConfig()))
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
@ -27,6 +28,7 @@ func TestMetricsSection(t *testing.T) {
|
|||
|
||||
require.Equal(t, 15*time.Second, to)
|
||||
require.Equal(t, "localhost:9090", addr)
|
||||
require.True(t, metricsconfig.Enabled(c))
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
|
|
@ -13,9 +13,17 @@ const (
|
|||
ShutdownTimeoutDefault = 30 * time.Second
|
||||
|
||||
// AddressDefault is a default value for profiler HTTP service endpoint.
|
||||
AddressDefault = ""
|
||||
AddressDefault = "localhost:6060"
|
||||
)
|
||||
|
||||
// Enabled returns the value of "enabled" config parameter
|
||||
// from "profiler" section.
|
||||
//
|
||||
// Returns false if the value is missing or invalid.
|
||||
func Enabled(c *config.Config) bool {
|
||||
return config.BoolSafe(c.Sub(subsection), "enabled")
|
||||
}
|
||||
|
||||
// ShutdownTimeout returns the value of "shutdown_timeout" config parameter
|
||||
// from "profiler" section.
|
||||
//
|
||||
|
|
|
@ -17,6 +17,7 @@ func TestProfilerSection(t *testing.T) {
|
|||
|
||||
require.Equal(t, profilerconfig.ShutdownTimeoutDefault, to)
|
||||
require.Equal(t, profilerconfig.AddressDefault, addr)
|
||||
require.False(t, profilerconfig.Enabled(configtest.EmptyConfig()))
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
@ -27,6 +28,7 @@ func TestProfilerSection(t *testing.T) {
|
|||
|
||||
require.Equal(t, 15*time.Second, to)
|
||||
require.Equal(t, "localhost:6060", addr)
|
||||
require.True(t, profilerconfig.Enabled(c))
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
|
|
@ -10,14 +10,13 @@ import (
|
|||
)
|
||||
|
||||
func initMetrics(c *cfg) {
|
||||
addr := metricsconfig.Address(c.appCfg)
|
||||
if addr == "" {
|
||||
if !metricsconfig.Enabled(c.appCfg) {
|
||||
return
|
||||
}
|
||||
|
||||
var prm httputil.Prm
|
||||
|
||||
prm.Address = addr
|
||||
prm.Address = metricsconfig.Address(c.appCfg)
|
||||
prm.Handler = promhttp.Handler()
|
||||
|
||||
srv := httputil.New(prm,
|
||||
|
|
|
@ -9,14 +9,14 @@ import (
|
|||
)
|
||||
|
||||
func initProfiler(c *cfg) {
|
||||
addr := profilerconfig.Address(c.appCfg)
|
||||
if addr == "" {
|
||||
if !profilerconfig.Enabled(c.appCfg) {
|
||||
c.log.Info("pprof is disabled")
|
||||
return
|
||||
}
|
||||
|
||||
var prm httputil.Prm
|
||||
|
||||
prm.Address = addr
|
||||
prm.Address = profilerconfig.Address(c.appCfg)
|
||||
prm.Handler = httputil.Handler()
|
||||
|
||||
srv := httputil.New(prm,
|
||||
|
|
|
@ -82,9 +82,11 @@ NEOFS_IR_CONTRACTS_ALPHABET_DOBRO=e6122b65d45c8feeb04455d67814394c147ed4d1
|
|||
NEOFS_IR_CONTRACTS_ALPHABET_YEST=cdbca5cb5d48a4472923844d0e3ee6328cf86d38
|
||||
NEOFS_IR_CONTRACTS_ALPHABET_ZHIVETE=f584699bc2ff457d339fb09f16217042c1a42101
|
||||
|
||||
NEOFS_IR_PROFILER_ENABLED=true
|
||||
NEOFS_IR_PROFILER_ADDRESS=localhost:6060
|
||||
NEOFS_IR_PROFILER_SHUTDOWN_TIMEOUT=30s
|
||||
|
||||
NEOFS_IR_METRICS_ENABLED=true
|
||||
NEOFS_IR_METRICS_ADDRESS=localhost:9090
|
||||
NEOFS_IR_METRICS_SHUTDOWN_TIMEOUT=30s
|
||||
|
||||
|
|
|
@ -124,10 +124,12 @@ contracts:
|
|||
zhivete: f584699bc2ff457d339fb09f16217042c1a42101 # Optional: override address of zhivete contract in sidechain
|
||||
|
||||
profiler:
|
||||
enabled: true
|
||||
address: localhost:6060 # Endpoint for application pprof profiling; disabled by default
|
||||
shutdown_timeout: 30s # Timeout for profiling HTTP server graceful shutdown
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
address: localhost:9090 # Endpoint for application prometheus metrics; disabled by default
|
||||
shutdown_timeout: 30s # Timeout for metrics HTTP server graceful shutdown
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
NEOFS_LOGGER_LEVEL=debug
|
||||
|
||||
NEOFS_PROFILER_ENABLED=true
|
||||
NEOFS_PROFILER_ADDRESS=localhost:6060
|
||||
NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s
|
||||
|
||||
NEOFS_METRICS_ENABLED=true
|
||||
NEOFS_METRICS_ADDRESS=localhost:9090
|
||||
NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
"level": "debug"
|
||||
},
|
||||
"profiler": {
|
||||
"enabled": true,
|
||||
"address": "localhost:6060",
|
||||
"shutdown_timeout": "15s"
|
||||
},
|
||||
"metrics": {
|
||||
"enabled": true,
|
||||
"address": "localhost:9090",
|
||||
"shutdown_timeout": "15s"
|
||||
},
|
||||
|
|
|
@ -2,10 +2,12 @@ logger:
|
|||
level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"
|
||||
|
||||
profiler:
|
||||
enabled: true
|
||||
address: localhost:6060 # endpoint for Node profiling
|
||||
shutdown_timeout: 15s # timeout for profiling HTTP server graceful shutdown
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
address: localhost:9090 # endpoint for Node metrics
|
||||
shutdown_timeout: 15s # timeout for metrics HTTP server graceful shutdown
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ logger:
|
|||
level: info
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
address: localhost:9090
|
||||
shutdown_timeout: 15s
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ node:
|
|||
attribute_1: User-Agent:NeoFS\/0.27
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
address: localhost:9090
|
||||
shutdown_timeout: 15s
|
||||
|
||||
|
|
Loading…
Reference in a new issue