forked from TrueCloudLab/frostfs-node
[#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
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue