From d4bec24c9fa7ede0fcc4d5b879316f0a54c61bb9 Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Mon, 16 Sep 2024 10:46:26 +0300 Subject: [PATCH] [#1366] node, ir: Support `timestamp` config option, update tests Signed-off-by: Aleksey Savchuk --- cmd/frostfs-ir/config.go | 2 ++ cmd/frostfs-ir/defaults.go | 1 + cmd/frostfs-ir/main.go | 2 ++ cmd/frostfs-node/config.go | 3 +++ cmd/frostfs-node/config/logger/config.go | 8 ++++++++ cmd/frostfs-node/config/logger/config_test.go | 2 ++ config/example/ir.env | 1 + config/example/ir.yaml | 1 + config/example/node.env | 1 + config/example/node.json | 3 ++- config/example/node.yaml | 1 + 11 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/frostfs-ir/config.go b/cmd/frostfs-ir/config.go index 4eaac845c..137e764ed 100644 --- a/cmd/frostfs-ir/config.go +++ b/cmd/frostfs-ir/config.go @@ -41,6 +41,8 @@ func reloadConfig() error { if err != nil { return err } + logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp") + return logPrm.Reload() } diff --git a/cmd/frostfs-ir/defaults.go b/cmd/frostfs-ir/defaults.go index e703301ae..899918d22 100644 --- a/cmd/frostfs-ir/defaults.go +++ b/cmd/frostfs-ir/defaults.go @@ -9,6 +9,7 @@ import ( func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("logger.level", "info") cfg.SetDefault("logger.destination", "stdout") + cfg.SetDefault("logger.timestamp", false) setPprofDefaults(cfg) diff --git a/cmd/frostfs-ir/main.go b/cmd/frostfs-ir/main.go index 02936ae78..4bc5923a0 100644 --- a/cmd/frostfs-ir/main.go +++ b/cmd/frostfs-ir/main.go @@ -79,6 +79,8 @@ func main() { ) exitErr(err) logPrm.SamplingHook = metrics.LogMetrics().GetSamplingHook() + logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp") + log, err = logger.NewLogger(logPrm) exitErr(err) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index c0019d36a..ed3a65c25 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -102,6 +102,7 @@ type applicationConfiguration struct { LoggerCfg struct { level string destination string + timestamp bool } EngineCfg struct { @@ -220,6 +221,7 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error { a.LoggerCfg.level = loggerconfig.Level(c) a.LoggerCfg.destination = loggerconfig.Destination(c) + a.LoggerCfg.timestamp = loggerconfig.Timestamp(c) // Storage Engine @@ -1023,6 +1025,7 @@ func (c *cfg) loggerPrm() (*logger.Prm, error) { // not expected since validation should be performed before panic("incorrect log destination format: " + c.LoggerCfg.destination) } + c.dynamicConfiguration.logger.PrependTimestamp = c.LoggerCfg.timestamp return c.dynamicConfiguration.logger, nil } diff --git a/cmd/frostfs-node/config/logger/config.go b/cmd/frostfs-node/config/logger/config.go index 378b9d793..ba9eeea2b 100644 --- a/cmd/frostfs-node/config/logger/config.go +++ b/cmd/frostfs-node/config/logger/config.go @@ -52,6 +52,14 @@ func Destination(c *config.Config) string { return DestinationDefault } +// Timestamp returns the value of "timestamp" config parameter +// from "logger" section. +// +// Returns false if the value isn't specified. +func Timestamp(c *config.Config) bool { + return config.BoolSafe(c.Sub(subsection), "timestamp") +} + // ToLokiConfig extracts loki config. func ToLokiConfig(c *config.Config) loki.Config { hostname, _ := os.Hostname() diff --git a/cmd/frostfs-node/config/logger/config_test.go b/cmd/frostfs-node/config/logger/config_test.go index 3587a0ddb..ffe8ac693 100644 --- a/cmd/frostfs-node/config/logger/config_test.go +++ b/cmd/frostfs-node/config/logger/config_test.go @@ -13,6 +13,7 @@ func TestLoggerSection_Level(t *testing.T) { t.Run("defaults", func(t *testing.T) { require.Equal(t, loggerconfig.LevelDefault, loggerconfig.Level(configtest.EmptyConfig())) require.Equal(t, loggerconfig.DestinationDefault, loggerconfig.Destination(configtest.EmptyConfig())) + require.Equal(t, false, loggerconfig.Timestamp(configtest.EmptyConfig())) }) const path = "../../../../config/example/node" @@ -20,6 +21,7 @@ func TestLoggerSection_Level(t *testing.T) { fileConfigTest := func(c *config.Config) { require.Equal(t, "debug", loggerconfig.Level(c)) require.Equal(t, "journald", loggerconfig.Destination(c)) + require.Equal(t, true, loggerconfig.Timestamp(c)) } configtest.ForEachFileType(path, fileConfigTest) diff --git a/config/example/ir.env b/config/example/ir.env index 3f9530ab6..7234a4b32 100644 --- a/config/example/ir.env +++ b/config/example/ir.env @@ -1,4 +1,5 @@ FROSTFS_IR_LOGGER_LEVEL=info +FROSTFS_IR_LOGGER_TIMESTAMP=true FROSTFS_IR_WALLET_PATH=/path/to/wallet.json FROSTFS_IR_WALLET_ADDRESS=NUHtW3eM6a4mmFCgyyr4rj4wygsTKB88XX diff --git a/config/example/ir.yaml b/config/example/ir.yaml index 401328e72..4c64f088b 100644 --- a/config/example/ir.yaml +++ b/config/example/ir.yaml @@ -2,6 +2,7 @@ logger: level: info # Logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal" + timestamp: true wallet: path: /path/to/wallet.json # Path to NEP-6 NEO wallet file diff --git a/config/example/node.env b/config/example/node.env index 030a79934..6618a981a 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -1,5 +1,6 @@ FROSTFS_LOGGER_LEVEL=debug FROSTFS_LOGGER_DESTINATION=journald +FROSTFS_LOGGER_TIMESTAMP=true FROSTFS_PPROF_ENABLED=true FROSTFS_PPROF_ADDRESS=localhost:6060 diff --git a/config/example/node.json b/config/example/node.json index 4e6d239fe..0d100ed80 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -1,7 +1,8 @@ { "logger": { "level": "debug", - "destination": "journald" + "destination": "journald", + "timestamp": true }, "pprof": { "enabled": true, diff --git a/config/example/node.yaml b/config/example/node.yaml index 5a8e6a2a4..86be35ba8 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -1,6 +1,7 @@ logger: level: debug # logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal" destination: journald # logger destination: one of "stdout" (default), "journald" + timestamp: true systemdnotify: enabled: true