Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding log to print all configuration flags at start of gcs fuse mount #1565

Merged
merged 14 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package util

import (
"encoding/json"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -76,3 +77,14 @@ func ResolveConfigFilePaths(config *config.MountConfig) (err error) {
}
return
}

// Returns empty String in case of failure in marshalling the passed input.
ankitaluthra1 marked this conversation as resolved.
Show resolved Hide resolved
func Stringify(input any) string {
ankitaluthra1 marked this conversation as resolved.
Show resolved Hide resolved
inputBytes, err := json.Marshal(input)

if err != nil {
logger.Warnf("Error in Stringify %v", err)
return ""
}
return string(inputBytes)
}
50 changes: 50 additions & 0 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package util

import (
"errors"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -157,3 +158,52 @@ func (t *UtilTest) TestResolveConfigFilePaths() {
AssertEq(nil, err)
ExpectEq(filepath.Join(homeDir, "test.txt"), mountConfig.LogConfig.FilePath)
}

func (t *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}}}"
AssertEq(expected, actual)
}

func (t *UtilTest) TestStringifyShouldReturnEmptyStringWhenMarshalErrorsOut() {
customInstance := customTypeForError{
value: "example",
}

actual := Stringify(customInstance)

expected := ""
AssertEq(expected, actual)
}

type customTypeForSuccess struct {
Value string
ankitaluthra1 marked this conversation as resolved.
Show resolved Hide resolved
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")
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ func runCLIApp(c *cli.Context) (err error) {
}

logger.Infof("Start gcsfuse/%s for app %q using mount point: %s\n", getVersion(), flags.AppName, mountPoint)
logger.Infof("GCSFuse mount command flags: %s", util.Stringify(*flags))
logger.Infof("GCSFuse mount config flags: %s", util.Stringify(*mountConfig))

// If we haven't been asked to run in foreground mode, we should run a daemon
// with the foreground flag set and wait for it to mount.
Expand Down
43 changes: 43 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"strings"
"testing"

"github.com/googlecloudplatform/gcsfuse/internal/config"
"github.com/googlecloudplatform/gcsfuse/internal/util"

mountpkg "github.com/googlecloudplatform/gcsfuse/internal/mount"
. "github.com/jacobsa/ogletest"
)
Expand Down Expand Up @@ -72,3 +75,43 @@ func (t *MainTest) TestGetUserAgentWhenMetadataImageTypeEnvVarSetAndAppNameNotSe

ExpectEq(expectedUserAgent, userAgent)
}

func (t *MainTest) TestStringifyShouldReturnAllFlagsPassedInMountConfigAsMarshalledString() {
mountConfig := &config.MountConfig{
WriteConfig: config.WriteConfig{
CreateEmptyFile: false,
},
LogConfig: config.LogConfig{
Severity: config.TRACE,
FilePath: "\"path\"to\"file\"",
LogRotateConfig: config.LogRotateConfig{
MaxFileSizeMB: 2,
BackupFileCount: 2,
Compress: true,
},
},
}

actual := util.Stringify(mountConfig)

expected := "{\"CreateEmptyFile\":false,\"Severity\":\"TRACE\",\"Format\":\"\",\"FilePath\":\"\\\"path\\\"to\\\"file\\\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":2,\"BackupFileCount\":2,\"Compress\":true}}"
AssertEq(expected, actual)
}

func (t *MainTest) TestStringifyShouldReturnAllFlagsPassedInFlagStorageAsMarshalledString() {
mountOptions := map[string]string{
"1": "one",
"2": "two",
"3": "three",
}
flags := &flagStorage{
SequentialReadSizeMb: 10,
ClientProtocol: mountpkg.ClientProtocol("http4"),
MountOptions: mountOptions,
}

actual := util.Stringify(flags)

expected := "{\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"\",\"MountOptions\":{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"},\"DirMode\":0,\"FileMode\":0,\"Uid\":0,\"Gid\":0,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":false,\"EgressBandwidthLimitBytesPerSecond\":0,\"OpRateLimitHz\":0,\"SequentialReadSizeMb\":10,\"MaxRetrySleep\":0,\"StatCacheCapacity\":0,\"StatCacheTTL\":0,\"TypeCacheTTL\":0,\"HttpClientTimeout\":0,\"MaxRetryDuration\":0,\"RetryMultiplier\":0,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http4\",\"MaxConnsPerHost\":0,\"MaxIdleConnsPerHost\":0,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":false,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"
AssertEq(expected, actual)
}