diff --git a/cfg/config.go b/cfg/config.go index dc4907ac53..0a06d9d0ec 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -24,187 +24,187 @@ import ( ) type Config struct { - AppName string `yaml:"app-name,omitempty"` + AppName string `yaml:"app-name,omitempty" json:"app-name,omitempty"` - CacheDir ResolvedPath `yaml:"cache-dir,omitempty"` + CacheDir ResolvedPath `yaml:"cache-dir,omitempty" json:"cache-dir,omitempty"` - Debug DebugConfig `yaml:"debug,omitempty"` + Debug DebugConfig `yaml:"debug,omitempty" json:"debug,omitempty"` - EnableHns bool `yaml:"enable-hns,omitempty"` + EnableHns bool `yaml:"enable-hns,omitempty" json:"enable-hns,omitempty"` - FileCache FileCacheConfig `yaml:"file-cache,omitempty"` + FileCache FileCacheConfig `yaml:"file-cache,omitempty" json:"file-cache,omitempty"` - FileSystem FileSystemConfig `yaml:"file-system,omitempty"` + FileSystem FileSystemConfig `yaml:"file-system,omitempty" json:"file-system,omitempty"` - Foreground bool `yaml:"foreground,omitempty"` + Foreground bool `yaml:"foreground,omitempty" json:"foreground,omitempty"` - GcsAuth GcsAuthConfig `yaml:"gcs-auth,omitempty"` + GcsAuth GcsAuthConfig `yaml:"gcs-auth,omitempty" json:"gcs-auth,omitempty"` - GcsConnection GcsConnectionConfig `yaml:"gcs-connection,omitempty"` + GcsConnection GcsConnectionConfig `yaml:"gcs-connection,omitempty" json:"gcs-connection,omitempty"` - GcsRetries GcsRetriesConfig `yaml:"gcs-retries,omitempty"` + GcsRetries GcsRetriesConfig `yaml:"gcs-retries,omitempty" json:"gcs-retries,omitempty"` - ImplicitDirs bool `yaml:"implicit-dirs,omitempty"` + ImplicitDirs bool `yaml:"implicit-dirs,omitempty" json:"implicit-dirs,omitempty"` - List ListConfig `yaml:"list,omitempty"` + List ListConfig `yaml:"list,omitempty" json:"list,omitempty"` - Logging LoggingConfig `yaml:"logging,omitempty"` + Logging LoggingConfig `yaml:"logging,omitempty" json:"logging,omitempty"` - MetadataCache MetadataCacheConfig `yaml:"metadata-cache,omitempty"` + MetadataCache MetadataCacheConfig `yaml:"metadata-cache,omitempty" json:"metadata-cache,omitempty"` - Metrics MetricsConfig `yaml:"metrics,omitempty"` + Metrics MetricsConfig `yaml:"metrics,omitempty" json:"metrics,omitempty"` - Monitoring MonitoringConfig `yaml:"monitoring,omitempty"` + Monitoring MonitoringConfig `yaml:"monitoring,omitempty" json:"monitoring,omitempty"` - OnlyDir string `yaml:"only-dir,omitempty"` + OnlyDir string `yaml:"only-dir,omitempty" json:"only-dir,omitempty"` - Write WriteConfig `yaml:"write,omitempty"` + Write WriteConfig `yaml:"write,omitempty" json:"write,omitempty"` } type DebugConfig struct { - ExitOnInvariantViolation bool `yaml:"exit-on-invariant-violation,omitempty"` + ExitOnInvariantViolation bool `yaml:"exit-on-invariant-violation,omitempty" json:"exit-on-invariant-violation,omitempty"` - Fuse bool `yaml:"fuse,omitempty"` + Fuse bool `yaml:"fuse,omitempty" json:"fuse,omitempty"` - Gcs bool `yaml:"gcs,omitempty"` + Gcs bool `yaml:"gcs,omitempty" json:"gcs,omitempty"` - LogMutex bool `yaml:"log-mutex,omitempty"` + LogMutex bool `yaml:"log-mutex,omitempty" json:"log-mutex,omitempty"` } type FileCacheConfig struct { - CacheFileForRangeRead bool `yaml:"cache-file-for-range-read,omitempty"` + CacheFileForRangeRead bool `yaml:"cache-file-for-range-read,omitempty" json:"cache-file-for-range-read,omitempty"` - DownloadChunkSizeMb int64 `yaml:"download-chunk-size-mb,omitempty"` + DownloadChunkSizeMb int64 `yaml:"download-chunk-size-mb,omitempty" json:"download-chunk-size-mb,omitempty"` - EnableCrc bool `yaml:"enable-crc,omitempty"` + EnableCrc bool `yaml:"enable-crc,omitempty" json:"enable-crc,omitempty"` - EnableParallelDownloads bool `yaml:"enable-parallel-downloads,omitempty"` + EnableParallelDownloads bool `yaml:"enable-parallel-downloads,omitempty" json:"enable-parallel-downloads,omitempty"` - MaxParallelDownloads int64 `yaml:"max-parallel-downloads,omitempty"` + MaxParallelDownloads int64 `yaml:"max-parallel-downloads,omitempty" json:"max-parallel-downloads,omitempty"` - MaxSizeMb int64 `yaml:"max-size-mb,omitempty"` + MaxSizeMb int64 `yaml:"max-size-mb,omitempty" json:"max-size-mb,omitempty"` - ParallelDownloadsPerFile int64 `yaml:"parallel-downloads-per-file,omitempty"` + ParallelDownloadsPerFile int64 `yaml:"parallel-downloads-per-file,omitempty" json:"parallel-downloads-per-file,omitempty"` - WriteBufferSize int64 `yaml:"write-buffer-size,omitempty"` + WriteBufferSize int64 `yaml:"write-buffer-size,omitempty" json:"write-buffer-size,omitempty"` } type FileSystemConfig struct { - DirMode Octal `yaml:"dir-mode,omitempty"` + DirMode Octal `yaml:"dir-mode,omitempty" json:"dir-mode,omitempty"` - DisableParallelDirops bool `yaml:"disable-parallel-dirops,omitempty"` + DisableParallelDirops bool `yaml:"disable-parallel-dirops,omitempty" json:"disable-parallel-dirops,omitempty"` - FileMode Octal `yaml:"file-mode,omitempty"` + FileMode Octal `yaml:"file-mode,omitempty" json:"file-mode,omitempty"` - FuseOptions []string `yaml:"fuse-options,omitempty"` + FuseOptions []string `yaml:"fuse-options,omitempty" json:"fuse-options,omitempty"` - Gid int64 `yaml:"gid,omitempty"` + Gid int64 `yaml:"gid,omitempty" json:"gid,omitempty"` - IgnoreInterrupts bool `yaml:"ignore-interrupts,omitempty"` + IgnoreInterrupts bool `yaml:"ignore-interrupts,omitempty" json:"ignore-interrupts,omitempty"` - KernelListCacheTtlSecs int64 `yaml:"kernel-list-cache-ttl-secs,omitempty"` + KernelListCacheTtlSecs int64 `yaml:"kernel-list-cache-ttl-secs,omitempty" json:"kernel-list-cache-ttl-secs,omitempty"` - RenameDirLimit int64 `yaml:"rename-dir-limit,omitempty"` + RenameDirLimit int64 `yaml:"rename-dir-limit,omitempty" json:"rename-dir-limit,omitempty"` - TempDir ResolvedPath `yaml:"temp-dir,omitempty"` + TempDir ResolvedPath `yaml:"temp-dir,omitempty" json:"temp-dir,omitempty"` - Uid int64 `yaml:"uid,omitempty"` + Uid int64 `yaml:"uid,omitempty" json:"uid,omitempty"` } type GcsAuthConfig struct { - AnonymousAccess bool `yaml:"anonymous-access,omitempty"` + AnonymousAccess bool `yaml:"anonymous-access,omitempty" json:"anonymous-access,omitempty"` - KeyFile ResolvedPath `yaml:"key-file,omitempty"` + KeyFile ResolvedPath `yaml:"key-file,omitempty" json:"key-file,omitempty"` - ReuseTokenFromUrl bool `yaml:"reuse-token-from-url,omitempty"` + ReuseTokenFromUrl bool `yaml:"reuse-token-from-url,omitempty" json:"reuse-token-from-url,omitempty"` - TokenUrl string `yaml:"token-url,omitempty"` + TokenUrl string `yaml:"token-url,omitempty" json:"token-url,omitempty"` } type GcsConnectionConfig struct { - BillingProject string `yaml:"billing-project,omitempty"` + BillingProject string `yaml:"billing-project,omitempty" json:"billing-project,omitempty"` - ClientProtocol Protocol `yaml:"client-protocol,omitempty"` + ClientProtocol Protocol `yaml:"client-protocol,omitempty" json:"client-protocol,omitempty"` - CustomEndpoint string `yaml:"custom-endpoint,omitempty"` + CustomEndpoint string `yaml:"custom-endpoint,omitempty" json:"custom-endpoint,omitempty"` - ExperimentalEnableJsonRead bool `yaml:"experimental-enable-json-read,omitempty"` + ExperimentalEnableJsonRead bool `yaml:"experimental-enable-json-read,omitempty" json:"experimental-enable-json-read,omitempty"` - GrpcConnPoolSize int64 `yaml:"grpc-conn-pool-size,omitempty"` + GrpcConnPoolSize int64 `yaml:"grpc-conn-pool-size,omitempty" json:"grpc-conn-pool-size,omitempty"` - HttpClientTimeout time.Duration `yaml:"http-client-timeout,omitempty"` + HttpClientTimeout time.Duration `yaml:"http-client-timeout,omitempty" json:"http-client-timeout,omitempty"` - LimitBytesPerSec float64 `yaml:"limit-bytes-per-sec,omitempty"` + LimitBytesPerSec float64 `yaml:"limit-bytes-per-sec,omitempty" json:"limit-bytes-per-sec,omitempty"` - LimitOpsPerSec float64 `yaml:"limit-ops-per-sec,omitempty"` + LimitOpsPerSec float64 `yaml:"limit-ops-per-sec,omitempty" json:"limit-ops-per-sec,omitempty"` - MaxConnsPerHost int64 `yaml:"max-conns-per-host,omitempty"` + MaxConnsPerHost int64 `yaml:"max-conns-per-host,omitempty" json:"max-conns-per-host,omitempty"` - MaxIdleConnsPerHost int64 `yaml:"max-idle-conns-per-host,omitempty"` + MaxIdleConnsPerHost int64 `yaml:"max-idle-conns-per-host,omitempty" json:"max-idle-conns-per-host,omitempty"` - SequentialReadSizeMb int64 `yaml:"sequential-read-size-mb,omitempty"` + SequentialReadSizeMb int64 `yaml:"sequential-read-size-mb,omitempty" json:"sequential-read-size-mb,omitempty"` } type GcsRetriesConfig struct { - MaxRetryAttempts int64 `yaml:"max-retry-attempts,omitempty"` + MaxRetryAttempts int64 `yaml:"max-retry-attempts,omitempty" json:"max-retry-attempts,omitempty"` - MaxRetrySleep time.Duration `yaml:"max-retry-sleep,omitempty"` + MaxRetrySleep time.Duration `yaml:"max-retry-sleep,omitempty" json:"max-retry-sleep,omitempty"` - Multiplier float64 `yaml:"multiplier,omitempty"` + Multiplier float64 `yaml:"multiplier,omitempty" json:"multiplier,omitempty"` } type ListConfig struct { - EnableEmptyManagedFolders bool `yaml:"enable-empty-managed-folders,omitempty"` + EnableEmptyManagedFolders bool `yaml:"enable-empty-managed-folders,omitempty" json:"enable-empty-managed-folders,omitempty"` } type LogRotateLoggingConfig struct { - BackupFileCount int64 `yaml:"backup-file-count,omitempty"` + BackupFileCount int64 `yaml:"backup-file-count,omitempty" json:"backup-file-count,omitempty"` - Compress bool `yaml:"compress,omitempty"` + Compress bool `yaml:"compress,omitempty" json:"compress,omitempty"` - MaxFileSizeMb int64 `yaml:"max-file-size-mb,omitempty"` + MaxFileSizeMb int64 `yaml:"max-file-size-mb,omitempty" json:"max-file-size-mb,omitempty"` } type LoggingConfig struct { - FilePath ResolvedPath `yaml:"file-path,omitempty"` + FilePath ResolvedPath `yaml:"file-path,omitempty" json:"file-path,omitempty"` - Format string `yaml:"format,omitempty"` + Format string `yaml:"format,omitempty" json:"format,omitempty"` - LogRotate LogRotateLoggingConfig `yaml:"log-rotate,omitempty"` + LogRotate LogRotateLoggingConfig `yaml:"log-rotate,omitempty" json:"log-rotate,omitempty"` - Severity LogSeverity `yaml:"severity,omitempty"` + Severity LogSeverity `yaml:"severity,omitempty" json:"severity,omitempty"` } type MetadataCacheConfig struct { - DeprecatedStatCacheCapacity int64 `yaml:"deprecated-stat-cache-capacity,omitempty"` + DeprecatedStatCacheCapacity int64 `yaml:"deprecated-stat-cache-capacity,omitempty" json:"deprecated-stat-cache-capacity,omitempty"` - DeprecatedStatCacheTtl time.Duration `yaml:"deprecated-stat-cache-ttl,omitempty"` + DeprecatedStatCacheTtl time.Duration `yaml:"deprecated-stat-cache-ttl,omitempty" json:"deprecated-stat-cache-ttl,omitempty"` - DeprecatedTypeCacheTtl time.Duration `yaml:"deprecated-type-cache-ttl,omitempty"` + DeprecatedTypeCacheTtl time.Duration `yaml:"deprecated-type-cache-ttl,omitempty" json:"deprecated-type-cache-ttl,omitempty"` - EnableNonexistentTypeCache bool `yaml:"enable-nonexistent-type-cache,omitempty"` + EnableNonexistentTypeCache bool `yaml:"enable-nonexistent-type-cache,omitempty" json:"enable-nonexistent-type-cache,omitempty"` - ExperimentalMetadataPrefetchOnMount string `yaml:"experimental-metadata-prefetch-on-mount,omitempty"` + ExperimentalMetadataPrefetchOnMount string `yaml:"experimental-metadata-prefetch-on-mount,omitempty" json:"experimental-metadata-prefetch-on-mount,omitempty"` - StatCacheMaxSizeMb int64 `yaml:"stat-cache-max-size-mb,omitempty"` + StatCacheMaxSizeMb int64 `yaml:"stat-cache-max-size-mb,omitempty" json:"stat-cache-max-size-mb,omitempty"` - TtlSecs int64 `yaml:"ttl-secs,omitempty"` + TtlSecs int64 `yaml:"ttl-secs,omitempty" json:"ttl-secs,omitempty"` - TypeCacheMaxSizeMb int64 `yaml:"type-cache-max-size-mb,omitempty"` + TypeCacheMaxSizeMb int64 `yaml:"type-cache-max-size-mb,omitempty" json:"type-cache-max-size-mb,omitempty"` } type MetricsConfig struct { - PrometheusPort int64 `yaml:"prometheus-port,omitempty"` + PrometheusPort int64 `yaml:"prometheus-port,omitempty" json:"prometheus-port,omitempty"` - StackdriverExportInterval time.Duration `yaml:"stackdriver-export-interval,omitempty"` + StackdriverExportInterval time.Duration `yaml:"stackdriver-export-interval,omitempty" json:"stackdriver-export-interval,omitempty"` } type MonitoringConfig struct { - ExperimentalOpentelemetryCollectorAddress string `yaml:"experimental-opentelemetry-collector-address,omitempty"` + ExperimentalOpentelemetryCollectorAddress string `yaml:"experimental-opentelemetry-collector-address,omitempty" json:"experimental-opentelemetry-collector-address,omitempty"` } type WriteConfig struct { - CreateEmptyFile bool `yaml:"create-empty-file,omitempty"` + CreateEmptyFile bool `yaml:"create-empty-file,omitempty" json:"create-empty-file,omitempty"` } func BindFlags(v *viper.Viper, flagSet *pflag.FlagSet) error { diff --git a/cfg/types.go b/cfg/types.go index 138e2cf604..918e476496 100644 --- a/cfg/types.go +++ b/cfg/types.go @@ -35,8 +35,8 @@ func (o *Octal) UnmarshalText(text []byte) error { return nil } -func (o *Octal) String() string { - return fmt.Sprintf("%o", *o) +func (o Octal) MarshalText() ([]byte, error) { + return []byte(strconv.FormatInt(int64(o), 8)), nil } // Protocol is the datatype that specifies the type of connection: http1/http2/grpc. diff --git a/cmd/legacy_main.go b/cmd/legacy_main.go index 4465896243..d680f29f88 100644 --- a/cmd/legacy_main.go +++ b/cmd/legacy_main.go @@ -292,19 +292,7 @@ func runCLIApp(c *cli.Context) (err error) { // if these are already being logged into a log-file, otherwise // there will be duplicate logs for these in both places (stdout and log-file). if newConfig.Foreground || newConfig.Logging.FilePath == "" { - flagsStringified, err := util.Stringify(*flags) - if err != nil { - logger.Warnf("failed to stringify cli flags: %v", err) - } else { - logger.Infof("GCSFuse mount command flags: %s", flagsStringified) - } - - mountConfigStringified, err := util.Stringify(*mountConfig) - if err != nil { - logger.Warnf("failed to stringify config-file: %v", err) - } else { - logger.Infof("GCSFuse mount config flags: %s", mountConfigStringified) - } + logger.Info("GCSFuse config", "config", newConfig) } // The following will not warn if the user explicitly passed the default value for StatCacheCapacity. diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 770e464bec..46027e7939 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -142,8 +142,8 @@ func Infof(format string, v ...interface{}) { } // Info prints the message with info severity. -func Info(v ...interface{}) { - defaultLogger.Info(fmt.Sprint(v...)) +func Info(message string, args ...any) { + defaultLogger.Info(message, args...) } // Warnf prints the message with WARNING severity in the specified format. diff --git a/internal/util/util.go b/internal/util/util.go index 8c779d1e66..757f84cbd7 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -16,7 +16,6 @@ package util import ( "context" - "encoding/json" "fmt" "math" "os" @@ -75,16 +74,6 @@ func GetResolvedPath(filePath string) (resolvedPath string, err error) { } } -// Stringify marshals an object (only exported attribute) to a JSON string. If marshalling fails, it returns an empty string. -func Stringify(input any) (string, error) { - inputBytes, err := json.Marshal(input) - - if err != nil { - return "", fmt.Errorf("error in Stringify %w", err) - } - return string(inputBytes), nil -} - // MiBsToBytes returns the bytes equivalent // of given number of MiBs. // For reference, each MiB = 2^20 bytes. diff --git a/internal/util/util_test.go b/internal/util/util_test.go index db9e9a6f77..cbd6b1f8c1 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -16,7 +16,6 @@ package util import ( "context" - "errors" "math" "os" "path/filepath" @@ -148,55 +147,6 @@ func (ts *UtilTest) ResolveWhenParentProcDirEnvSetAndAbsoluteFilePath() { assert.Equal(ts.T(), "/var/dir/test.txt", resolvedPath) } -func (ts *UtilTest) TestStringifyShouldReturnAllFieldsPassedInCustomObjectAsMarshalledString() { - sampleMap := map[string]int{ - "1": 1, - "2": 2, - "3": 3, - } - sampleNestedValue := nestedCustomType{ - SomeField: 10, - SomeOther: sampleMap, - } - customObject := &customTypeForSuccess{ - Value: "test_value", - NestedValue: sampleNestedValue, - } - - actual, _ := Stringify(customObject) - - expected := "{\"Value\":\"test_value\",\"NestedValue\":{\"SomeField\":10,\"SomeOther\":{\"1\":1,\"2\":2,\"3\":3}}}" - assert.Equal(ts.T(), expected, actual) -} - -func (ts *UtilTest) TestStringifyShouldReturnEmptyStringWhenMarshalErrorsOut() { - customInstance := customTypeForError{ - value: "example", - } - - actual, _ := Stringify(customInstance) - - expected := "" - assert.Equal(ts.T(), expected, actual) -} - -type customTypeForSuccess struct { - Value string - NestedValue nestedCustomType -} -type nestedCustomType struct { - SomeField int - SomeOther map[string]int -} -type customTypeForError struct { - value string -} - -// MarshalJSON returns an error to simulate a failure during JSON marshaling -func (c customTypeForError) MarshalJSON() ([]byte, error) { - return nil, errors.New("intentional error during JSON marshaling") -} - func (ts *UtilTest) TestMiBsToBytes() { cases := []struct { mib uint64 diff --git a/tools/config-gen/templates/config.tpl b/tools/config-gen/templates/config.tpl index 1f3ff918b8..0f64eb5373 100644 --- a/tools/config-gen/templates/config.tpl +++ b/tools/config-gen/templates/config.tpl @@ -27,7 +27,7 @@ import ( {{range .TypeTemplateData}} type {{ .TypeName}} struct { {{- range $idx, $fld := .Fields}} - {{ $fld.FieldName}} {{ $fld.DataType}} {{$bt}}yaml:"{{$fld.ConfigPath}},omitempty"{{$bt}} + {{ $fld.FieldName}} {{ $fld.DataType}} {{$bt}}yaml:"{{$fld.ConfigPath}},omitempty" json:"{{$fld.ConfigPath}},omitempty"{{$bt}} {{end}} } {{end}}