Skip to content

Commit 90e9374

Browse files
authored
CLOUDP-253916 - readinessProbe: send to stdout as well, give option for compression and reduce default size (#1561)
1 parent e4b4e7b commit 90e9374

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

cmd/readiness/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,25 @@ func parseHealthStatus(reader io.Reader) (health.Status, error) {
208208
}
209209

210210
func initLogger(l *lumberjack.Logger) {
211-
log := zap.New(zapcore.NewCore(
211+
consoleCore := zapcore.NewCore(
212212
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
213-
zapcore.AddSync(l),
214-
zap.DebugLevel,
215-
), zap.Development())
213+
zapcore.AddSync(os.Stdout),
214+
zap.DebugLevel)
215+
216+
cores := []zapcore.Core{consoleCore}
217+
if config.ReadBoolWitDefault(config.WithAgentFileLogging, "true") {
218+
fileCore := zapcore.NewCore(
219+
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
220+
zapcore.AddSync(l),
221+
zap.DebugLevel)
222+
cores = append(cores, fileCore)
223+
}
224+
225+
core := zapcore.NewTee(cores...)
226+
log := zap.New(core, zap.Development())
216227
logger = log.Sugar()
228+
229+
logger.Infof("logging configuration: %+v", l)
217230
}
218231

219232
func main() {

pkg/readiness/config/config.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import (
1515
const (
1616
DefaultAgentHealthStatusFilePath = "/var/log/mongodb-mms-automation/agent-health-status.json"
1717
AgentHealthStatusFilePathEnv = "AGENT_STATUS_FILEPATH"
18+
WithAgentFileLogging = "MDB_WITH_AGENT_FILE_LOGGING"
1819

19-
defaultLogPath = "/var/log/mongodb-mms-automation/readiness.log"
20-
podNamespaceEnv = "POD_NAMESPACE"
21-
automationConfigSecretEnv = "AUTOMATION_CONFIG_MAP" //nolint
22-
logPathEnv = "LOG_FILE_PATH"
23-
hostNameEnv = "HOSTNAME"
24-
readinessProbeLoggerBackups = "READINESS_PROBE_LOGGER_BACKUPS"
25-
readinessProbeLoggerMaxSize = "READINESS_PROBE_LOGGER_MAX_SIZE"
26-
readinessProbeLoggerMaxAge = "READINESS_PROBE_LOGGER_MAX_AGE"
20+
defaultLogPath = "/var/log/mongodb-mms-automation/readiness.log"
21+
podNamespaceEnv = "POD_NAMESPACE"
22+
automationConfigSecretEnv = "AUTOMATION_CONFIG_MAP" //nolint
23+
logPathEnv = "LOG_FILE_PATH"
24+
hostNameEnv = "HOSTNAME"
25+
readinessProbeLoggerBackups = "READINESS_PROBE_LOGGER_BACKUPS"
26+
readinessProbeLoggerMaxSize = "READINESS_PROBE_LOGGER_MAX_SIZE"
27+
readinessProbeLoggerMaxAge = "READINESS_PROBE_LOGGER_MAX_AGE"
28+
readinessProbeLoggerCompress = "READINESS_PROBE_LOGGER_COMPRESS"
2729
)
2830

2931
type Config struct {
@@ -71,8 +73,9 @@ func GetLogger() *lumberjack.Logger {
7173
logger := &lumberjack.Logger{
7274
Filename: readinessProbeLogFilePath(),
7375
MaxBackups: readIntOrDefault(readinessProbeLoggerBackups, 5),
74-
MaxSize: readInt(readinessProbeLoggerMaxSize),
76+
MaxSize: readIntOrDefault(readinessProbeLoggerMaxSize, 5),
7577
MaxAge: readInt(readinessProbeLoggerMaxAge),
78+
Compress: ReadBoolWitDefault(readinessProbeLoggerCompress, "false"),
7679
}
7780
return logger
7881
}
@@ -105,3 +108,9 @@ func readIntOrDefault(envVarName string, defaultValue int) int {
105108
}
106109
return intValue
107110
}
111+
112+
// ReadBoolWitDefault returns the boolean value of an envvar of the given name.
113+
func ReadBoolWitDefault(envVarName string, defaultValue string) bool {
114+
envVar := GetEnvOrDefault(envVarName, defaultValue)
115+
return strings.TrimSpace(strings.ToLower(envVar)) == "true"
116+
}

0 commit comments

Comments
 (0)