From ec3e4fb2a5f0c1780544a8be61cf5b6870d6969a Mon Sep 17 00:00:00 2001 From: Andrey Kolkov Date: Fri, 29 Jan 2021 18:34:11 +0400 Subject: [PATCH] Feature/441 improve logging (#599) * Added zerolog adapter * Zerolog configured as previous * Added config for pretty log format * fix pkg configs too * Added structured log methods * Simplified logger interface * Replaced go-logger to zerolog * fix time format in json log * Linter fixes: - mute errcheck - fix goimports * Added Logger.Clone() method * Fix logger mock Co-authored-by: Andrey Kolkov --- api/controller/pattern_test.go | 2 +- api/controller/tag_test.go | 2 +- checker/check_test.go | 10 +- checker/event_test.go | 2 +- checker/trigger_checker_test.go | 8 +- cmd/api/config.go | 5 +- cmd/api/main.go | 5 +- cmd/checker/config.go | 5 +- cmd/checker/main.go | 6 +- cmd/cli/config.go | 14 +- cmd/cli/main.go | 4 +- cmd/cli/user_test.go | 4 +- cmd/config.go | 5 +- cmd/filter/config.go | 5 +- cmd/filter/main.go | 4 +- cmd/notifier/config.go | 5 +- cmd/notifier/main.go | 4 +- database/redis/bot_test.go | 6 +- database/redis/contact_test.go | 3 +- database/redis/database_dialer_test.go | 24 +-- database/redis/database_test.go | 6 +- database/redis/last_check_test.go | 2 +- database/redis/locks_test.go | 2 +- database/redis/metric_test.go | 2 +- database/redis/notification_event_test.go | 6 +- database/redis/notification_test.go | 36 ++--- database/redis/selfstate_test.go | 2 +- database/redis/subscription_test.go | 2 +- database/redis/tag_test.go | 2 +- database/redis/throttling_test.go | 2 +- database/redis/trigger_test.go | 2 +- database/redis/triggers_lock_test.go | 2 +- .../redis/triggers_search_results_test.go | 9 +- database/redis/triggers_to_check_test.go | 10 +- database/redis/triggers_to_reindex_test.go | 6 +- database/redis/unused_triggers_test.go | 6 +- filter/pattern_index_test.go | 2 +- filter/patterns_storage_test.go | 2 +- go.mod | 3 +- go.sum | 6 +- index/actualizer_test.go | 2 +- index/bleve/trigger_index_benchmark_test.go | 2 +- index/index_test.go | 3 +- index/search_test.go | 2 +- integration_tests/notifier/notifier_test.go | 10 +- interfaces.go | 10 ++ local/api.yml | 1 + local/checker.yml | 1 + local/cli.yml | 2 +- local/filter.yml | 1 + local/notifier.yml | 1 + logging/go-logging/logger.go | 47 ------ logging/zerolog_adapter/logger.go | 142 ++++++++++++++++++ mock/moira-alert/logger.go | 72 +++++++++ notifier/events/event_test.go | 2 +- notifier/notifications/notifications_test.go | 4 +- notifier/notifier_test.go | 2 +- notifier/plotting_test.go | 2 +- notifier/scheduler_test.go | 2 +- notifier/selfstate/heartbeat/database_test.go | 2 +- notifier/selfstate/heartbeat/filter_test.go | 2 +- .../selfstate/heartbeat/local_checker_test.go | 2 +- notifier/selfstate/heartbeat/notifier_test.go | 2 +- .../heartbeat/remote_checker_test.go | 2 +- notifier/selfstate/selfstate_test.go | 2 +- perfomance_tests/filter/filter_test.go | 2 +- pkg/api/api.yml | 1 + pkg/checker/checker.yml | 1 + pkg/cli/cli.yml | 2 +- pkg/filter/filter.yml | 1 + pkg/notifier/notifier.yml | 1 + senders/discord/init_test.go | 4 +- senders/mail/send_test.go | 6 +- senders/msteams/msteams_test.go | 6 +- senders/opsgenie/init_test.go | 4 +- senders/opsgenie/send_test.go | 4 +- senders/pagerduty/init_test.go | 4 +- senders/pushover/pushover_test.go | 6 +- senders/script/script_test.go | 6 +- senders/selfstate/selfstate_test.go | 4 +- senders/slack/slack_test.go | 4 +- senders/telegram/init_test.go | 4 +- senders/twilio/sms_test.go | 4 +- senders/twilio/twilio_test.go | 4 +- senders/twilio/voice_test.go | 4 +- senders/victorops/init_test.go | 4 +- senders/webhook/webhook_test.go | 2 +- worker/worker_test.go | 5 +- 88 files changed, 419 insertions(+), 217 deletions(-) delete mode 100644 logging/go-logging/logger.go create mode 100644 logging/zerolog_adapter/logger.go diff --git a/api/controller/pattern_test.go b/api/controller/pattern_test.go index fde2718a7..f923504aa 100644 --- a/api/controller/pattern_test.go +++ b/api/controller/pattern_test.go @@ -9,8 +9,8 @@ import ( "github.com/moira-alert/moira" "github.com/moira-alert/moira/api" "github.com/moira-alert/moira/api/dto" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/api/controller/tag_test.go b/api/controller/tag_test.go index ff81f538c..4f994e736 100644 --- a/api/controller/tag_test.go +++ b/api/controller/tag_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira" "github.com/moira-alert/moira/api" diff --git a/checker/check_test.go b/checker/check_test.go index c1c2243f2..e1e66cddc 100644 --- a/checker/check_test.go +++ b/checker/check_test.go @@ -10,12 +10,12 @@ import ( "github.com/moira-alert/moira" "github.com/moira-alert/moira/checker/metrics/conversion" "github.com/moira-alert/moira/expression" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" "github.com/moira-alert/moira/metrics" mock_metric_source "github.com/moira-alert/moira/mock/metric_source" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) @@ -322,7 +322,7 @@ func TestTriggerChecker_PrepareMetrics(t *testing.T) { func TestGetMetricStepsStates(t *testing.T) { logger, _ := logging.GetLogger("Test") - logging.SetLevel(logging.INFO, "Test") + logger.Level("info") // nolint: errcheck var warnValue float64 = 10 var errValue float64 = 20 @@ -503,7 +503,7 @@ func TestGetMetricStepsStates(t *testing.T) { func TestCheckForNODATA(t *testing.T) { logger, _ := logging.GetLogger("Test") - logging.SetLevel(logging.INFO, "Test") + logger.Level("info") // nolint: errcheck metricLastState := moira.MetricState{ EventTimestamp: 11, Maintenance: 11111, @@ -907,7 +907,7 @@ func TestCheck(t *testing.T) { func TestIgnoreNodataToOk(t *testing.T) { mockCtrl := gomock.NewController(t) logger, _ := logging.GetLogger("Test") - logging.SetLevel(logging.INFO, "Test") + logger.Level("info") // nolint: errcheck defer mockCtrl.Finish() var retention int64 = 10 @@ -970,7 +970,7 @@ func TestHandleTrigger(t *testing.T) { mockCtrl := gomock.NewController(t) dataBase := mock_moira_alert.NewMockDatabase(mockCtrl) logger, _ := logging.GetLogger("Test") - logging.SetLevel(logging.INFO, "Test") + logger.Level("info") // nolint: errcheck defer mockCtrl.Finish() var retention int64 = 10 diff --git a/checker/event_test.go b/checker/event_test.go index dd962bc35..1e63113dc 100644 --- a/checker/event_test.go +++ b/checker/event_test.go @@ -6,8 +6,8 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/checker/trigger_checker_test.go b/checker/trigger_checker_test.go index d36d7f5de..e57c4741e 100644 --- a/checker/trigger_checker_test.go +++ b/checker/trigger_checker_test.go @@ -7,11 +7,11 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" "github.com/moira-alert/moira/database" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" "github.com/moira-alert/moira/metrics" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) @@ -77,21 +77,21 @@ func TestInitTriggerChecker(t *testing.T) { Timestamp: 1502694427, State: moira.StateOK, Suppressed: false, - Values: map[string]float64{"t1": value}, //nolint + Values: map[string]float64{"t1": value}, //nolint EventTimestamp: 1501680428, }, "2": { Timestamp: 1502694427, State: moira.StateOK, Suppressed: false, - Values: map[string]float64{"t1": value}, //nolint + Values: map[string]float64{"t1": value}, //nolint EventTimestamp: 1501679827, }, "3": { Timestamp: 1502694427, State: moira.StateOK, Suppressed: false, - Values: map[string]float64{"t1": value}, //nolint + Values: map[string]float64{"t1": value}, //nolint EventTimestamp: 1501679887, }, }, diff --git a/cmd/api/config.go b/cmd/api/config.go index 69728ac75..845cd2258 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -90,8 +90,9 @@ func getDefault() config { MetricsTTL: "1h", }, Logger: cmd.LoggerConfig{ - LogFile: "stdout", - LogLevel: "info", + LogFile: "stdout", + LogLevel: "info", + LogPrettyFormat: false, }, API: apiConfig{ Listen: ":8081", diff --git a/cmd/api/main.go b/cmd/api/main.go index d073b635a..4c0511f52 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -16,7 +16,7 @@ import ( "github.com/moira-alert/moira/cmd" "github.com/moira-alert/moira/database/redis" "github.com/moira-alert/moira/index" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" "github.com/moira-alert/moira/metric_source/remote" @@ -61,7 +61,8 @@ func main() { apiConfig := config.API.getSettings(config.Redis.MetricsTTL, config.Remote.MetricsTTL) - logger, err := logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName) + logger, err := logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName, config.Logger.LogPrettyFormat) + if err != nil { fmt.Fprintf(os.Stderr, "Can not configure log: %s\n", err.Error()) os.Exit(1) diff --git a/cmd/checker/config.go b/cmd/checker/config.go index c23b73b59..4160ee25c 100644 --- a/cmd/checker/config.go +++ b/cmd/checker/config.go @@ -50,8 +50,9 @@ func getDefault() config { MetricsTTL: "1h", }, Logger: cmd.LoggerConfig{ - LogFile: "stdout", - LogLevel: "info", + LogFile: "stdout", + LogLevel: "info", + LogPrettyFormat: false, }, Checker: checkerConfig{ NoDataCheckInterval: "60s", diff --git a/cmd/checker/main.go b/cmd/checker/main.go index b17f2dbc8..7ffc2f7e3 100644 --- a/cmd/checker/main.go +++ b/cmd/checker/main.go @@ -18,7 +18,7 @@ import ( "github.com/moira-alert/moira/checker/worker" "github.com/moira-alert/moira/cmd" "github.com/moira-alert/moira/database/redis" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" ) @@ -61,7 +61,7 @@ func main() { os.Exit(1) } - logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName) + logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName, config.Logger.LogPrettyFormat) if err != nil { fmt.Fprintf(os.Stderr, "Can not configure log: %s\n", err.Error()) os.Exit(1) @@ -97,7 +97,7 @@ func main() { SourceProvider: metricSourceProvider, Metrics: checkerMetrics, TriggerCache: cache.New(checkerSettings.CheckInterval, time.Minute*60), //nolint - LazyTriggersCache: cache.New(time.Minute*10, time.Minute*60), //nolint + LazyTriggersCache: cache.New(time.Minute*10, time.Minute*60), //nolint PatternCache: cache.New(checkerSettings.CheckInterval, time.Minute*60), //nolint } err = checkerWorker.Start() diff --git a/cmd/cli/config.go b/cmd/cli/config.go index 74c6bb864..b7ef17e35 100644 --- a/cmd/cli/config.go +++ b/cmd/cli/config.go @@ -5,10 +5,11 @@ import ( ) type config struct { - LogFile string `yaml:"log_file"` - LogLevel string `yaml:"log_level"` - Redis cmd.RedisConfig `yaml:"redis"` - Cleanup cleanupConfig `yaml:"cleanup"` + LogFile string `yaml:"log_file"` + LogLevel string `yaml:"log_level"` + LogPrettyFormat bool `yaml:"log_pretty_format"` + Redis cmd.RedisConfig `yaml:"redis"` + Cleanup cleanupConfig `yaml:"cleanup"` } type cleanupConfig struct { @@ -19,8 +20,9 @@ type cleanupConfig struct { func getDefault() config { return config{ - LogFile: "stdout", - LogLevel: "info", + LogFile: "stdout", + LogLevel: "info", + LogPrettyFormat: false, Redis: cmd.RedisConfig{ Host: "localhost", Port: "6379", diff --git a/cmd/cli/main.go b/cmd/cli/main.go index ef3b55b3f..801d7cb25 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -9,7 +9,7 @@ import ( "github.com/moira-alert/moira" "github.com/moira-alert/moira/cmd" "github.com/moira-alert/moira/database/redis" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" ) // Moira version @@ -121,7 +121,7 @@ func initApp() (cleanupConfig, moira.Logger, moira.Database) { os.Exit(1) } - logger, err := logging.ConfigureLog(config.LogFile, config.LogLevel, "cli") + logger, err := logging.ConfigureLog(config.LogFile, config.LogLevel, "cli", config.LogPrettyFormat) if err != nil { fmt.Fprintf(os.Stderr, "Can't configure main logger: %v\n", err) os.Exit(1) diff --git a/cmd/cli/user_test.go b/cmd/cli/user_test.go index f88614792..55dad26d5 100644 --- a/cmd/cli/user_test.go +++ b/cmd/cli/user_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/moira-alert/moira/database/redis" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira" @@ -18,7 +18,7 @@ func TestUpdateUsers(t *testing.T) { } conf := getDefault() - logger, err := logging.ConfigureLog(conf.LogFile, conf.LogLevel, "cli") + logger, err := logging.ConfigureLog(conf.LogFile, conf.LogLevel, "cli", conf.LogPrettyFormat) if err != nil { t.Fatal(err) } diff --git a/cmd/config.go b/cmd/config.go index b125f4ffe..a3a3fbb9b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -77,8 +77,9 @@ func (graphiteConfig *GraphiteConfig) GetSettings() metrics.GraphiteRegistryConf // LoggerConfig is logger settings structure that initialises at the start of moira type LoggerConfig struct { - LogFile string `yaml:"log_file"` - LogLevel string `yaml:"log_level"` + LogFile string `yaml:"log_file"` + LogLevel string `yaml:"log_level"` + LogPrettyFormat bool `yaml:"log_pretty_format"` } // TelemetryConfig is settings for listener, pprof, graphite diff --git a/cmd/filter/config.go b/cmd/filter/config.go index 2b927d88d..3bed3ea33 100644 --- a/cmd/filter/config.go +++ b/cmd/filter/config.go @@ -37,8 +37,9 @@ func getDefault() config { MetricsTTL: "1h", }, Logger: cmd.LoggerConfig{ - LogFile: "stdout", - LogLevel: "info", + LogFile: "stdout", + LogLevel: "info", + LogPrettyFormat: false, }, Filter: filterConfig{ Listen: ":2003", diff --git a/cmd/filter/main.go b/cmd/filter/main.go index 0f7b9d88e..0f05b72fa 100644 --- a/cmd/filter/main.go +++ b/cmd/filter/main.go @@ -16,7 +16,7 @@ import ( "github.com/moira-alert/moira/filter/heartbeat" matchedmetrics "github.com/moira-alert/moira/filter/matched_metrics" "github.com/moira-alert/moira/filter/patterns" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" "github.com/xiam/to" ) @@ -59,7 +59,7 @@ func main() { os.Exit(1) } - logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName) + logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName, config.Logger.LogPrettyFormat) if err != nil { fmt.Fprintf(os.Stderr, "Can not configure log: %s\n", err.Error()) os.Exit(1) diff --git a/cmd/notifier/config.go b/cmd/notifier/config.go index 07b53b17e..5afac8cfe 100644 --- a/cmd/notifier/config.go +++ b/cmd/notifier/config.go @@ -69,8 +69,9 @@ func getDefault() config { }, Logger: cmd.LoggerConfig{ - LogFile: "stdout", - LogLevel: "info", + LogFile: "stdout", + LogLevel: "info", + LogPrettyFormat: false, }, Notifier: notifierConfig{ SenderTimeout: "10s", diff --git a/cmd/notifier/main.go b/cmd/notifier/main.go index 67a5e2e80..2cc30dd3e 100644 --- a/cmd/notifier/main.go +++ b/cmd/notifier/main.go @@ -14,7 +14,7 @@ import ( "github.com/moira-alert/moira" "github.com/moira-alert/moira/cmd" "github.com/moira-alert/moira/database/redis" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" "github.com/moira-alert/moira/notifier" "github.com/moira-alert/moira/notifier/events" @@ -60,7 +60,7 @@ func main() { os.Exit(1) } - logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName) + logger, err = logging.ConfigureLog(config.Logger.LogFile, config.Logger.LogLevel, serviceName, config.Logger.LogPrettyFormat) if err != nil { fmt.Fprintf(os.Stderr, "Can not configure log: %s\n", err.Error()) os.Exit(1) diff --git a/database/redis/bot_test.go b/database/redis/bot_test.go index 8e964916c..c5f9bbc77 100644 --- a/database/redis/bot_test.go +++ b/database/redis/bot_test.go @@ -6,11 +6,11 @@ import ( . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira/database" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" ) func TestBotDataStoring(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() @@ -59,7 +59,7 @@ func TestBotDataStoring(t *testing.T) { } func TestBotDataStoringErrorConnection(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, emptyConfig) dataBase.flush() defer dataBase.flush() diff --git a/database/redis/contact_test.go b/database/redis/contact_test.go index da6851dc9..28fe50d10 100644 --- a/database/redis/contact_test.go +++ b/database/redis/contact_test.go @@ -4,11 +4,11 @@ import ( "fmt" "testing" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" "github.com/moira-alert/moira/database" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" ) var user1 = "user1" @@ -16,6 +16,7 @@ var user2 = "user2" func TestContacts(t *testing.T) { logger, _ := logging.GetLogger("dataBase") + dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() diff --git a/database/redis/database_dialer_test.go b/database/redis/database_dialer_test.go index 0615bb759..74843e963 100644 --- a/database/redis/database_dialer_test.go +++ b/database/redis/database_dialer_test.go @@ -4,15 +4,15 @@ import ( "testing" "time" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) -var logger, _ = logging.ConfigureLog("stdout", "debug", "test") +var logger, _ = logging.ConfigureLog("stdout", "debug", "test", true) var sentinelConfig = SentinelPoolDialerConfig{ - MasterName: "master01", //nolint - DB: 0, + MasterName: "master01", //nolint + DB: 0, DialTimeout: time.Millisecond, SentinelAddresses: []string{ "fake-sentinel:26379", @@ -22,28 +22,28 @@ var sentinelConfig = SentinelPoolDialerConfig{ func TestDirectDialer(t *testing.T) { Convey("Direct dialer", t, func() { Convey("Tries dial and fails", func() { - dialer := DirectPoolDialer { //nolint + dialer := DirectPoolDialer{ //nolint serverAddress: "fake-redis:6379", - db: 0, //nolint - dialTimeout: time.Millisecond, + db: 0, //nolint + dialTimeout: time.Millisecond, } _, err := dialer.Dial() So(err.Error(), ShouldEqual, "dial tcp: i/o timeout") }) - //nolint + //nolint Convey("Test dials successfully", func() { - dialer := DirectPoolDialer { //nolint + dialer := DirectPoolDialer{ //nolint serverAddress: "localhost:6379", - db: 0, //nolint - dialTimeout: 5 * time.Second, + db: 0, //nolint + dialTimeout: 5 * time.Second, } conn, err := dialer.Dial() So(err, ShouldBeNil) - //nolint + //nolint err = dialer.Test(conn, time.Now()) So(err, ShouldBeNil) }) diff --git a/database/redis/database_test.go b/database/redis/database_test.go index f08e514d4..d827f344c 100644 --- a/database/redis/database_test.go +++ b/database/redis/database_test.go @@ -3,7 +3,7 @@ package redis import ( "testing" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" @@ -21,7 +21,7 @@ func newTestDatabase(logger moira.Logger, config Config) *DbConnector { // docker run -p 6379:6379 redis func TestInitialization(t *testing.T) { Convey("Initialization methods", t, func() { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) // nolint: govet database := newTestDatabase(logger, emptyConfig) So(database, ShouldNotBeEmpty) _, err := database.pool.Dial() @@ -30,7 +30,7 @@ func TestInitialization(t *testing.T) { } func TestAllowStale(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) // nolint: govet Convey("Allow stale", t, func() { Convey("When using redis directly, returns same db", func() { diff --git a/database/redis/last_check_test.go b/database/redis/last_check_test.go index a71ca8eaf..809bd15a1 100644 --- a/database/redis/last_check_test.go +++ b/database/redis/last_check_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/gofrs/uuid" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/database/redis/locks_test.go b/database/redis/locks_test.go index 9529edb25..b30798ded 100644 --- a/database/redis/locks_test.go +++ b/database/redis/locks_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/moira-alert/moira/database" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/database/redis/metric_test.go b/database/redis/metric_test.go index 4217dab47..3024ae4fc 100644 --- a/database/redis/metric_test.go +++ b/database/redis/metric_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/patrickmn/go-cache" . "github.com/smartystreets/goconvey/convey" "gopkg.in/tomb.v2" diff --git a/database/redis/notification_event_test.go b/database/redis/notification_event_test.go index 11001aa0d..ea36aaa81 100644 --- a/database/redis/notification_event_test.go +++ b/database/redis/notification_event_test.go @@ -3,7 +3,7 @@ package redis import ( "testing" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "time" @@ -19,7 +19,7 @@ const triggerID3 = "F0F4A5B9-637C-4933-AA0D-88B9798A2630" //nolint var now = time.Now().Unix() var value = float64(0) - //nolint +//nolint func TestNotificationEvents(t *testing.T) { logger, _ := logging.GetLogger("dataBase") dataBase := newTestDatabase(logger, config) @@ -245,7 +245,7 @@ func TestNotificationEvents(t *testing.T) { OldState: moira.StateNODATA, TriggerID: triggerID, Metric: "my.metric", - Value: &value, //nolint + Value: &value, //nolint }, true) So(err, ShouldBeNil) diff --git a/database/redis/notification_test.go b/database/redis/notification_test.go index e022792c4..7693b02d7 100644 --- a/database/redis/notification_test.go +++ b/database/redis/notification_test.go @@ -7,8 +7,8 @@ import ( "time" "github.com/moira-alert/moira" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/notifier" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) @@ -53,7 +53,7 @@ func TestScheduledNotification(t *testing.T) { }) Convey("Test fetch notifications", func() { - actual, err := dataBase.FetchNotifications(now - 3600, notifier.NotificationsLimitUnlimited) //nolint + actual, err := dataBase.FetchNotifications(now-3600, notifier.NotificationsLimitUnlimited) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld}) @@ -62,7 +62,7 @@ func TestScheduledNotification(t *testing.T) { So(total, ShouldEqual, 2) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ification, ¬ificationNew}) - actual, err = dataBase.FetchNotifications(now + 3600, notifier.NotificationsLimitUnlimited) //nolint + actual, err = dataBase.FetchNotifications(now+3600, notifier.NotificationsLimitUnlimited) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ification, ¬ificationNew}) @@ -73,9 +73,9 @@ func TestScheduledNotification(t *testing.T) { }) Convey("Test fetch notifications limit 0", func() { - actual, err := dataBase.FetchNotifications(now - 3600, 0) //nolint + actual, err := dataBase.FetchNotifications(now-3600, 0) //nolint So(err, ShouldBeError) - So(actual, ShouldBeNil ) //nolint + So(actual, ShouldBeNil) //nolint }) Convey("Test remove notifications by key", func() { @@ -113,7 +113,7 @@ func TestScheduledNotification(t *testing.T) { So(total, ShouldEqual, 1) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ification3}) - total, err = dataBase.RemoveNotification(strings.Join([]string{fmt.Sprintf("%v", now + 3600), id1, id1}, "")) //nolint + total, err = dataBase.RemoveNotification(strings.Join([]string{fmt.Sprintf("%v", now+3600), id1, id1}, "")) //nolint So(err, ShouldBeNil) So(total, ShouldEqual, 1) @@ -122,7 +122,7 @@ func TestScheduledNotification(t *testing.T) { So(total, ShouldEqual, 0) So(actual, ShouldResemble, []*moira.ScheduledNotification{}) - actual, err = dataBase.FetchNotifications(now + 3600, notifier.NotificationsLimitUnlimited) //nolint + actual, err = dataBase.FetchNotifications(now+3600, notifier.NotificationsLimitUnlimited) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{}) }) @@ -161,7 +161,7 @@ func TestScheduledNotification(t *testing.T) { So(total, ShouldEqual, 0) So(actual, ShouldResemble, []*moira.ScheduledNotification{}) - actual, err = dataBase.FetchNotifications(now + 3600, notifier.NotificationsLimitUnlimited) //nolint + actual, err = dataBase.FetchNotifications(now+3600, notifier.NotificationsLimitUnlimited) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{}) }) @@ -230,7 +230,7 @@ func TestFetchNotifications(t *testing.T) { Convey("Test fetch notifications with limit if all notifications has diff timestamp", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.FetchNotifications(now + 6000, 1) //nolint + actual, err := dataBase.FetchNotifications(now+6000, 1) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld}) @@ -245,7 +245,7 @@ func TestFetchNotifications(t *testing.T) { Convey("Test fetch notifications with limit little bit greater than count if all notifications has diff timestamp", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.FetchNotifications(now + 6000, 4) //nolint + actual, err := dataBase.FetchNotifications(now+6000, 4) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification}) @@ -261,7 +261,7 @@ func TestFetchNotifications(t *testing.T) { Convey("Test fetch notifications with limit greater than count if all notifications has diff timestamp", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.FetchNotifications(now + 6000, 200000) //nolint + actual, err := dataBase.FetchNotifications(now+6000, 200000) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification, ¬ificationNew}) @@ -276,7 +276,7 @@ func TestFetchNotifications(t *testing.T) { Convey("Test fetch notifications without limit", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.FetchNotifications(now + 6000, notifier.NotificationsLimitUnlimited) //nolint + actual, err := dataBase.FetchNotifications(now+6000, notifier.NotificationsLimitUnlimited) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification, ¬ificationNew}) @@ -381,7 +381,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { Convey("Test all notification with ts and limit in db", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.fetchNotificationsWithLimitDo(now + 6000, 1) //nolint + actual, err := dataBase.fetchNotificationsWithLimitDo(now+6000, 1) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld}) @@ -391,7 +391,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { Convey("Test 0 notification with ts and limit in empty db", func() { addNotifications(dataBase, []moira.ScheduledNotification{}) - actual, err := dataBase.fetchNotificationsWithLimitDo(now + 6000, 10) //nolint + actual, err := dataBase.fetchNotificationsWithLimitDo(now+6000, 10) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{}) @@ -401,7 +401,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { Convey("Test all notification with ts and big limit in db", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.fetchNotificationsWithLimitDo(now + 6000, 100) //nolint + actual, err := dataBase.fetchNotificationsWithLimitDo(now+6000, 100) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification}) @@ -411,7 +411,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { Convey("Test notification with ts and small limit in db", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld, notification4}) - actual, err := dataBase.fetchNotificationsWithLimitDo(now + 6000, 3) //nolint + actual, err := dataBase.fetchNotificationsWithLimitDo(now+6000, 3) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification4}) @@ -421,7 +421,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { Convey("Test notification with ts and limit = count", func() { addNotifications(dataBase, []moira.ScheduledNotification{notification, notificationNew, notificationOld}) - actual, err := dataBase.fetchNotificationsWithLimitDo(now + 6000, 3) //nolint + actual, err := dataBase.fetchNotificationsWithLimitDo(now+6000, 3) //nolint So(err, ShouldBeNil) So(actual, ShouldResemble, []*moira.ScheduledNotification{¬ificationOld, ¬ification}) @@ -431,7 +431,7 @@ func TestFetchNotificationsWithLimitDo(t *testing.T) { }) } -func TestLimitNotifications(t *testing.T) { //nolint +func TestLimitNotifications(t *testing.T) { //nolint Convey("limitNotifications manipulation", t, func() { now := time.Now().Unix() notificationNew := moira.ScheduledNotification{ diff --git a/database/redis/selfstate_test.go b/database/redis/selfstate_test.go index 06405bbd0..162f4ba3d 100644 --- a/database/redis/selfstate_test.go +++ b/database/redis/selfstate_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/moira-alert/moira" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/database/redis/subscription_test.go b/database/redis/subscription_test.go index 80da7ff74..fceb32de1 100644 --- a/database/redis/subscription_test.go +++ b/database/redis/subscription_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/gofrs/uuid" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/database/redis/tag_test.go b/database/redis/tag_test.go index 987bbd572..a4d0189f4 100644 --- a/database/redis/tag_test.go +++ b/database/redis/tag_test.go @@ -3,7 +3,7 @@ package redis import ( "testing" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/database/redis/throttling_test.go b/database/redis/throttling_test.go index 59091c81c..7362f76b7 100644 --- a/database/redis/throttling_test.go +++ b/database/redis/throttling_test.go @@ -3,7 +3,7 @@ package redis import ( "testing" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "time" diff --git a/database/redis/trigger_test.go b/database/redis/trigger_test.go index b5a37f4de..36f7fb095 100644 --- a/database/redis/trigger_test.go +++ b/database/redis/trigger_test.go @@ -6,7 +6,7 @@ import ( "github.com/gofrs/uuid" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/database/redis/triggers_lock_test.go b/database/redis/triggers_lock_test.go index 75da903d7..f5accf36d 100644 --- a/database/redis/triggers_lock_test.go +++ b/database/redis/triggers_lock_test.go @@ -3,7 +3,7 @@ package redis import ( "testing" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/database/redis/triggers_search_results_test.go b/database/redis/triggers_search_results_test.go index 0902a432e..111a5c9e7 100644 --- a/database/redis/triggers_search_results_test.go +++ b/database/redis/triggers_search_results_test.go @@ -2,12 +2,12 @@ package redis import ( "fmt" - "log" "strings" "testing" "github.com/moira-alert/moira" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" + "github.com/rs/zerolog" . "github.com/smartystreets/goconvey/convey" ) @@ -131,8 +131,9 @@ func TestTriggersSearchResultsStoring(t *testing.T) { } func BenchmarkSaveTriggersSearchResults(b *testing.B) { - logger, _ := logging.GetLogger("dataBase") - logging.SetBackend(logging.NewLogBackend(&strings.Builder{}, "", log.LstdFlags)) + logger = &logging.Logger{ + Logger: zerolog.New(&strings.Builder{}).With().Str(logging.ModuleFieldName, "dataBase").Logger(), + } dataBase := newTestDatabase(logger, config) dataBase.flush() diff --git a/database/redis/triggers_to_check_test.go b/database/redis/triggers_to_check_test.go index 6f1134980..a5670e289 100644 --- a/database/redis/triggers_to_check_test.go +++ b/database/redis/triggers_to_check_test.go @@ -6,11 +6,11 @@ import ( "github.com/gofrs/uuid" . "github.com/smartystreets/goconvey/convey" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" ) func TestTriggerToCheck(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() @@ -103,7 +103,7 @@ func TestTriggerToCheck(t *testing.T) { } func TestRemoteTriggerToCheck(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() @@ -195,7 +195,7 @@ func TestRemoteTriggerToCheck(t *testing.T) { } func TestRemoteTriggerToCheckConnection(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, emptyConfig) dataBase.flush() defer dataBase.flush() @@ -210,7 +210,7 @@ func TestRemoteTriggerToCheckConnection(t *testing.T) { } func TestTriggerToCheckConnection(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, emptyConfig) dataBase.flush() defer dataBase.flush() diff --git a/database/redis/triggers_to_reindex_test.go b/database/redis/triggers_to_reindex_test.go index f4526abf4..db583281a 100644 --- a/database/redis/triggers_to_reindex_test.go +++ b/database/redis/triggers_to_reindex_test.go @@ -6,12 +6,12 @@ import ( "time" "github.com/gofrs/uuid" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestTriggersToReindex(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() @@ -118,7 +118,7 @@ func TestTriggersToReindex(t *testing.T) { } func TestTriggerToReindexConnection(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, emptyConfig) dataBase.flush() defer dataBase.flush() diff --git a/database/redis/unused_triggers_test.go b/database/redis/unused_triggers_test.go index 9ff4c938a..2c9c885a7 100644 --- a/database/redis/unused_triggers_test.go +++ b/database/redis/unused_triggers_test.go @@ -5,12 +5,12 @@ import ( "github.com/gofrs/uuid" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestUnusedTriggers(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, config) dataBase.flush() defer dataBase.flush() @@ -277,7 +277,7 @@ func TestUnusedTriggers(t *testing.T) { } func TestUnusedTriggersConnection(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) dataBase := newTestDatabase(logger, emptyConfig) dataBase.flush() defer dataBase.flush() diff --git a/filter/pattern_index_test.go b/filter/pattern_index_test.go index 4d1dcb707..cba30528a 100644 --- a/filter/pattern_index_test.go +++ b/filter/pattern_index_test.go @@ -3,7 +3,7 @@ package filter import ( "testing" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/filter/patterns_storage_test.go b/filter/patterns_storage_test.go index e0937a61a..7281a4250 100644 --- a/filter/patterns_storage_test.go +++ b/filter/patterns_storage_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/golang/mock/gomock" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/go.mod b/go.mod index fb3b78209..7928ed794 100644 --- a/go.mod +++ b/go.mod @@ -73,6 +73,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rs/cors v1.7.0 + github.com/rs/zerolog v1.20.0 github.com/russross/blackfriday/v2 v2.0.1 github.com/sirupsen/logrus v1.7.0 // indirect github.com/smartystreets/assertions v1.2.0 @@ -111,4 +112,4 @@ require ( gopkg.in/yaml.v2 v2.3.0 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect honnef.co/go/tools v0.0.1-2020.1.5 // indirect -) \ No newline at end of file +) diff --git a/go.sum b/go.sum index a38b6b774..226b2e3a3 100644 --- a/go.sum +++ b/go.sum @@ -541,6 +541,9 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs= +github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -823,6 +826,7 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -956,4 +960,4 @@ modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= \ No newline at end of file +sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/index/actualizer_test.go b/index/actualizer_test.go index 3bf079257..1a8861dbf 100644 --- a/index/actualizer_test.go +++ b/index/actualizer_test.go @@ -7,7 +7,7 @@ import ( "github.com/moira-alert/moira/metrics" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/index/bleve/trigger_index_benchmark_test.go b/index/bleve/trigger_index_benchmark_test.go index f97b9f3ed..b1b9bcefc 100644 --- a/index/bleve/trigger_index_benchmark_test.go +++ b/index/bleve/trigger_index_benchmark_test.go @@ -8,7 +8,7 @@ import ( "github.com/gofrs/uuid" "github.com/moira-alert/moira" "github.com/moira-alert/moira/index/mapping" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" ) type config struct { diff --git a/index/index_test.go b/index/index_test.go index e891f56ee..9330bd7b6 100644 --- a/index/index_test.go +++ b/index/index_test.go @@ -9,11 +9,12 @@ import ( bleveOriginal "github.com/blevesearch/bleve" "github.com/golang/mock/gomock" "github.com/moira-alert/moira" - "github.com/op/go-logging" + . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira/index/bleve" "github.com/moira-alert/moira/index/fixtures" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" ) diff --git a/index/search_test.go b/index/search_test.go index 99f1bc3e8..ed38a726f 100644 --- a/index/search_test.go +++ b/index/search_test.go @@ -6,7 +6,7 @@ import ( "github.com/moira-alert/moira/metrics" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/integration_tests/notifier/notifier_test.go b/integration_tests/notifier/notifier_test.go index 08c9d5602..fea8a47ec 100644 --- a/integration_tests/notifier/notifier_test.go +++ b/integration_tests/notifier/notifier_test.go @@ -8,10 +8,10 @@ import ( "github.com/golang/mock/gomock" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" - "github.com/op/go-logging" "github.com/moira-alert/moira" "github.com/moira-alert/moira/database/redis" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/moira-alert/moira/notifier" @@ -80,9 +80,9 @@ func TestNotifier(t *testing.T) { defer mockCtrl.Finish() database := redis.NewTestDatabase(logger) metricsSourceProvider := metricSource.CreateMetricSourceProvider(local.Create(database), nil) - database.SaveContact(&contact) //nolint - database.SaveSubscription(&subscription) //nolint - database.SaveTrigger(trigger.ID, &trigger) //nolint + database.SaveContact(&contact) //nolint + database.SaveSubscription(&subscription) //nolint + database.SaveTrigger(trigger.ID, &trigger) //nolint database.PushNotificationEvent(&event, true) //nolint notifier2 := notifier.NewNotifier(database, logger, notifierConfig, notifierMetrics, metricsSourceProvider, map[string]moira.ImageStore{}) sender := mock_moira_alert.NewMockSender(mockCtrl) @@ -111,7 +111,7 @@ func TestNotifier(t *testing.T) { waitTestEnd() - fetchEventsWorker.Stop() //nolint + fetchEventsWorker.Stop() //nolint fetchNotificationsWorker.Stop() //nolint } diff --git a/interfaces.go b/interfaces.go index 73640d82b..70c37b6ae 100644 --- a/interfaces.go +++ b/interfaces.go @@ -149,6 +149,16 @@ type Logger interface { Fatalf(format string, args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) + + // Structured logging methods, use to add context fields + String(key, value string) Logger + Int(key string, value int) Logger + Fields(fields map[string]interface{}) Logger + + // Get child logger with the minimum accepted level + Level(string) (Logger, error) + // Returns new copy of log, when need to avoid context duplication + Clone() Logger } // Sender interface for implementing specified contact type sender diff --git a/local/api.yml b/local/api.yml index aee42012f..12703cd58 100644 --- a/local/api.yml +++ b/local/api.yml @@ -43,3 +43,4 @@ web: log: log_file: stdout log_level: debug + log_pretty_format: true diff --git a/local/checker.yml b/local/checker.yml index 2b8715ec0..9c8835875 100644 --- a/local/checker.yml +++ b/local/checker.yml @@ -27,3 +27,4 @@ checker: log: log_file: stdout log_level: debug + log_pretty_format: true diff --git a/local/cli.yml b/local/cli.yml index 862ab9627..ee733b2fc 100644 --- a/local/cli.yml +++ b/local/cli.yml @@ -5,4 +5,4 @@ redis: metrics_ttl: 3h log_file: stdout log_level: debug - +log_pretty_format: true diff --git a/local/filter.yml b/local/filter.yml index 867239cdb..ac9b8517c 100644 --- a/local/filter.yml +++ b/local/filter.yml @@ -22,3 +22,4 @@ filter: log: log_file: stdout log_level: debug + log_pretty_format: true diff --git a/local/notifier.yml b/local/notifier.yml index 335db24c0..8e658808a 100644 --- a/local/notifier.yml +++ b/local/notifier.yml @@ -38,3 +38,4 @@ notifier: log: log_file: stdout log_level: info + log_pretty_format: true diff --git a/logging/go-logging/logger.go b/logging/go-logging/logger.go deleted file mode 100644 index 37cede7f9..000000000 --- a/logging/go-logging/logger.go +++ /dev/null @@ -1,47 +0,0 @@ -package logging - -import ( - "fmt" - "os" - "path/filepath" - - goLogging "github.com/op/go-logging" -) - -// ConfigureLog creates new logger based on github.com/op/go-logging package -func ConfigureLog(logFile, logLevel, module string) (*goLogging.Logger, error) { - log, err := goLogging.GetLogger(module) - if err != nil { - return nil, fmt.Errorf("can't initialize logger: %s", err.Error()) - } - level, err := goLogging.LogLevel(logLevel) - if err != nil { - level = goLogging.DEBUG - } - - goLogging.SetFormatter(goLogging.MustStringFormatter("%{time:2006-01-02 15:04:05.000}\t%{module}\t%{level}\t%{message}")) - logBackend, err := getLogBackend(logFile) - if err != nil { - return nil, err - } - logBackend.Color = false - goLogging.SetBackend(logBackend) - goLogging.SetLevel(level, module) - return log, nil -} - -func getLogBackend(logFileName string) (*goLogging.LogBackend, error) { - if logFileName == "stdout" || logFileName == "" { - return goLogging.NewLogBackend(os.Stdout, "", 0), nil - } - - logDir := filepath.Dir(logFileName) - if err := os.MkdirAll(logDir, 0755); err != nil { - return nil, fmt.Errorf("can't create log directories %s: %s", logDir, err.Error()) - } - logFile, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) - if err != nil { - return nil, fmt.Errorf("can't open log file %s: %s", logFileName, err.Error()) - } - return goLogging.NewLogBackend(logFile, "", 0), nil -} diff --git a/logging/zerolog_adapter/logger.go b/logging/zerolog_adapter/logger.go new file mode 100644 index 000000000..58da5e642 --- /dev/null +++ b/logging/zerolog_adapter/logger.go @@ -0,0 +1,142 @@ +package logging + +import ( + "fmt" + "io" + "os" + "path/filepath" + + "github.com/rs/zerolog" + + "github.com/moira-alert/moira" +) + +type Logger struct { + zerolog.Logger +} + +const ( + ModuleFieldName = "module" + DefaultTimeFormat = "2006-01-02 15:04:05.000" +) + +// ConfigureLog creates new logger based on github.com/rs/zerolog package +func ConfigureLog(logFile, logLevel, module string, pretty bool) (*Logger, error) { + return newLog(logFile, logLevel, module, pretty, false) +} + +// GetLogger need only for backward compatibility in tests +func GetLogger(module string) (moira.Logger, error) { + return newLog("stdout", "info", module, true, true) +} + +func newLog(logFile, logLevel, module string, pretty, colorOff bool) (*Logger, error) { + level, err := zerolog.ParseLevel(logLevel) + if err != nil { + level = zerolog.DebugLevel + } + + logWriter, err := getLogWriter(logFile) + if err != nil { + return nil, err + } + zerolog.TimeFieldFormat = DefaultTimeFormat + + if pretty { + logWriter = zerolog.ConsoleWriter{ + Out: logWriter, + NoColor: colorOff, + TimeFormat: DefaultTimeFormat, + PartsOrder: []string{zerolog.TimestampFieldName, ModuleFieldName, zerolog.LevelFieldName, zerolog.MessageFieldName}, + } + } + + logger := zerolog.New(logWriter).Level(level).With().Str(ModuleFieldName, module).Logger() + return &Logger{logger}, nil +} + +func getLogWriter(logFileName string) (io.Writer, error) { + if logFileName == "stdout" || logFileName == "" { + return os.Stdout, nil + } + + logDir := filepath.Dir(logFileName) + if err := os.MkdirAll(logDir, 0755); err != nil { + return nil, fmt.Errorf("can't create log directories %s: %s", logDir, err.Error()) + } + logFile, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) + if err != nil { + return nil, fmt.Errorf("can't open log file %s: %s", logFileName, err.Error()) + } + return logFile, nil +} + +func (l Logger) Debug(args ...interface{}) { + l.Logger.Debug().Timestamp().Msg(fmt.Sprint(args...)) +} + +func (l Logger) Debugf(format string, args ...interface{}) { + l.Logger.Debug().Timestamp().Msgf(format, args...) +} + +func (l Logger) Info(args ...interface{}) { + l.Logger.Info().Timestamp().Msg(fmt.Sprint(args...)) +} + +func (l Logger) Infof(format string, args ...interface{}) { + l.Logger.Info().Timestamp().Msgf(format, args...) +} + +func (l Logger) Error(args ...interface{}) { + l.Logger.Error().Timestamp().Msgf(fmt.Sprint(args...)) +} + +func (l Logger) Errorf(format string, args ...interface{}) { + l.Logger.Error().Timestamp().Msgf(format, args...) +} + +func (l Logger) Fatal(args ...interface{}) { + l.Logger.Fatal().Timestamp().Msg(fmt.Sprint(args...)) +} + +func (l Logger) Fatalf(format string, args ...interface{}) { + l.Logger.Fatal().Timestamp().Msgf(format, args...) +} + +func (l Logger) Warning(args ...interface{}) { + l.Logger.Warn().Timestamp().Msg(fmt.Sprint(args...)) +} + +func (l Logger) Warningf(format string, args ...interface{}) { + l.Logger.Warn().Timestamp().Msgf(format, args...) +} + +func (l *Logger) String(key, value string) moira.Logger { + l.Logger = l.Logger.With().Str(key, value).Logger() + return l +} + +func (l *Logger) Int(key string, value int) moira.Logger { + l.Logger = l.Logger.With().Int(key, value).Logger() + return l +} + +func (l *Logger) Fields(fields map[string]interface{}) moira.Logger { + l.Logger = l.Logger.With().Fields(fields).Logger() + return l +} + +func (l *Logger) Level(s string) (moira.Logger, error) { + level, err := zerolog.ParseLevel(s) + if err != nil { + return l, err + } + l.Logger = l.Logger.Level(level) + return l, nil +} + +func (l Logger) Clone() moira.Logger { + return &Logger{ + Logger: l.Logger.With().Logger(), + } +} diff --git a/mock/moira-alert/logger.go b/mock/moira-alert/logger.go index f7d40fd45..1212cb376 100644 --- a/mock/moira-alert/logger.go +++ b/mock/moira-alert/logger.go @@ -6,6 +6,7 @@ package mock_moira_alert import ( gomock "github.com/golang/mock/gomock" + "github.com/moira-alert/moira" reflect "reflect" ) @@ -32,6 +33,20 @@ func (m *MockLogger) EXPECT() *MockLoggerMockRecorder { return m.recorder } +// Clone mocks base method +func (m *MockLogger) Clone() moira.Logger { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clone") + ret0, _ := ret[0].(moira.Logger) + return ret0 +} + +// Clone indicates an expected call of Clone +func (mr *MockLoggerMockRecorder) Clone() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clone", reflect.TypeOf((*MockLogger)(nil).Clone)) +} + // Debug mocks base method func (m *MockLogger) Debug(arg0 ...interface{}) { m.ctrl.T.Helper() @@ -131,6 +146,20 @@ func (mr *MockLoggerMockRecorder) Fatalf(arg0 interface{}, arg1 ...interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fatalf", reflect.TypeOf((*MockLogger)(nil).Fatalf), varargs...) } +// Fields mocks base method +func (m *MockLogger) Fields(arg0 map[string]interface{}) moira.Logger { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fields", arg0) + ret0, _ := ret[0].(moira.Logger) + return ret0 +} + +// Fields indicates an expected call of Fields +func (mr *MockLoggerMockRecorder) Fields(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fields", reflect.TypeOf((*MockLogger)(nil).Fields), arg0) +} + // Info mocks base method func (m *MockLogger) Info(arg0 ...interface{}) { m.ctrl.T.Helper() @@ -164,6 +193,49 @@ func (mr *MockLoggerMockRecorder) Infof(arg0 interface{}, arg1 ...interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Infof", reflect.TypeOf((*MockLogger)(nil).Infof), varargs...) } +// Int mocks base method +func (m *MockLogger) Int(arg0 string, arg1 int) moira.Logger { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Int", arg0, arg1) + ret0, _ := ret[0].(moira.Logger) + return ret0 +} + +// Int indicates an expected call of Int +func (mr *MockLoggerMockRecorder) Int(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Int", reflect.TypeOf((*MockLogger)(nil).Int), arg0, arg1) +} + +// Level mocks base method +func (m *MockLogger) Level(arg0 string) (moira.Logger, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Level", arg0) + ret0, _ := ret[0].(moira.Logger) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Level indicates an expected call of Level +func (mr *MockLoggerMockRecorder) Level(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Level", reflect.TypeOf((*MockLogger)(nil).Level), arg0) +} + +// String mocks base method +func (m *MockLogger) String(arg0, arg1 string) moira.Logger { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "String", arg0, arg1) + ret0, _ := ret[0].(moira.Logger) + return ret0 +} + +// String indicates an expected call of String +func (mr *MockLoggerMockRecorder) String(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "String", reflect.TypeOf((*MockLogger)(nil).String), arg0, arg1) +} + // Warning mocks base method func (m *MockLogger) Warning(arg0 ...interface{}) { m.ctrl.T.Helper() diff --git a/notifier/events/event_test.go b/notifier/events/event_test.go index c186ea63e..3632d7856 100644 --- a/notifier/events/event_test.go +++ b/notifier/events/event_test.go @@ -6,7 +6,7 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/notifier/notifications/notifications_test.go b/notifier/notifications/notifications_test.go index ee22a12cf..4806063db 100644 --- a/notifier/notifications/notifications_test.go +++ b/notifier/notifications/notifications_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" @@ -97,7 +97,7 @@ func TestProcessScheduledEvent(t *testing.T) { }) Convey("Two same notifications, should send one package", t, func() { - dataBase.EXPECT().FetchNotifications(gomock.Any(), notifier2.NotificationsLimitUnlimited).Return([]*moira.ScheduledNotification{ //nolint + dataBase.EXPECT().FetchNotifications(gomock.Any(), notifier2.NotificationsLimitUnlimited).Return([]*moira.ScheduledNotification{ //nolint ¬ification2, ¬ification3, }, nil) diff --git a/notifier/notifier_test.go b/notifier/notifier_test.go index 88d52e3b4..03b2f4491 100644 --- a/notifier/notifier_test.go +++ b/notifier/notifier_test.go @@ -7,9 +7,9 @@ import ( "time" "github.com/golang/mock/gomock" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" diff --git a/notifier/plotting_test.go b/notifier/plotting_test.go index c027afd8f..1500f5c69 100644 --- a/notifier/plotting_test.go +++ b/notifier/plotting_test.go @@ -10,11 +10,11 @@ import ( "github.com/gofrs/uuid" "github.com/golang/mock/gomock" "github.com/moira-alert/moira" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" metricSource "github.com/moira-alert/moira/metric_source" "github.com/moira-alert/moira/metric_source/local" mockMetricSource "github.com/moira-alert/moira/mock/metric_source" "github.com/moira-alert/moira/plotting" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/scheduler_test.go b/notifier/scheduler_test.go index ab33444c6..cf7b43bb4 100644 --- a/notifier/scheduler_test.go +++ b/notifier/scheduler_test.go @@ -7,9 +7,9 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/heartbeat/database_test.go b/notifier/selfstate/heartbeat/database_test.go index 1e36dd513..267a6718e 100644 --- a/notifier/selfstate/heartbeat/database_test.go +++ b/notifier/selfstate/heartbeat/database_test.go @@ -8,7 +8,7 @@ import ( mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/heartbeat/filter_test.go b/notifier/selfstate/heartbeat/filter_test.go index 935083eeb..d1fd88c7d 100644 --- a/notifier/selfstate/heartbeat/filter_test.go +++ b/notifier/selfstate/heartbeat/filter_test.go @@ -10,7 +10,7 @@ import ( mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/heartbeat/local_checker_test.go b/notifier/selfstate/heartbeat/local_checker_test.go index ac08f400c..0899eb54c 100644 --- a/notifier/selfstate/heartbeat/local_checker_test.go +++ b/notifier/selfstate/heartbeat/local_checker_test.go @@ -9,7 +9,7 @@ import ( mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/heartbeat/notifier_test.go b/notifier/selfstate/heartbeat/notifier_test.go index aff3b0857..1e865737d 100644 --- a/notifier/selfstate/heartbeat/notifier_test.go +++ b/notifier/selfstate/heartbeat/notifier_test.go @@ -8,7 +8,7 @@ import ( mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/heartbeat/remote_checker_test.go b/notifier/selfstate/heartbeat/remote_checker_test.go index 52b916ec7..9aa142129 100644 --- a/notifier/selfstate/heartbeat/remote_checker_test.go +++ b/notifier/selfstate/heartbeat/remote_checker_test.go @@ -8,7 +8,7 @@ import ( mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/golang/mock/gomock" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/notifier/selfstate/selfstate_test.go b/notifier/selfstate/selfstate_test.go index 85a046d70..7bdcbb282 100644 --- a/notifier/selfstate/selfstate_test.go +++ b/notifier/selfstate/selfstate_test.go @@ -11,9 +11,9 @@ import ( "github.com/moira-alert/moira" "github.com/golang/mock/gomock" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" mock_notifier "github.com/moira-alert/moira/mock/notifier" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) diff --git a/perfomance_tests/filter/filter_test.go b/perfomance_tests/filter/filter_test.go index 1c68f5ce9..1165f1615 100644 --- a/perfomance_tests/filter/filter_test.go +++ b/perfomance_tests/filter/filter_test.go @@ -12,9 +12,9 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira/filter" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/moira-alert/moira/metrics" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" ) func BenchmarkProcessIncomingMetric(b *testing.B) { diff --git a/pkg/api/api.yml b/pkg/api/api.yml index 374c58434..6a1f645a3 100644 --- a/pkg/api/api.yml +++ b/pkg/api/api.yml @@ -33,3 +33,4 @@ web: log: log_file: stdout log_level: info + log_pretty_format: false diff --git a/pkg/checker/checker.yml b/pkg/checker/checker.yml index b7e8bb093..65bd0cae2 100644 --- a/pkg/checker/checker.yml +++ b/pkg/checker/checker.yml @@ -21,3 +21,4 @@ checker: log: log_file: stdout log_level: info + log_pretty_format: false diff --git a/pkg/cli/cli.yml b/pkg/cli/cli.yml index 7440783a9..6f25df8eb 100644 --- a/pkg/cli/cli.yml +++ b/pkg/cli/cli.yml @@ -4,4 +4,4 @@ redis: dbid: 0 log_file: stdout log_level: info - +log_pretty_format: false diff --git a/pkg/filter/filter.yml b/pkg/filter/filter.yml index 632c1a74f..74fd1a120 100644 --- a/pkg/filter/filter.yml +++ b/pkg/filter/filter.yml @@ -17,3 +17,4 @@ filter: log: log_file: stdout log_level: info + log_pretty_format: false diff --git a/pkg/notifier/notifier.yml b/pkg/notifier/notifier.yml index b79a524ee..3eb24706a 100644 --- a/pkg/notifier/notifier.yml +++ b/pkg/notifier/notifier.yml @@ -30,3 +30,4 @@ notifier: log: log_file: stdout log_level: info + log_pretty_format: false diff --git a/senders/discord/init_test.go b/senders/discord/init_test.go index c20f10bc3..a00315d13 100644 --- a/senders/discord/init_test.go +++ b/senders/discord/init_test.go @@ -7,7 +7,7 @@ import ( "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) @@ -26,7 +26,7 @@ func (db *MockDB) NewLock(name string, ttl time.Duration) moira.Lock { } func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") Convey("Init tests", t, func() { sender := Sender{DataBase: &MockDB{}} diff --git a/senders/mail/send_test.go b/senders/mail/send_test.go index be13e3ac0..d14a43000 100644 --- a/senders/mail/send_test.go +++ b/senders/mail/send_test.go @@ -8,12 +8,12 @@ import ( "time" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestMakeMessage(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) contact := moira.ContactData{ ID: "ContactID-000000000000001", Type: "email", @@ -76,7 +76,7 @@ func generateTestEvents(n int, subscriptionID string) []moira.NotificationEvent } func TestEmptyTriggerID(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) contact := moira.ContactData{ ID: "ContactID-000000000000001", Type: "email", diff --git a/senders/msteams/msteams_test.go b/senders/msteams/msteams_test.go index b35cebd2c..d9e8a40a7 100644 --- a/senders/msteams/msteams_test.go +++ b/senders/msteams/msteams_test.go @@ -5,13 +5,13 @@ import ( "time" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "gopkg.in/h2non/gock.v1" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) Convey("Init tests", t, func() { sender := Sender{} senderSettings := map[string]string{ @@ -32,7 +32,7 @@ func TestInit(t *testing.T) { func TestMSTeamsHttpResponse(t *testing.T) { sender := Sender{} - logger, _ := logging.ConfigureLog("stdout", "info", "test") + logger, _ := logging.ConfigureLog("stdout", "info", "test", true) location, _ := time.LoadLocation("UTC") _ = sender.Init(map[string]string{ "max_events": "-1", diff --git a/senders/opsgenie/init_test.go b/senders/opsgenie/init_test.go index 491639993..744390b6f 100644 --- a/senders/opsgenie/init_test.go +++ b/senders/opsgenie/init_test.go @@ -8,13 +8,13 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() diff --git a/senders/opsgenie/send_test.go b/senders/opsgenie/send_test.go index 21be9a803..9cf2404ed 100644 --- a/senders/opsgenie/send_test.go +++ b/senders/opsgenie/send_test.go @@ -6,7 +6,7 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" - logging "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" "github.com/opsgenie/opsgenie-go-sdk-v2/alert" . "github.com/smartystreets/goconvey/convey" @@ -120,7 +120,7 @@ func TestBuildTitle(t *testing.T) { func TestMakeCreateAlertRequest(t *testing.T) { location, _ := time.LoadLocation("UTC") - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() imageStore := mock_moira_alert.NewMockImageStore(mockCtrl) diff --git a/senders/pagerduty/init_test.go b/senders/pagerduty/init_test.go index 5db58a054..59c8195c8 100644 --- a/senders/pagerduty/init_test.go +++ b/senders/pagerduty/init_test.go @@ -8,12 +8,12 @@ import ( "github.com/moira-alert/moira" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() diff --git a/senders/pushover/pushover_test.go b/senders/pushover/pushover_test.go index 7462a948b..8b34d8ab1 100644 --- a/senders/pushover/pushover_test.go +++ b/senders/pushover/pushover_test.go @@ -8,12 +8,12 @@ import ( "github.com/gregdel/pushover" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestSender_Init(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) Convey("Empty map", t, func() { sender := Sender{} err := sender.Init(map[string]string{}, logger, nil, "") @@ -146,7 +146,7 @@ func TestBuildTitle(t *testing.T) { func TestMakePushoverMessage(t *testing.T) { location, _ := time.LoadLocation("UTC") - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) sender := Sender{ frontURI: "https://my-moira.com", diff --git a/senders/script/script_test.go b/senders/script/script_test.go index bbdd59a94..154f72b7e 100644 --- a/senders/script/script_test.go +++ b/senders/script/script_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) @@ -45,7 +45,7 @@ var execStringTestCases = []execStringTestCase{ } func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) Convey("Init tests", t, func() { sender := Sender{} settings := map[string]string{} @@ -79,7 +79,7 @@ func TestInit(t *testing.T) { } func TestBuildCommandData(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) Convey("Test send events", t, func() { sender := Sender{exec: "script.go first second", logger: logger} scriptFile, args, scriptBody, err := sender.buildCommandData([]moira.NotificationEvent{{Metric: "New metric"}}, moira.ContactData{ID: "ContactID"}, moira.TriggerData{ID: "TriggerID"}, true) diff --git a/senders/selfstate/selfstate_test.go b/senders/selfstate/selfstate_test.go index 8ac14a0c4..d64e13462 100644 --- a/senders/selfstate/selfstate_test.go +++ b/senders/selfstate/selfstate_test.go @@ -8,7 +8,7 @@ import ( . "github.com/smartystreets/goconvey/convey" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" ) @@ -39,7 +39,7 @@ func TestSender_SendEvents(t *testing.T) { defer mockCtrl.Finish() dataBase := mock_moira_alert.NewMockDatabase(mockCtrl) - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) sender := Sender{Database: dataBase, logger: logger} Convey("Has connection to database", t, func() { diff --git a/senders/slack/slack_test.go b/senders/slack/slack_test.go index 1bf0feda8..d4a201b0c 100644 --- a/senders/slack/slack_test.go +++ b/senders/slack/slack_test.go @@ -7,13 +7,13 @@ import ( "time" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" "github.com/nlopes/slack" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) Convey("Init tests", t, func() { sender := Sender{} senderSettings := map[string]string{} diff --git a/senders/telegram/init_test.go b/senders/telegram/init_test.go index 4cb448b16..24c8aac3f 100644 --- a/senders/telegram/init_test.go +++ b/senders/telegram/init_test.go @@ -5,12 +5,12 @@ import ( "testing" "time" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") Convey("Init tests", t, func() { sender := Sender{} diff --git a/senders/twilio/sms_test.go b/senders/twilio/sms_test.go index 16e52aea8..7f6c8d2c0 100644 --- a/senders/twilio/sms_test.go +++ b/senders/twilio/sms_test.go @@ -6,7 +6,7 @@ import ( twilio "github.com/carlosdp/twiliogo" "github.com/moira-alert/moira" - logging "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) @@ -67,7 +67,7 @@ Please, fix your system or tune this trigger to generate less events.` } func TestTwilioSenderSms_SendEvents(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") sender := twilioSenderSms{ twilioSender: twilioSender{ diff --git a/senders/twilio/twilio_test.go b/senders/twilio/twilio_test.go index 1fc5b8e10..8d886a788 100644 --- a/senders/twilio/twilio_test.go +++ b/senders/twilio/twilio_test.go @@ -6,14 +6,14 @@ import ( "time" twilio "github.com/carlosdp/twiliogo" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { Convey("Tests init twilio sender", t, func() { sender := Sender{} - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") settings := map[string]string{} Convey("no api asid", func() { diff --git a/senders/twilio/voice_test.go b/senders/twilio/voice_test.go index 2483ef381..17ca6e501 100644 --- a/senders/twilio/voice_test.go +++ b/senders/twilio/voice_test.go @@ -5,14 +5,14 @@ import ( twilio "github.com/carlosdp/twiliogo" "github.com/moira-alert/moira" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" "testing" ) func TestTwilioSenderVoice_SendEvents(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") sender := twilioSenderVoice{ twilioSender: twilioSender{ diff --git a/senders/victorops/init_test.go b/senders/victorops/init_test.go index de9911faf..b3f0d5b3c 100644 --- a/senders/victorops/init_test.go +++ b/senders/victorops/init_test.go @@ -9,13 +9,13 @@ import ( "github.com/moira-alert/moira" "github.com/moira-alert/moira/senders/victorops/api" - "github.com/moira-alert/moira/logging/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" . "github.com/smartystreets/goconvey/convey" ) func TestInit(t *testing.T) { - logger, _ := logging.ConfigureLog("stdout", "debug", "test") + logger, _ := logging.ConfigureLog("stdout", "debug", "test", true) location, _ := time.LoadLocation("UTC") mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() diff --git a/senders/webhook/webhook_test.go b/senders/webhook/webhook_test.go index d4927bf94..9918711e9 100644 --- a/senders/webhook/webhook_test.go +++ b/senders/webhook/webhook_test.go @@ -14,7 +14,7 @@ import ( "github.com/moira-alert/moira" - "github.com/op/go-logging" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" . "github.com/smartystreets/goconvey/convey" ) diff --git a/worker/worker_test.go b/worker/worker_test.go index 05a75f52a..63c0dacb5 100644 --- a/worker/worker_test.go +++ b/worker/worker_test.go @@ -9,8 +9,8 @@ import ( "github.com/golang/mock/gomock" "github.com/moira-alert/moira" "github.com/moira-alert/moira/database" + logging "github.com/moira-alert/moira/logging/zerolog_adapter" mock_moira_alert "github.com/moira-alert/moira/mock/moira-alert" - "github.com/op/go-logging" . "github.com/smartystreets/goconvey/convey" ) @@ -157,9 +157,10 @@ func createTestWorkerWithDefaultAction(lock moira.Lock) *Worker { } func createTestWorkerWithAction(lock moira.Lock, action Action) *Worker { + log, _ := logging.GetLogger("Test Worker") worker := NewWorker( "Test Worker", - logging.MustGetLogger("Test Worker"), + log, lock, action, )