Skip to content

Commit

Permalink
CLOUDP-253916 - readinessProbe: send to stdout as well, give option f…
Browse files Browse the repository at this point in the history
…or compression and reduce default size (#1561)
  • Loading branch information
nammn authored Jun 24, 2024
1 parent e4b4e7b commit 90e9374
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
21 changes: 17 additions & 4 deletions cmd/readiness/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,25 @@ func parseHealthStatus(reader io.Reader) (health.Status, error) {
}

func initLogger(l *lumberjack.Logger) {
log := zap.New(zapcore.NewCore(
consoleCore := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(l),
zap.DebugLevel,
), zap.Development())
zapcore.AddSync(os.Stdout),
zap.DebugLevel)

cores := []zapcore.Core{consoleCore}
if config.ReadBoolWitDefault(config.WithAgentFileLogging, "true") {
fileCore := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(l),
zap.DebugLevel)
cores = append(cores, fileCore)
}

core := zapcore.NewTee(cores...)
log := zap.New(core, zap.Development())
logger = log.Sugar()

logger.Infof("logging configuration: %+v", l)
}

func main() {
Expand Down
27 changes: 18 additions & 9 deletions pkg/readiness/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (
const (
DefaultAgentHealthStatusFilePath = "/var/log/mongodb-mms-automation/agent-health-status.json"
AgentHealthStatusFilePathEnv = "AGENT_STATUS_FILEPATH"
WithAgentFileLogging = "MDB_WITH_AGENT_FILE_LOGGING"

defaultLogPath = "/var/log/mongodb-mms-automation/readiness.log"
podNamespaceEnv = "POD_NAMESPACE"
automationConfigSecretEnv = "AUTOMATION_CONFIG_MAP" //nolint
logPathEnv = "LOG_FILE_PATH"
hostNameEnv = "HOSTNAME"
readinessProbeLoggerBackups = "READINESS_PROBE_LOGGER_BACKUPS"
readinessProbeLoggerMaxSize = "READINESS_PROBE_LOGGER_MAX_SIZE"
readinessProbeLoggerMaxAge = "READINESS_PROBE_LOGGER_MAX_AGE"
defaultLogPath = "/var/log/mongodb-mms-automation/readiness.log"
podNamespaceEnv = "POD_NAMESPACE"
automationConfigSecretEnv = "AUTOMATION_CONFIG_MAP" //nolint
logPathEnv = "LOG_FILE_PATH"
hostNameEnv = "HOSTNAME"
readinessProbeLoggerBackups = "READINESS_PROBE_LOGGER_BACKUPS"
readinessProbeLoggerMaxSize = "READINESS_PROBE_LOGGER_MAX_SIZE"
readinessProbeLoggerMaxAge = "READINESS_PROBE_LOGGER_MAX_AGE"
readinessProbeLoggerCompress = "READINESS_PROBE_LOGGER_COMPRESS"
)

type Config struct {
Expand Down Expand Up @@ -71,8 +73,9 @@ func GetLogger() *lumberjack.Logger {
logger := &lumberjack.Logger{
Filename: readinessProbeLogFilePath(),
MaxBackups: readIntOrDefault(readinessProbeLoggerBackups, 5),
MaxSize: readInt(readinessProbeLoggerMaxSize),
MaxSize: readIntOrDefault(readinessProbeLoggerMaxSize, 5),
MaxAge: readInt(readinessProbeLoggerMaxAge),
Compress: ReadBoolWitDefault(readinessProbeLoggerCompress, "false"),
}
return logger
}
Expand Down Expand Up @@ -105,3 +108,9 @@ func readIntOrDefault(envVarName string, defaultValue int) int {
}
return intValue
}

// ReadBoolWitDefault returns the boolean value of an envvar of the given name.
func ReadBoolWitDefault(envVarName string, defaultValue string) bool {
envVar := GetEnvOrDefault(envVarName, defaultValue)
return strings.TrimSpace(strings.ToLower(envVar)) == "true"
}

0 comments on commit 90e9374

Please sign in to comment.