Skip to content

Commit

Permalink
dont use custom type strings in legacy mount config
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeenkaur committed Jun 24, 2024
1 parent a1d8786 commit 8b3b628
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func resolveConfigFilePaths(mountConfig *config.MountConfig) (err error) {

// Resolve cache-dir path
resolvedPath, err := resolveFilePath(string(mountConfig.CacheDir), "cache-dir")
mountConfig.CacheDir = config.CacheDir(resolvedPath)
mountConfig.CacheDir = resolvedPath
if err != nil {
return
}
Expand Down
5 changes: 2 additions & 3 deletions internal/config/mount_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type WriteConfig struct {
}

type LogConfig struct {
Severity LogSeverity `yaml:"severity"`
Severity string `yaml:"severity"`
Format string `yaml:"format"`
FilePath string `yaml:"file-path"`
LogRotateConfig LogRotateConfig `yaml:"log-rotate"`
Expand Down Expand Up @@ -103,7 +103,6 @@ type GCSAuth struct {

// Enable the storage control client flow on HNS buckets to utilize new APIs.
type EnableHNS bool
type CacheDir string

type FileSystemConfig struct {
IgnoreInterrupts bool `yaml:"ignore-interrupts"`
Expand Down Expand Up @@ -144,7 +143,7 @@ type MountConfig struct {
WriteConfig `yaml:"write"`
LogConfig `yaml:"logging"`
FileCacheConfig `yaml:"file-cache"`
CacheDir `yaml:"cache-dir"`
CacheDir string `yaml:"cache-dir"`
MetadataCacheConfig `yaml:"metadata-cache"`
ListConfig `yaml:"list"`
GCSConnection `yaml:"gcs-connection"`
Expand Down
18 changes: 8 additions & 10 deletions internal/config/yaml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import (
"gopkg.in/yaml.v3"
)

type LogSeverity string

const (
TRACE LogSeverity = "TRACE"
DEBUG LogSeverity = "DEBUG"
INFO LogSeverity = "INFO"
WARNING LogSeverity = "WARNING"
ERROR LogSeverity = "ERROR"
OFF LogSeverity = "OFF"
TRACE string = "TRACE"
DEBUG string = "DEBUG"
INFO string = "INFO"
WARNING string = "WARNING"
ERROR string = "ERROR"
OFF string = "OFF"

parseConfigFileErrMsgFormat = "error parsing config file: %v"

Expand All @@ -50,7 +48,7 @@ const (
ReadRequestSizeMBInvalidValueError = "the value of read-request-size-mb for file-cache can't be less than 1"
)

func IsValidLogSeverity(severity LogSeverity) bool {
func IsValidLogSeverity(severity string) bool {
switch severity {
case
TRACE,
Expand Down Expand Up @@ -159,7 +157,7 @@ func ParseConfigFile(fileName string) (mountConfig *MountConfig, err error) {
}

// convert log severity to upper-case
mountConfig.LogConfig.Severity = LogSeverity(strings.ToUpper(string(mountConfig.LogConfig.Severity)))
mountConfig.LogConfig.Severity = strings.ToUpper(mountConfig.LogConfig.Severity)
if !IsValidLogSeverity(mountConfig.LogConfig.Severity) {
err = fmt.Errorf("error parsing config file: log severity should be one of [trace, debug, info, warning, error, off]")
return
Expand Down
8 changes: 4 additions & 4 deletions internal/fs/read_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (t *FileCacheTest) SetUpTestSuite() {
MaxSizeMB: FileCacheSizeInMb,
CacheFileForRangeRead: false,
},
CacheDir: config.CacheDir(CacheDir),
CacheDir: CacheDir,
}
t.fsTest.SetUpTestSuite()
}
Expand Down Expand Up @@ -604,7 +604,7 @@ func (t *FileCacheWithCacheForRangeRead) SetUpTestSuite() {
MaxSizeMB: -1,
CacheFileForRangeRead: true,
},
CacheDir: config.CacheDir(CacheDir),
CacheDir: CacheDir,
}
t.fsTest.SetUpTestSuite()
}
Expand Down Expand Up @@ -737,7 +737,7 @@ func (t *FileCacheIsDisabledWithCacheDirAndZeroMaxSize) SetUpTestSuite() {
MaxSizeMB: 0,
CacheFileForRangeRead: true,
},
CacheDir: config.CacheDir(CacheDir),
CacheDir: CacheDir,
}
t.fsTest.SetUpTestSuite()
}
Expand Down Expand Up @@ -781,7 +781,7 @@ func (t *FileCacheDestroyTest) SetUpTestSuite() {
MaxSizeMB: -1,
CacheFileForRangeRead: true,
},
CacheDir: config.CacheDir(CacheDir),
CacheDir: CacheDir,
}
t.fsTest.SetUpTestSuite()
}
Expand Down
4 changes: 2 additions & 2 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ type loggerFactory struct {
file *os.File
sysWriter *syslog.Writer
format string
level config.LogSeverity
level string
logRotateConfig config.LogRotateConfig
fileWriter *lumberjack.Logger
}

func (f *loggerFactory) newLogger(level config.LogSeverity) *slog.Logger {
func (f *loggerFactory) newLogger(level string) *slog.Logger {
// create a new logger
var programLevel = new(slog.LevelVar)
logger := slog.New(f.handler(programLevel, ""))
Expand Down
8 changes: 4 additions & 4 deletions internal/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestLoggerSuite(t *testing.T) {
// Boilerplate
// //////////////////////////////////////////////////////////////////////

func redirectLogsToGivenBuffer(buf *bytes.Buffer, level config.LogSeverity) {
func redirectLogsToGivenBuffer(buf *bytes.Buffer, level string) {
var programLevel = new(slog.LevelVar)
defaultLogger = slog.New(
defaultLoggerFactory.createJsonOrTextHandler(buf, programLevel, "TestLogs: "),
Expand All @@ -63,7 +63,7 @@ func redirectLogsToGivenBuffer(buf *bytes.Buffer, level config.LogSeverity) {
// fetchLogOutputForSpecifiedSeverityLevel takes configured severity and
// functions that write logs as parameter and returns string array containing
// output from each function call.
func fetchLogOutputForSpecifiedSeverityLevel(level config.LogSeverity, functions []func()) []string {
func fetchLogOutputForSpecifiedSeverityLevel(level string, functions []func()) []string {
// create a logger that writes to buffer at configured level.
var buf bytes.Buffer
redirectLogsToGivenBuffer(&buf, level)
Expand Down Expand Up @@ -109,7 +109,7 @@ func validateOutput(t *testing.T, expected []string, output []string) {
}
}

func validateLogOutputAtSpecifiedFormatAndSeverity(t *testing.T, format string, level config.LogSeverity, expectedOutput []string) {
func validateLogOutputAtSpecifiedFormatAndSeverity(t *testing.T, format string, level string, expectedOutput []string) {
// set log format
defaultLoggerFactory.format = format

Expand Down Expand Up @@ -231,7 +231,7 @@ func (t *LoggerTest) TestJSONFormatLogs_LogLevelTRACE() {

func (t *LoggerTest) TestSetLoggingLevel() {
testData := []struct {
inputLevel config.LogSeverity
inputLevel string
programLevel *slog.LevelVar
expectedProgramLevel slog.Level
}{
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/slog_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
nanosKey = "nanos"
)

func setLoggingLevel(level config.LogSeverity, programLevel *slog.LevelVar) {
func setLoggingLevel(level string, programLevel *slog.LevelVar) {
switch level {
// logs having severity >= the configured value will be logged.
case config.TRACE:
Expand Down
2 changes: 1 addition & 1 deletion tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) {
// files
MaxSizeMB: 2,
},
CacheDir: config.CacheDir(cacheDirPath),
CacheDir: cacheDirPath,
LogConfig: config.LogConfig{
Severity: config.TRACE,
LogRotateConfig: config.DefaultLogRotateConfig(),
Expand Down
2 changes: 1 addition & 1 deletion tools/integration_tests/read_cache/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func createConfigFile(cacheSize int64, cacheFileForRangeRead bool, fileName stri
MaxSizeMB: cacheSize,
CacheFileForRangeRead: cacheFileForRangeRead,
},
CacheDir: config.CacheDir(cacheDirPath),
CacheDir: cacheDirPath,
LogConfig: config.LogConfig{
Severity: config.TRACE,
Format: "json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) {
MaxSizeMB: 700,
CacheFileForRangeRead: true,
},
CacheDir: config.CacheDir(cacheDirPath),
CacheDir: cacheDirPath,
LogConfig: config.LogConfig{
Severity: config.TRACE,
LogRotateConfig: config.DefaultLogRotateConfig(),
Expand All @@ -63,7 +63,7 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) {
MaxSizeMB: -1,
CacheFileForRangeRead: false,
},
CacheDir: config.CacheDir(cacheDirPath),
CacheDir: cacheDirPath,
LogConfig: config.LogConfig{
Severity: config.TRACE,
LogRotateConfig: config.DefaultLogRotateConfig(),
Expand Down
2 changes: 1 addition & 1 deletion tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) {
// files
MaxSizeMB: 3,
},
CacheDir: config.CacheDir(cacheDirPath),
CacheDir: cacheDirPath,
LogConfig: config.LogConfig{
Severity: config.TRACE,
LogRotateConfig: config.DefaultLogRotateConfig(),
Expand Down

0 comments on commit 8b3b628

Please sign in to comment.