forked from TrueCloudLab/frostfs-node
[#1366] node, ir: Support timestamp
config option, update tests
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
ea48e928c8
commit
d4bec24c9f
11 changed files with 24 additions and 1 deletions
|
@ -41,6 +41,8 @@ func reloadConfig() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp")
|
||||||
|
|
||||||
return logPrm.Reload()
|
return logPrm.Reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
func defaultConfiguration(cfg *viper.Viper) {
|
func defaultConfiguration(cfg *viper.Viper) {
|
||||||
cfg.SetDefault("logger.level", "info")
|
cfg.SetDefault("logger.level", "info")
|
||||||
cfg.SetDefault("logger.destination", "stdout")
|
cfg.SetDefault("logger.destination", "stdout")
|
||||||
|
cfg.SetDefault("logger.timestamp", false)
|
||||||
|
|
||||||
setPprofDefaults(cfg)
|
setPprofDefaults(cfg)
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,8 @@ func main() {
|
||||||
)
|
)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
logPrm.SamplingHook = metrics.LogMetrics().GetSamplingHook()
|
logPrm.SamplingHook = metrics.LogMetrics().GetSamplingHook()
|
||||||
|
logPrm.PrependTimestamp = cfg.GetBool("logger.timestamp")
|
||||||
|
|
||||||
log, err = logger.NewLogger(logPrm)
|
log, err = logger.NewLogger(logPrm)
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ type applicationConfiguration struct {
|
||||||
LoggerCfg struct {
|
LoggerCfg struct {
|
||||||
level string
|
level string
|
||||||
destination string
|
destination string
|
||||||
|
timestamp bool
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineCfg struct {
|
EngineCfg struct {
|
||||||
|
@ -220,6 +221,7 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error {
|
||||||
|
|
||||||
a.LoggerCfg.level = loggerconfig.Level(c)
|
a.LoggerCfg.level = loggerconfig.Level(c)
|
||||||
a.LoggerCfg.destination = loggerconfig.Destination(c)
|
a.LoggerCfg.destination = loggerconfig.Destination(c)
|
||||||
|
a.LoggerCfg.timestamp = loggerconfig.Timestamp(c)
|
||||||
|
|
||||||
// Storage Engine
|
// Storage Engine
|
||||||
|
|
||||||
|
@ -1023,6 +1025,7 @@ func (c *cfg) loggerPrm() (*logger.Prm, error) {
|
||||||
// not expected since validation should be performed before
|
// not expected since validation should be performed before
|
||||||
panic("incorrect log destination format: " + c.LoggerCfg.destination)
|
panic("incorrect log destination format: " + c.LoggerCfg.destination)
|
||||||
}
|
}
|
||||||
|
c.dynamicConfiguration.logger.PrependTimestamp = c.LoggerCfg.timestamp
|
||||||
|
|
||||||
return c.dynamicConfiguration.logger, nil
|
return c.dynamicConfiguration.logger, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,14 @@ func Destination(c *config.Config) string {
|
||||||
return DestinationDefault
|
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.
|
// ToLokiConfig extracts loki config.
|
||||||
func ToLokiConfig(c *config.Config) loki.Config {
|
func ToLokiConfig(c *config.Config) loki.Config {
|
||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
|
|
|
@ -13,6 +13,7 @@ func TestLoggerSection_Level(t *testing.T) {
|
||||||
t.Run("defaults", func(t *testing.T) {
|
t.Run("defaults", func(t *testing.T) {
|
||||||
require.Equal(t, loggerconfig.LevelDefault, loggerconfig.Level(configtest.EmptyConfig()))
|
require.Equal(t, loggerconfig.LevelDefault, loggerconfig.Level(configtest.EmptyConfig()))
|
||||||
require.Equal(t, loggerconfig.DestinationDefault, loggerconfig.Destination(configtest.EmptyConfig()))
|
require.Equal(t, loggerconfig.DestinationDefault, loggerconfig.Destination(configtest.EmptyConfig()))
|
||||||
|
require.Equal(t, false, loggerconfig.Timestamp(configtest.EmptyConfig()))
|
||||||
})
|
})
|
||||||
|
|
||||||
const path = "../../../../config/example/node"
|
const path = "../../../../config/example/node"
|
||||||
|
@ -20,6 +21,7 @@ func TestLoggerSection_Level(t *testing.T) {
|
||||||
fileConfigTest := func(c *config.Config) {
|
fileConfigTest := func(c *config.Config) {
|
||||||
require.Equal(t, "debug", loggerconfig.Level(c))
|
require.Equal(t, "debug", loggerconfig.Level(c))
|
||||||
require.Equal(t, "journald", loggerconfig.Destination(c))
|
require.Equal(t, "journald", loggerconfig.Destination(c))
|
||||||
|
require.Equal(t, true, loggerconfig.Timestamp(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
configtest.ForEachFileType(path, fileConfigTest)
|
configtest.ForEachFileType(path, fileConfigTest)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
FROSTFS_IR_LOGGER_LEVEL=info
|
FROSTFS_IR_LOGGER_LEVEL=info
|
||||||
|
FROSTFS_IR_LOGGER_TIMESTAMP=true
|
||||||
|
|
||||||
FROSTFS_IR_WALLET_PATH=/path/to/wallet.json
|
FROSTFS_IR_WALLET_PATH=/path/to/wallet.json
|
||||||
FROSTFS_IR_WALLET_ADDRESS=NUHtW3eM6a4mmFCgyyr4rj4wygsTKB88XX
|
FROSTFS_IR_WALLET_ADDRESS=NUHtW3eM6a4mmFCgyyr4rj4wygsTKB88XX
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
logger:
|
logger:
|
||||||
level: info # Logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"
|
level: info # Logger level: one of "debug", "info" (default), "warn", "error", "dpanic", "panic", "fatal"
|
||||||
|
timestamp: true
|
||||||
|
|
||||||
wallet:
|
wallet:
|
||||||
path: /path/to/wallet.json # Path to NEP-6 NEO wallet file
|
path: /path/to/wallet.json # Path to NEP-6 NEO wallet file
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
FROSTFS_LOGGER_LEVEL=debug
|
FROSTFS_LOGGER_LEVEL=debug
|
||||||
FROSTFS_LOGGER_DESTINATION=journald
|
FROSTFS_LOGGER_DESTINATION=journald
|
||||||
|
FROSTFS_LOGGER_TIMESTAMP=true
|
||||||
|
|
||||||
FROSTFS_PPROF_ENABLED=true
|
FROSTFS_PPROF_ENABLED=true
|
||||||
FROSTFS_PPROF_ADDRESS=localhost:6060
|
FROSTFS_PPROF_ADDRESS=localhost:6060
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
"logger": {
|
"logger": {
|
||||||
"level": "debug",
|
"level": "debug",
|
||||||
"destination": "journald"
|
"destination": "journald",
|
||||||
|
"timestamp": true
|
||||||
},
|
},
|
||||||
"pprof": {
|
"pprof": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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"
|
||||||
destination: journald # logger destination: one of "stdout" (default), "journald"
|
destination: journald # logger destination: one of "stdout" (default), "journald"
|
||||||
|
timestamp: true
|
||||||
|
|
||||||
systemdnotify:
|
systemdnotify:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
Loading…
Reference in a new issue