Skip to content

Commit

Permalink
Log new configuration (#2309)
Browse files Browse the repository at this point in the history
* Log new configuration
  • Loading branch information
kislaykishore authored and ashmeenkaur committed Aug 19, 2024
1 parent 9907bc4 commit 0ad76e8
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 157 deletions.
156 changes: 78 additions & 78 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cfg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 1 addition & 13 deletions cmd/legacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package util

import (
"context"
"encoding/json"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -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.
Expand Down
50 changes: 0 additions & 50 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package util

import (
"context"
"errors"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0ad76e8

Please sign in to comment.