Skip to content

Commit

Permalink
change file-count to backup-file-count
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Nov 24, 2023
1 parent 7323f1c commit 90d1dc7
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
18 changes: 9 additions & 9 deletions internal/config/mount_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package config

const (
// Default log rotation config values.
defaultMaxFileSizeMB = 512
defaultFileCount = 10
defaultCompress = false
defaultMaxFileSizeMB = 512
defaultBackupFileCount = 10
defaultCompress = false
)

type WriteConfig struct {
Expand Down Expand Up @@ -46,16 +46,16 @@ type MountConfig struct {
// 3. compress: indicates whether the rotated log files should be compressed
// using gzip. The default value is False.
type LogRotateConfig struct {
MaxFileSizeMB int `yaml:"max-file-size-mb"`
FileCount int `yaml:"file-count"`
Compress bool `yaml:"compress"`
MaxFileSizeMB int `yaml:"max-file-size-mb"`
BackupFileCount int `yaml:"backup-file-count"`
Compress bool `yaml:"compress"`
}

func DefaultLogRotateConfig() LogRotateConfig {
return LogRotateConfig{
MaxFileSizeMB: defaultMaxFileSizeMB,
FileCount: defaultFileCount,
Compress: defaultCompress,
MaxFileSizeMB: defaultMaxFileSizeMB,
BackupFileCount: defaultBackupFileCount,
Compress: defaultCompress,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/testdata/invalid_log_rotate_config_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ logging:
severity: error
log-rotate:
max-file-size-mb: -1
file-count: -1
backup-file-count: -1
2 changes: 1 addition & 1 deletion internal/config/testdata/invalid_log_rotate_config_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ write:
logging:
severity: error
log-rotate:
file-count: -1
backup-file-count: -1
2 changes: 1 addition & 1 deletion internal/config/testdata/valid_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ logging:
severity: error
log-rotate:
max-file-size-mb: 100
file-count: 5
backup-file-count: 5
compress: false


4 changes: 2 additions & 2 deletions internal/config/yaml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func IsValidLogRotateConfig(config LogRotateConfig) error {
if config.MaxFileSizeMB <= 0 {
return fmt.Errorf("max-file-size-mb should be atleast 1")
}
if config.FileCount <= 0 {
return fmt.Errorf("file-count should be atleast 1")
if config.BackupFileCount <= 0 {
return fmt.Errorf("backup-file-count should be atleast 1")
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/config/yaml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func validateDefaultConfig(mountConfig *MountConfig) {
ExpectEq("", mountConfig.LogConfig.Format)
ExpectEq("", mountConfig.LogConfig.FilePath)
ExpectEq(512, mountConfig.LogConfig.LogRotateConfig.MaxFileSizeMB)
ExpectEq(10, mountConfig.LogConfig.LogRotateConfig.FileCount)
ExpectEq(10, mountConfig.LogConfig.LogRotateConfig.BackupFileCount)
ExpectEq(false, mountConfig.LogConfig.LogRotateConfig.Compress)
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (t *YamlParserTest) TestReadConfigFile_ValidConfig() {
ExpectEq("/tmp/logfile.json", mountConfig.LogConfig.FilePath)
ExpectEq("text", mountConfig.LogConfig.Format)
ExpectEq(100, mountConfig.LogConfig.LogRotateConfig.MaxFileSizeMB)
ExpectEq(5, mountConfig.LogConfig.LogRotateConfig.FileCount)
ExpectEq(5, mountConfig.LogConfig.LogRotateConfig.BackupFileCount)
ExpectEq(false, mountConfig.LogConfig.LogRotateConfig.Compress)
}

Expand All @@ -111,5 +111,5 @@ func (t *YamlParserTest) TestReadConfigFile_InvalidLogRotateConfig2() {

AssertNe(nil, err)
AssertTrue(strings.Contains(err.Error(),
fmt.Sprintf(parseConfigFileErrMsgFormat, "file-count should be atleast 1")))
fmt.Sprintf(parseConfigFileErrMsgFormat, "backup-file-count should be atleast 1")))
}
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func InitLogFile(logConfig config.LogConfig) error {
fileWriter = &lumberjack.Logger{
Filename: f.Name(),
MaxSize: logConfig.LogRotateConfig.MaxFileSizeMB,
MaxBackups: logConfig.LogRotateConfig.FileCount - 1,
MaxBackups: logConfig.LogRotateConfig.BackupFileCount,
Compress: logConfig.LogRotateConfig.Compress,
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions internal/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ func (t *LoggerTest) TestInitLogFile() {
filePath, _ := os.UserHomeDir()
filePath += "/log.txt"
fileSize := 100
fileCount := 2
backupFileCount := 2
logConfig := config.LogConfig{
Severity: config.DEBUG,
Format: format,
FilePath: filePath,
LogRotateConfig: config.LogRotateConfig{
MaxFileSizeMB: fileSize,
FileCount: fileCount,
Compress: true,
MaxFileSizeMB: fileSize,
BackupFileCount: backupFileCount,
Compress: true,
},
}

Expand All @@ -288,6 +288,6 @@ func (t *LoggerTest) TestInitLogFile() {
ExpectEq(format, defaultLoggerFactory.format)
ExpectEq(config.DEBUG, defaultLoggerFactory.level)
ExpectEq(fileSize, defaultLoggerFactory.logRotateConfig.MaxFileSizeMB)
ExpectEq(fileCount, defaultLoggerFactory.logRotateConfig.FileCount)
ExpectEq(backupFileCount, defaultLoggerFactory.logRotateConfig.BackupFileCount)
ExpectEq(true, defaultLoggerFactory.logRotateConfig.Compress)
}
12 changes: 6 additions & 6 deletions tools/integration_tests/log_rotation/log_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ const (
var logDirPath string
var logFilePath string

func getMountConfigForLogRotation(maxFileSizeMB, fileCount int, compress bool,
func getMountConfigForLogRotation(maxFileSizeMB, backupFileCount int, compress bool,
logFilePath string) config.MountConfig {
mountConfig := config.MountConfig{
LogConfig: config.LogConfig{
Severity: config.TRACE,
FilePath: logFilePath,
LogRotateConfig: config.LogRotateConfig{
MaxFileSizeMB: maxFileSizeMB,
FileCount: fileCount,
Compress: compress,
MaxFileSizeMB: maxFileSizeMB,
BackupFileCount: backupFileCount,
Compress: compress,
},
},
}
Expand Down Expand Up @@ -80,10 +80,10 @@ func TestMain(m *testing.M) {

// Set up config files.
configFile1 := setup.YAMLConfigFile(
getMountConfigForLogRotation(maxFileSizeMB, logFileCount, true, logFilePath),
getMountConfigForLogRotation(maxFileSizeMB, backupLogFileCount, true, logFilePath),
"config1.yaml")
configFile2 := setup.YAMLConfigFile(
getMountConfigForLogRotation(maxFileSizeMB, logFileCount, false, logFilePath),
getMountConfigForLogRotation(maxFileSizeMB, backupLogFileCount, false, logFilePath),
"config2.yaml")

// Set up flags to run tests on.
Expand Down
4 changes: 2 additions & 2 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func TestMain(m *testing.M) {
LogConfig: config.LogConfig{
Severity: config.TRACE,
LogRotateConfig: config.LogRotateConfig{
MaxFileSizeMB: 10,
FileCount: 1,
MaxFileSizeMB: 10,
BackupFileCount: 0, // to retain all backup log files.
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion tools/integration_tests/run_tests_mounted_directory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ echo "logging:
severity: trace
log-rotate:
max-file-size-mb: 2
file-count: 3
backup-file-count: 3
compress: true
" > /tmp/gcsfuse_config.yaml
gcsfuse --config-file=/tmp/gcsfuse_config.yaml $TEST_BUCKET_NAME $MOUNT_DIR
Expand Down

0 comments on commit 90d1dc7

Please sign in to comment.