config: use logging.Config in RuntimeConfig

To add structure to RuntimeConfig, and remove the need to translate into a third type.
This commit is contained in:
Daniel Nephin 2020-08-19 13:17:05 -04:00
parent e4578aace8
commit a97adadd2b
6 changed files with 154 additions and 198 deletions

View File

@ -3662,11 +3662,11 @@ func (a *Agent) ReloadConfig() error {
// runtime configuration and applies it. // runtime configuration and applies it.
func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error { func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error {
// Change the log level and update it // Change the log level and update it
if logging.ValidateLogLevel(newCfg.LogLevel) { if logging.ValidateLogLevel(newCfg.Logging.LogLevel) {
a.logger.SetLevel(logging.LevelFromString(newCfg.LogLevel)) a.logger.SetLevel(logging.LevelFromString(newCfg.Logging.LogLevel))
} else { } else {
a.logger.Warn("Invalid log level in new configuration", "level", newCfg.LogLevel) a.logger.Warn("Invalid log level in new configuration", "level", newCfg.Logging.LogLevel)
newCfg.LogLevel = a.config.LogLevel newCfg.Logging.LogLevel = a.config.Logging.LogLevel
} }
// Bulk update the services and checks // Bulk update the services and checks

View File

@ -25,6 +25,7 @@ import (
"github.com/hashicorp/consul/ipaddr" "github.com/hashicorp/consul/ipaddr"
"github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/lib"
libtempl "github.com/hashicorp/consul/lib/template" libtempl "github.com/hashicorp/consul/lib/template"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/tlsutil" "github.com/hashicorp/consul/tlsutil"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
"github.com/hashicorp/go-bexpr" "github.com/hashicorp/go-bexpr"
@ -971,91 +972,94 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
EnableDebug: b.boolVal(c.EnableDebug), EnableDebug: b.boolVal(c.EnableDebug),
EnableRemoteScriptChecks: enableRemoteScriptChecks, EnableRemoteScriptChecks: enableRemoteScriptChecks,
EnableLocalScriptChecks: enableLocalScriptChecks, EnableLocalScriptChecks: enableLocalScriptChecks,
EnableSyslog: b.boolVal(c.EnableSyslog),
EnableUI: b.boolVal(c.UI), EnableUI: b.boolVal(c.UI),
EncryptKey: b.stringVal(c.EncryptKey), EncryptKey: b.stringVal(c.EncryptKey),
EncryptVerifyIncoming: b.boolVal(c.EncryptVerifyIncoming), EncryptVerifyIncoming: b.boolVal(c.EncryptVerifyIncoming),
EncryptVerifyOutgoing: b.boolVal(c.EncryptVerifyOutgoing), EncryptVerifyOutgoing: b.boolVal(c.EncryptVerifyOutgoing),
GRPCPort: grpcPort, GRPCPort: grpcPort,
GRPCAddrs: grpcAddrs, GRPCAddrs: grpcAddrs,
HTTPMaxConnsPerClient: b.intVal(c.Limits.HTTPMaxConnsPerClient), HTTPMaxConnsPerClient: b.intVal(c.Limits.HTTPMaxConnsPerClient),
HTTPSHandshakeTimeout: b.durationVal("limits.https_handshake_timeout", c.Limits.HTTPSHandshakeTimeout), HTTPSHandshakeTimeout: b.durationVal("limits.https_handshake_timeout", c.Limits.HTTPSHandshakeTimeout),
KeyFile: b.stringVal(c.KeyFile), KeyFile: b.stringVal(c.KeyFile),
KVMaxValueSize: b.uint64Val(c.Limits.KVMaxValueSize), KVMaxValueSize: b.uint64Val(c.Limits.KVMaxValueSize),
LeaveDrainTime: b.durationVal("performance.leave_drain_time", c.Performance.LeaveDrainTime), LeaveDrainTime: b.durationVal("performance.leave_drain_time", c.Performance.LeaveDrainTime),
LeaveOnTerm: leaveOnTerm, LeaveOnTerm: leaveOnTerm,
LogLevel: b.stringVal(c.LogLevel), Logging: logging.Config{
LogJSON: b.boolVal(c.LogJSON), LogLevel: b.stringVal(c.LogLevel),
LogFile: b.stringVal(c.LogFile), LogJSON: b.boolVal(c.LogJSON),
LogRotateBytes: b.intVal(c.LogRotateBytes), LogFilePath: b.stringVal(c.LogFile),
LogRotateDuration: b.durationVal("log_rotate_duration", c.LogRotateDuration), EnableSyslog: b.boolVal(c.EnableSyslog),
LogRotateMaxFiles: b.intVal(c.LogRotateMaxFiles), SyslogFacility: b.stringVal(c.SyslogFacility),
MaxQueryTime: b.durationVal("max_query_time", c.MaxQueryTime), LogRotateDuration: b.durationVal("log_rotate_duration", c.LogRotateDuration),
NodeID: types.NodeID(b.stringVal(c.NodeID)), LogRotateBytes: b.intVal(c.LogRotateBytes),
NodeMeta: c.NodeMeta, LogRotateMaxFiles: b.intVal(c.LogRotateMaxFiles),
NodeName: b.nodeName(c.NodeName), },
NonVotingServer: b.boolVal(c.NonVotingServer), MaxQueryTime: b.durationVal("max_query_time", c.MaxQueryTime),
PidFile: b.stringVal(c.PidFile), NodeID: types.NodeID(b.stringVal(c.NodeID)),
PrimaryDatacenter: primaryDatacenter, NodeMeta: c.NodeMeta,
PrimaryGateways: b.expandAllOptionalAddrs("primary_gateways", c.PrimaryGateways), NodeName: b.nodeName(c.NodeName),
PrimaryGatewaysInterval: b.durationVal("primary_gateways_interval", c.PrimaryGatewaysInterval), NonVotingServer: b.boolVal(c.NonVotingServer),
RPCAdvertiseAddr: rpcAdvertiseAddr, PidFile: b.stringVal(c.PidFile),
RPCBindAddr: rpcBindAddr, PrimaryDatacenter: primaryDatacenter,
RPCHandshakeTimeout: b.durationVal("limits.rpc_handshake_timeout", c.Limits.RPCHandshakeTimeout), PrimaryGateways: b.expandAllOptionalAddrs("primary_gateways", c.PrimaryGateways),
RPCHoldTimeout: b.durationVal("performance.rpc_hold_timeout", c.Performance.RPCHoldTimeout), PrimaryGatewaysInterval: b.durationVal("primary_gateways_interval", c.PrimaryGatewaysInterval),
RPCMaxBurst: b.intVal(c.Limits.RPCMaxBurst), RPCAdvertiseAddr: rpcAdvertiseAddr,
RPCMaxConnsPerClient: b.intVal(c.Limits.RPCMaxConnsPerClient), RPCBindAddr: rpcBindAddr,
RPCProtocol: b.intVal(c.RPCProtocol), RPCHandshakeTimeout: b.durationVal("limits.rpc_handshake_timeout", c.Limits.RPCHandshakeTimeout),
RPCRateLimit: rate.Limit(b.float64Val(c.Limits.RPCRate)), RPCHoldTimeout: b.durationVal("performance.rpc_hold_timeout", c.Performance.RPCHoldTimeout),
RaftProtocol: b.intVal(c.RaftProtocol), RPCMaxBurst: b.intVal(c.Limits.RPCMaxBurst),
RaftSnapshotThreshold: b.intVal(c.RaftSnapshotThreshold), RPCMaxConnsPerClient: b.intVal(c.Limits.RPCMaxConnsPerClient),
RaftSnapshotInterval: b.durationVal("raft_snapshot_interval", c.RaftSnapshotInterval), RPCProtocol: b.intVal(c.RPCProtocol),
RaftTrailingLogs: b.intVal(c.RaftTrailingLogs), RPCRateLimit: rate.Limit(b.float64Val(c.Limits.RPCRate)),
ReconnectTimeoutLAN: b.durationVal("reconnect_timeout", c.ReconnectTimeoutLAN), RaftProtocol: b.intVal(c.RaftProtocol),
ReconnectTimeoutWAN: b.durationVal("reconnect_timeout_wan", c.ReconnectTimeoutWAN), RaftSnapshotThreshold: b.intVal(c.RaftSnapshotThreshold),
RejoinAfterLeave: b.boolVal(c.RejoinAfterLeave), RaftSnapshotInterval: b.durationVal("raft_snapshot_interval", c.RaftSnapshotInterval),
RetryJoinIntervalLAN: b.durationVal("retry_interval", c.RetryJoinIntervalLAN), RaftTrailingLogs: b.intVal(c.RaftTrailingLogs),
RetryJoinIntervalWAN: b.durationVal("retry_interval_wan", c.RetryJoinIntervalWAN), ReconnectTimeoutLAN: b.durationVal("reconnect_timeout", c.ReconnectTimeoutLAN),
RetryJoinLAN: b.expandAllOptionalAddrs("retry_join", c.RetryJoinLAN), ReconnectTimeoutWAN: b.durationVal("reconnect_timeout_wan", c.ReconnectTimeoutWAN),
RetryJoinMaxAttemptsLAN: b.intVal(c.RetryJoinMaxAttemptsLAN), RejoinAfterLeave: b.boolVal(c.RejoinAfterLeave),
RetryJoinMaxAttemptsWAN: b.intVal(c.RetryJoinMaxAttemptsWAN), RetryJoinIntervalLAN: b.durationVal("retry_interval", c.RetryJoinIntervalLAN),
RetryJoinWAN: b.expandAllOptionalAddrs("retry_join_wan", c.RetryJoinWAN), RetryJoinIntervalWAN: b.durationVal("retry_interval_wan", c.RetryJoinIntervalWAN),
SegmentName: b.stringVal(c.SegmentName), RetryJoinLAN: b.expandAllOptionalAddrs("retry_join", c.RetryJoinLAN),
Segments: segments, RetryJoinMaxAttemptsLAN: b.intVal(c.RetryJoinMaxAttemptsLAN),
SerfAdvertiseAddrLAN: serfAdvertiseAddrLAN, RetryJoinMaxAttemptsWAN: b.intVal(c.RetryJoinMaxAttemptsWAN),
SerfAdvertiseAddrWAN: serfAdvertiseAddrWAN, RetryJoinWAN: b.expandAllOptionalAddrs("retry_join_wan", c.RetryJoinWAN),
SerfAllowedCIDRsLAN: serfAllowedCIDRSLAN, SegmentName: b.stringVal(c.SegmentName),
SerfAllowedCIDRsWAN: serfAllowedCIDRSWAN, Segments: segments,
SerfBindAddrLAN: serfBindAddrLAN, SerfAdvertiseAddrLAN: serfAdvertiseAddrLAN,
SerfBindAddrWAN: serfBindAddrWAN, SerfAdvertiseAddrWAN: serfAdvertiseAddrWAN,
SerfPortLAN: serfPortLAN, SerfAllowedCIDRsLAN: serfAllowedCIDRSLAN,
SerfPortWAN: serfPortWAN, SerfAllowedCIDRsWAN: serfAllowedCIDRSWAN,
ServerMode: b.boolVal(c.ServerMode), SerfBindAddrLAN: serfBindAddrLAN,
ServerName: b.stringVal(c.ServerName), SerfBindAddrWAN: serfBindAddrWAN,
ServerPort: serverPort, SerfPortLAN: serfPortLAN,
Services: services, SerfPortWAN: serfPortWAN,
SessionTTLMin: b.durationVal("session_ttl_min", c.SessionTTLMin), ServerMode: b.boolVal(c.ServerMode),
SkipLeaveOnInt: skipLeaveOnInt, ServerName: b.stringVal(c.ServerName),
StartJoinAddrsLAN: b.expandAllOptionalAddrs("start_join", c.StartJoinAddrsLAN), ServerPort: serverPort,
StartJoinAddrsWAN: b.expandAllOptionalAddrs("start_join_wan", c.StartJoinAddrsWAN), Services: services,
SyslogFacility: b.stringVal(c.SyslogFacility), SessionTTLMin: b.durationVal("session_ttl_min", c.SessionTTLMin),
TLSCipherSuites: b.tlsCipherSuites("tls_cipher_suites", c.TLSCipherSuites), SkipLeaveOnInt: skipLeaveOnInt,
TLSMinVersion: b.stringVal(c.TLSMinVersion), StartJoinAddrsLAN: b.expandAllOptionalAddrs("start_join", c.StartJoinAddrsLAN),
TLSPreferServerCipherSuites: b.boolVal(c.TLSPreferServerCipherSuites), StartJoinAddrsWAN: b.expandAllOptionalAddrs("start_join_wan", c.StartJoinAddrsWAN),
TaggedAddresses: c.TaggedAddresses, TLSCipherSuites: b.tlsCipherSuites("tls_cipher_suites", c.TLSCipherSuites),
TranslateWANAddrs: b.boolVal(c.TranslateWANAddrs), TLSMinVersion: b.stringVal(c.TLSMinVersion),
TxnMaxReqLen: b.uint64Val(c.Limits.TxnMaxReqLen), TLSPreferServerCipherSuites: b.boolVal(c.TLSPreferServerCipherSuites),
UIDir: b.stringVal(c.UIDir), TaggedAddresses: c.TaggedAddresses,
UIContentPath: UIPathBuilder(b.stringVal(c.UIContentPath)), TranslateWANAddrs: b.boolVal(c.TranslateWANAddrs),
UnixSocketGroup: b.stringVal(c.UnixSocket.Group), TxnMaxReqLen: b.uint64Val(c.Limits.TxnMaxReqLen),
UnixSocketMode: b.stringVal(c.UnixSocket.Mode), UIDir: b.stringVal(c.UIDir),
UnixSocketUser: b.stringVal(c.UnixSocket.User), UIContentPath: UIPathBuilder(b.stringVal(c.UIContentPath)),
VerifyIncoming: b.boolVal(c.VerifyIncoming), UnixSocketGroup: b.stringVal(c.UnixSocket.Group),
VerifyIncomingHTTPS: b.boolVal(c.VerifyIncomingHTTPS), UnixSocketMode: b.stringVal(c.UnixSocket.Mode),
VerifyIncomingRPC: b.boolVal(c.VerifyIncomingRPC), UnixSocketUser: b.stringVal(c.UnixSocket.User),
VerifyOutgoing: verifyOutgoing, VerifyIncoming: b.boolVal(c.VerifyIncoming),
VerifyServerHostname: verifyServerName, VerifyIncomingHTTPS: b.boolVal(c.VerifyIncomingHTTPS),
Watches: c.Watches, VerifyIncomingRPC: b.boolVal(c.VerifyIncomingRPC),
VerifyOutgoing: verifyOutgoing,
VerifyServerHostname: verifyServerName,
Watches: c.Watches,
} }
if rt.Cache.EntryFetchMaxBurst <= 0 { if rt.Cache.EntryFetchMaxBurst <= 0 {

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/tlsutil" "github.com/hashicorp/consul/tlsutil"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
"github.com/hashicorp/go-uuid" "github.com/hashicorp/go-uuid"
@ -724,13 +725,6 @@ type RuntimeConfig struct {
// flag: -enable-script-checks // flag: -enable-script-checks
EnableRemoteScriptChecks bool EnableRemoteScriptChecks bool
// EnableSyslog is used to also tee all the logs over to syslog. Only supported
// on linux and OSX. Other platforms will generate an error.
//
// hcl: enable_syslog = (true|false)
// flag: -syslog
EnableSyslog bool
// EnableUI enables the statically-compiled assets for the Consul web UI and // EnableUI enables the statically-compiled assets for the Consul web UI and
// serves them at the default /ui/ endpoint automatically. // serves them at the default /ui/ endpoint automatically.
// //
@ -858,40 +852,8 @@ type RuntimeConfig struct {
// hcl: leave_on_terminate = (true|false) // hcl: leave_on_terminate = (true|false)
LeaveOnTerm bool LeaveOnTerm bool
// LogLevel is the level of the logs to write. Defaults to "INFO". // Logging configuration used to initialize agent logging.
// Logging logging.Config
// hcl: log_level = string
LogLevel string
// LogJSON controls whether to output logs as structured JSON. Defaults to false.
//
// hcl: log_json = (true|false)
// flag: -log-json
LogJSON bool
// LogFile is the path to the file where the logs get written to. Defaults to empty string.
//
// hcl: log_file = string
// flags: -log-file string
LogFile string
// LogRotateDuration is the time configured to rotate logs based on time
//
// hcl: log_rotate_duration = string
// flags: -log-rotate-duration string
LogRotateDuration time.Duration
// LogRotateBytes is the time configured to rotate logs based on bytes written
//
// hcl: log_rotate_bytes = int
// flags: -log-rotate-bytes int
LogRotateBytes int
// LogRotateMaxFiles is the maximum number of log file archives to keep
//
// hcl: log_rotate_max_files = int
// flags: -log-rotate-max-files int
LogRotateMaxFiles int
// MaxQueryTime is the maximum amount of time a blocking query can wait // MaxQueryTime is the maximum amount of time a blocking query can wait
// before Consul will force a response. Consul applies jitter to the wait // before Consul will force a response. Consul applies jitter to the wait
@ -1422,12 +1384,6 @@ type RuntimeConfig struct {
// flag: -join-wan string -join-wan string // flag: -join-wan string -join-wan string
StartJoinAddrsWAN []string StartJoinAddrsWAN []string
// SyslogFacility is used to control where the syslog messages go
// By default, goes to LOCAL0
//
// hcl: syslog_facility = string
SyslogFacility string
// TLSCipherSuites is used to specify the list of supported ciphersuites. // TLSCipherSuites is used to specify the list of supported ciphersuites.
// //
// The values should be a list of the following values: // The values should be a list of the following values:

View File

@ -22,6 +22,7 @@ import (
"github.com/hashicorp/consul/agent/checks" "github.com/hashicorp/consul/agent/checks"
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -288,7 +289,7 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
rt.EnableDebug = true rt.EnableDebug = true
rt.EnableUI = true rt.EnableUI = true
rt.LeaveOnTerm = false rt.LeaveOnTerm = false
rt.LogLevel = "DEBUG" rt.Logging.LogLevel = "DEBUG"
rt.RPCAdvertiseAddr = tcpAddr("127.0.0.1:8300") rt.RPCAdvertiseAddr = tcpAddr("127.0.0.1:8300")
rt.RPCBindAddr = tcpAddr("127.0.0.1:8300") rt.RPCBindAddr = tcpAddr("127.0.0.1:8300")
rt.SerfAdvertiseAddrLAN = tcpAddr("127.0.0.1:8301") rt.SerfAdvertiseAddrLAN = tcpAddr("127.0.0.1:8301")
@ -533,7 +534,7 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
`-data-dir=` + dataDir, `-data-dir=` + dataDir,
}, },
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.LogLevel = "a" rt.Logging.LogLevel = "a"
rt.DataDir = dataDir rt.DataDir = dataDir
}, },
}, },
@ -544,7 +545,7 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
`-data-dir=` + dataDir, `-data-dir=` + dataDir,
}, },
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.LogJSON = true rt.Logging.LogJSON = true
rt.DataDir = dataDir rt.DataDir = dataDir
}, },
}, },
@ -557,7 +558,7 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
json: []string{`{ "log_rotate_max_files": 2 }`}, json: []string{`{ "log_rotate_max_files": 2 }`},
hcl: []string{`log_rotate_max_files = 2`}, hcl: []string{`log_rotate_max_files = 2`},
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.LogRotateMaxFiles = 2 rt.Logging.LogRotateMaxFiles = 2
rt.DataDir = dataDir rt.DataDir = dataDir
}, },
}, },
@ -835,7 +836,7 @@ func TestBuilder_BuildAndValide_ConfigFlagsAndEdgecases(t *testing.T) {
`-data-dir=` + dataDir, `-data-dir=` + dataDir,
}, },
patch: func(rt *RuntimeConfig) { patch: func(rt *RuntimeConfig) {
rt.EnableSyslog = true rt.Logging.EnableSyslog = true
rt.DataDir = dataDir rt.DataDir = dataDir
}, },
}, },
@ -6053,7 +6054,6 @@ func TestFullConfig(t *testing.T) {
EnableDebug: true, EnableDebug: true,
EnableRemoteScriptChecks: true, EnableRemoteScriptChecks: true,
EnableLocalScriptChecks: true, EnableLocalScriptChecks: true,
EnableSyslog: true,
EnableUI: true, EnableUI: true,
EncryptKey: "A4wELWqH", EncryptKey: "A4wELWqH",
EncryptVerifyIncoming: true, EncryptVerifyIncoming: true,
@ -6074,39 +6074,43 @@ func TestFullConfig(t *testing.T) {
KVMaxValueSize: 1234567800000000, KVMaxValueSize: 1234567800000000,
LeaveDrainTime: 8265 * time.Second, LeaveDrainTime: 8265 * time.Second,
LeaveOnTerm: true, LeaveOnTerm: true,
LogLevel: "k1zo9Spt", Logging: logging.Config{
LogJSON: true, LogLevel: "k1zo9Spt",
MaxQueryTime: 18237 * time.Second, LogJSON: true,
NodeID: types.NodeID("AsUIlw99"), EnableSyslog: true,
NodeMeta: map[string]string{"5mgGQMBk": "mJLtVMSG", "A7ynFMJB": "0Nx6RGab"}, SyslogFacility: "hHv79Uia",
NodeName: "otlLxGaI", },
NonVotingServer: true, MaxQueryTime: 18237 * time.Second,
PidFile: "43xN80Km", NodeID: types.NodeID("AsUIlw99"),
PrimaryDatacenter: "ejtmd43d", NodeMeta: map[string]string{"5mgGQMBk": "mJLtVMSG", "A7ynFMJB": "0Nx6RGab"},
PrimaryGateways: []string{"aej8eeZo", "roh2KahS"}, NodeName: "otlLxGaI",
PrimaryGatewaysInterval: 18866 * time.Second, NonVotingServer: true,
RPCAdvertiseAddr: tcpAddr("17.99.29.16:3757"), PidFile: "43xN80Km",
RPCBindAddr: tcpAddr("16.99.34.17:3757"), PrimaryDatacenter: "ejtmd43d",
RPCHandshakeTimeout: 1932 * time.Millisecond, PrimaryGateways: []string{"aej8eeZo", "roh2KahS"},
RPCHoldTimeout: 15707 * time.Second, PrimaryGatewaysInterval: 18866 * time.Second,
RPCProtocol: 30793, RPCAdvertiseAddr: tcpAddr("17.99.29.16:3757"),
RPCRateLimit: 12029.43, RPCBindAddr: tcpAddr("16.99.34.17:3757"),
RPCMaxBurst: 44848, RPCHandshakeTimeout: 1932 * time.Millisecond,
RPCMaxConnsPerClient: 2954, RPCHoldTimeout: 15707 * time.Second,
RaftProtocol: 19016, RPCProtocol: 30793,
RaftSnapshotThreshold: 16384, RPCRateLimit: 12029.43,
RaftSnapshotInterval: 30 * time.Second, RPCMaxBurst: 44848,
RaftTrailingLogs: 83749, RPCMaxConnsPerClient: 2954,
ReconnectTimeoutLAN: 23739 * time.Second, RaftProtocol: 19016,
ReconnectTimeoutWAN: 26694 * time.Second, RaftSnapshotThreshold: 16384,
RejoinAfterLeave: true, RaftSnapshotInterval: 30 * time.Second,
RetryJoinIntervalLAN: 8067 * time.Second, RaftTrailingLogs: 83749,
RetryJoinIntervalWAN: 28866 * time.Second, ReconnectTimeoutLAN: 23739 * time.Second,
RetryJoinLAN: []string{"pbsSFY7U", "l0qLtWij"}, ReconnectTimeoutWAN: 26694 * time.Second,
RetryJoinMaxAttemptsLAN: 913, RejoinAfterLeave: true,
RetryJoinMaxAttemptsWAN: 23160, RetryJoinIntervalLAN: 8067 * time.Second,
RetryJoinWAN: []string{"PFsR02Ye", "rJdQIhER"}, RetryJoinIntervalWAN: 28866 * time.Second,
SegmentName: "BC2NhTDi", RetryJoinLAN: []string{"pbsSFY7U", "l0qLtWij"},
RetryJoinMaxAttemptsLAN: 913,
RetryJoinMaxAttemptsWAN: 23160,
RetryJoinWAN: []string{"PFsR02Ye", "rJdQIhER"},
SegmentName: "BC2NhTDi",
Segments: []structs.NetworkSegment{ Segments: []structs.NetworkSegment{
{ {
Name: "PExYMe2E", Name: "PExYMe2E",
@ -6411,7 +6415,6 @@ func TestFullConfig(t *testing.T) {
SkipLeaveOnInt: true, SkipLeaveOnInt: true,
StartJoinAddrsLAN: []string{"LR3hGDoG", "MwVpZ4Up"}, StartJoinAddrsLAN: []string{"LR3hGDoG", "MwVpZ4Up"},
StartJoinAddrsWAN: []string{"EbFSc3nA", "kwXTh623"}, StartJoinAddrsWAN: []string{"EbFSc3nA", "kwXTh623"},
SyslogFacility: "hHv79Uia",
Telemetry: lib.TelemetryConfig{ Telemetry: lib.TelemetryConfig{
CirconusAPIApp: "p4QOTe9j", CirconusAPIApp: "p4QOTe9j",
CirconusAPIToken: "E3j35V23", CirconusAPIToken: "E3j35V23",
@ -6941,7 +6944,6 @@ func TestSanitize(t *testing.T) {
"EnableCentralServiceConfig": false, "EnableCentralServiceConfig": false,
"EnableLocalScriptChecks": false, "EnableLocalScriptChecks": false,
"EnableRemoteScriptChecks": false, "EnableRemoteScriptChecks": false,
"EnableSyslog": false,
"EnableUI": false, "EnableUI": false,
"EncryptKey": "hidden", "EncryptKey": "hidden",
"EncryptVerifyIncoming": false, "EncryptVerifyIncoming": false,
@ -6967,12 +6969,17 @@ func TestSanitize(t *testing.T) {
"KVMaxValueSize": 1234567800000000, "KVMaxValueSize": 1234567800000000,
"LeaveDrainTime": "0s", "LeaveDrainTime": "0s",
"LeaveOnTerm": false, "LeaveOnTerm": false,
"LogLevel": "", "Logging": {
"LogJSON": false, "EnableSyslog": false,
"LogFile": "", "LogLevel": "",
"LogRotateBytes": 0, "LogJSON": false,
"LogRotateDuration": "0s", "LogFilePath": "",
"LogRotateMaxFiles": 0, "LogRotateBytes": 0,
"LogRotateDuration": "0s",
"LogRotateMaxFiles": 0,
"Name": "",
"SyslogFacility": ""
},
"MaxQueryTime": "0s", "MaxQueryTime": "0s",
"NodeID": "", "NodeID": "",
"NodeMeta": {}, "NodeMeta": {},
@ -7079,7 +7086,6 @@ func TestSanitize(t *testing.T) {
"StartJoinAddrsWAN": [], "StartJoinAddrsWAN": [],
"SyncCoordinateIntervalMin": "0s", "SyncCoordinateIntervalMin": "0s",
"SyncCoordinateRateTarget": 0, "SyncCoordinateRateTarget": 0,
"SyslogFacility": "",
"TLSCipherSuites": [], "TLSCipherSuites": [],
"TLSMinVersion": "", "TLSMinVersion": "",
"TLSPreferServerCipherSuites": false, "TLSPreferServerCipherSuites": false,

View File

@ -51,23 +51,13 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error)
return d, err return d, err
} }
// TODO: use logging.Config in RuntimeConfig instead of separate fields logConf := cfg.Logging
logConf := logging.Config{ logConf.Name = logging.Agent
LogLevel: cfg.LogLevel,
LogJSON: cfg.LogJSON,
Name: logging.Agent,
EnableSyslog: cfg.EnableSyslog,
SyslogFacility: cfg.SyslogFacility,
LogFilePath: cfg.LogFile,
LogRotateDuration: cfg.LogRotateDuration,
LogRotateBytes: cfg.LogRotateBytes,
LogRotateMaxFiles: cfg.LogRotateMaxFiles,
}
d.Logger, err = logging.Setup(logConf, logOut) d.Logger, err = logging.Setup(logConf, logOut)
if err != nil { if err != nil {
return d, err return d, err
} }
grpclog.SetLoggerV2(logging.NewGRPCLogger(cfg.LogLevel, d.Logger)) grpclog.SetLoggerV2(logging.NewGRPCLogger(cfg.Logging.LogLevel, d.Logger))
for _, w := range warnings { for _, w := range warnings {
d.Logger.Warn(w) d.Logger.Warn(w)

View File

@ -181,7 +181,7 @@ func (c *cmd) run(args []string) int {
// Setup gate to check if we should output CLI information // Setup gate to check if we should output CLI information
cli := GatedUi{ cli := GatedUi{
JSONoutput: config.LogJSON, JSONoutput: config.Logging.LogJSON,
ui: c.UI, ui: c.UI,
} }