From bf713cbf805c19def0c3badf7ed23a05d5e1b8f2 Mon Sep 17 00:00:00 2001 From: schmidtw Date: Thu, 4 Apr 2024 20:47:06 -0700 Subject: [PATCH 1/3] Add more sane default values, and move the logging configuration into the default instead of built in. --- cmd/xmidt-agent/config.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/xmidt-agent/main.go | 18 ++---------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/cmd/xmidt-agent/config.go b/cmd/xmidt-agent/config.go index 247bbb3..e4648bf 100644 --- a/cmd/xmidt-agent/config.go +++ b/cmd/xmidt-agent/config.go @@ -4,6 +4,7 @@ package main import ( + "crypto/tls" "fmt" "io/fs" "net/http" @@ -12,9 +13,11 @@ import ( "github.com/goschtalt/goschtalt" "github.com/xmidt-org/arrange/arrangehttp" + "github.com/xmidt-org/arrange/arrangetls" "github.com/xmidt-org/retry" "github.com/xmidt-org/sallust" "github.com/xmidt-org/wrp-go/v3" + "go.uber.org/zap/zapcore" "gopkg.in/dealancer/validate.v2" ) @@ -253,8 +256,22 @@ var defaultConfig = Config{ RefetchPercent: 90.0, FileName: "credentials.msgpack", FilePermissions: fs.FileMode(0600), + HTTPClient: arrangehttp.ClientConfig{ + Timeout: 20 * time.Second, + Transport: arrangehttp.TransportConfig{ + DisableKeepAlives: true, + MaxIdleConns: 1, + }, + TLS: &arrangetls.Config{ + MinVersion: tls.VersionTLS13, + }, + }, }, XmidtService: XmidtService{ + Backoff: Backoff{ + MinDelay: 7 * time.Second, + MaxDelay: 10 * time.Minute, + }, JwtTxtRedirector: JwtTxtRedirector{ Timeout: 10 * time.Second, AllowedAlgorithms: []string{ @@ -307,6 +324,27 @@ var defaultConfig = Config{ Pubsub: Pubsub{ PublishTimeout: 200 * time.Millisecond, }, + Logger: sallust.Config{ + EncoderConfig: sallust.EncoderConfig{ + TimeKey: "T", + LevelKey: "L", + NameKey: "N", + CallerKey: "C", + FunctionKey: zapcore.OmitKey, + MessageKey: "M", + StacktraceKey: "S", + LineEnding: zapcore.DefaultLineEnding, + EncodeLevel: "capital", + EncodeTime: "RFC3339Nano", + EncodeDuration: "string", + EncodeCaller: "short", + }, + Rotation: &sallust.Rotation{ + MaxSize: 1 * 1024 * 1024, // 1MB max/file + MaxAge: 30, // 30 days max + MaxBackups: 10, // max 10 files + }, + }, MockTr181: MockTr181{ FilePath: "./mock_tr181.json", }, diff --git a/cmd/xmidt-agent/main.go b/cmd/xmidt-agent/main.go index f7aaceb..530e9f0 100644 --- a/cmd/xmidt-agent/main.go +++ b/cmd/xmidt-agent/main.go @@ -24,7 +24,6 @@ import ( "go.uber.org/fx" "go.uber.org/fx/fxevent" "go.uber.org/zap" - "go.uber.org/zap/zapcore" ) const ( @@ -188,22 +187,9 @@ type LoggerIn struct { // Create the logger and configure it based on if the program is in // debug mode or normal mode. func provideLogger(in LoggerIn) (*zap.Logger, error) { - in.Cfg.EncoderConfig = sallust.EncoderConfig{ - TimeKey: "T", - LevelKey: "L", - NameKey: "N", - CallerKey: "C", - FunctionKey: zapcore.OmitKey, - MessageKey: "M", - StacktraceKey: "S", - LineEnding: zapcore.DefaultLineEnding, - EncodeLevel: "capitalColor", - EncodeTime: "RFC3339", - EncodeDuration: "string", - EncodeCaller: "short", - } - if in.CLI.Dev { + in.Cfg.EncoderConfig.EncodeLevel = "capitalColor" + in.Cfg.EncoderConfig.EncodeTime = "RFC3339" in.Cfg.Level = "DEBUG" in.Cfg.Development = true in.Cfg.Encoding = "console" From 1718b02637ee45401b371f87ef0b1f789c76c9a1 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Fri, 5 Apr 2024 09:29:22 -0700 Subject: [PATCH 2/3] Update cmd/xmidt-agent/config.go Co-authored-by: Owen Cabalceta --- cmd/xmidt-agent/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/xmidt-agent/config.go b/cmd/xmidt-agent/config.go index e4648bf..1130c09 100644 --- a/cmd/xmidt-agent/config.go +++ b/cmd/xmidt-agent/config.go @@ -340,7 +340,7 @@ var defaultConfig = Config{ EncodeCaller: "short", }, Rotation: &sallust.Rotation{ - MaxSize: 1 * 1024 * 1024, // 1MB max/file + MaxSize: 1 // 1MB max/file MaxAge: 30, // 30 days max MaxBackups: 10, // max 10 files }, From 0de1e1a45278d47fc39d376ed74bd4187aaee64b Mon Sep 17 00:00:00 2001 From: schmidtw Date: Fri, 5 Apr 2024 09:31:22 -0700 Subject: [PATCH 3/3] Fix the missing comma and formatting. --- cmd/xmidt-agent/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/xmidt-agent/config.go b/cmd/xmidt-agent/config.go index 1130c09..444aa6b 100644 --- a/cmd/xmidt-agent/config.go +++ b/cmd/xmidt-agent/config.go @@ -340,9 +340,9 @@ var defaultConfig = Config{ EncodeCaller: "short", }, Rotation: &sallust.Rotation{ - MaxSize: 1 // 1MB max/file - MaxAge: 30, // 30 days max - MaxBackups: 10, // max 10 files + MaxSize: 1, // 1MB max/file + MaxAge: 30, // 30 days max + MaxBackups: 10, // max 10 files }, }, MockTr181: MockTr181{