Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more sane default values, and move the logging configuration into… #68

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cmd/xmidt-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"crypto/tls"
"fmt"
"io/fs"
"net/http"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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, // 1MB max/file
MaxAge: 30, // 30 days max
MaxBackups: 10, // max 10 files
},
},
MockTr181: MockTr181{
FilePath: "./mock_tr181.json",
},
Expand Down
18 changes: 2 additions & 16 deletions cmd/xmidt-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"go.uber.org/fx"
"go.uber.org/fx/fxevent"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

const (
Expand Down Expand Up @@ -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"
Expand Down
Loading