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 6 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 main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -185,6 +186,15 @@ func populateArgs(c *cli.Context) (
return
}

func stringify(input any) string {
ankitaluthra1 marked this conversation as resolved.
Show resolved Hide resolved
inputBytes, err := json.Marshal(input)

if err != nil {
logger.Errorf("Error in stringify %v", err)
raj-prince marked this conversation as resolved.
Show resolved Hide resolved
return ""
}
return string(inputBytes)
}
func runCLIApp(c *cli.Context) (err error) {
err = resolvePathForTheFlagsInContext(c)
if err != nil {
Expand Down Expand Up @@ -224,6 +234,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("Loading config for mount flags %s", stringify(*flags))
raj-prince marked this conversation as resolved.
Show resolved Hide resolved
logger.Infof("Loading config from config-file %s", 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
64 changes: 64 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"errors"
"fmt"
"os"
"strings"
"testing"

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

mountpkg "github.com/googlecloudplatform/gcsfuse/internal/mount"
. "github.com/jacobsa/ogletest"
)
Expand Down Expand Up @@ -72,3 +75,64 @@ 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 := stringify(mountConfig)

expected := "{\"CreateEmptyFile\":false,\"Severity\":\"TRACE\",\"Format\":\"\",\"FilePath\":\"\\\"path\\\"to\\\"file\\\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":2,\"BackupFileCount\":2,\"Compress\":true}}"
AssertEq(strings.TrimSpace(expected), strings.TrimSpace(actual))
raj-prince marked this conversation as resolved.
Show resolved Hide resolved
}

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 := 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(strings.TrimSpace(expected), strings.TrimSpace(actual))
}

func (t *MainTest) TestStringifyShouldReturnEmptyStringWhenMarshalErrorsOut() {

raj-prince marked this conversation as resolved.
Show resolved Hide resolved
customInstance := CustomType{
Value: "example",
}

actual := stringify(customInstance)

expected := ""
AssertEq(strings.TrimSpace(expected), strings.TrimSpace(actual))
}

type CustomType struct {
raj-prince marked this conversation as resolved.
Show resolved Hide resolved
Value string
}

// MarshalJSON returns an error to simulate a failure during JSON marshaling
func (c CustomType) MarshalJSON() ([]byte, error) {
return nil, errors.New("intentional error during JSON marshaling")
}