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

Respect log format flag/config for stdout logs #1770

Merged
merged 6 commits into from
Mar 11, 2024

Conversation

ashmeenkaur
Copy link
Collaborator

@ashmeenkaur ashmeenkaur commented Mar 6, 2024

Description

Background: A default logger with log format json is created using golang init() function. This logger logs the output to stdout/stderr until explict logger is created based on user specified configuration/flags.

This PR includes changes to ensure that init logger respects the user specified log format.

Link to the issue in case of a bug fix.

NA

Testing details

  1. Manual - Manually verifies the console output:
Default format

ashmeen@ashmeen:~/gcsfuse$ go run ./ ashmeenbkt /tmp/mnt
{"timestamp":{"seconds":1709746144,"nanos":259745636},"severity":"INFO","message":"Start gcsfuse/unknown (Go version go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto) for app \"\" using mount point: /tmp/mnt\n"}
{"timestamp":{"seconds":1709746144,"nanos":259907976},"severity":"INFO","message":"GCSFuse mount command flags: {\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"\",\"MountOptions\":{},\"DirMode\":493,\"FileMode\":420,\"Uid\":-1,\"Gid\":-1,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":true,\"EgressBandwidthLimitBytesPerSecond\":-1,\"OpRateLimitHz\":-1,\"SequentialReadSizeMb\":200,\"MaxRetrySleep\":30000000000,\"StatCacheCapacity\":20460,\"StatCacheTTL\":60000000000,\"TypeCacheTTL\":60000000000,\"HttpClientTimeout\":0,\"MaxRetryDuration\":-1000000000,\"RetryMultiplier\":2,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http1\",\"MaxConnsPerHost\":100,\"MaxIdleConnsPerHost\":100,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"json\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":true,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"}
{"timestamp":{"seconds":1709746144,"nanos":259959126},"severity":"INFO","message":"GCSFuse mount config flags: {\"CreateEmptyFile\":false,\"Severity\":\"INFO\",\"Format\":\"json\",\"FilePath\":\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":512,\"BackupFileCount\":10,\"Compress\":true},\"MaxSizeMB\":-1,\"CacheFileForRangeRead\":false,\"CacheDir\":\"\",\"TtlInSeconds\":-9223372036854775808,\"TypeCacheMaxSizeMB\":4,\"StatCacheMaxSizeMB\":-9223372036854775808,\"EnableEmptyManagedFolders\":false}"}
{"timestamp":{"seconds":1709746144,"nanos":573254485},"severity":"INFO","message":"File system has been successfully mounted."}

Text Format via flag

ashmeen@ashmeen:~/gcsfuse$ go run ./ --log-format=text ashmeenbkt /tmp/mnt
time="06/03/2024 05:27:56.373766" severity=INFO message="Start gcsfuse/unknown (Go version go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto) for app \"\" using mount point: /tmp/mnt\n"
time="06/03/2024 05:27:56.373967" severity=INFO message="GCSFuse mount command flags: {\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"\",\"MountOptions\":{},\"DirMode\":493,\"FileMode\":420,\"Uid\":-1,\"Gid\":-1,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":true,\"EgressBandwidthLimitBytesPerSecond\":-1,\"OpRateLimitHz\":-1,\"SequentialReadSizeMb\":200,\"MaxRetrySleep\":30000000000,\"StatCacheCapacity\":20460,\"StatCacheTTL\":60000000000,\"TypeCacheTTL\":60000000000,\"HttpClientTimeout\":0,\"MaxRetryDuration\":-1000000000,\"RetryMultiplier\":2,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http1\",\"MaxConnsPerHost\":100,\"MaxIdleConnsPerHost\":100,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"text\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":true,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"
time="06/03/2024 05:27:56.374023" severity=INFO message="GCSFuse mount config flags: {\"CreateEmptyFile\":false,\"Severity\":\"INFO\",\"Format\":\"text\",\"FilePath\":\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":512,\"BackupFileCount\":10,\"Compress\":true},\"MaxSizeMB\":-1,\"CacheFileForRangeRead\":false,\"CacheDir\":\"\",\"TtlInSeconds\":-9223372036854775808,\"TypeCacheMaxSizeMB\":4,\"StatCacheMaxSizeMB\":-9223372036854775808,\"EnableEmptyManagedFolders\":false}"
time="06/03/2024 05:27:56.677186" severity=INFO message="File system has been successfully mounted."

JSON Format via flag

ashmeen@ashmeen:~/gcsfuse$ go run ./ --log-format=json ashmeenbkt /tmp/mnt
{"timestamp":{"seconds":1709746106,"nanos":301735419},"severity":"INFO","message":"Start gcsfuse/unknown (Go version go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto) for app \"\" using mount point: /tmp/mnt\n"}
{"timestamp":{"seconds":1709746106,"nanos":301988849},"severity":"INFO","message":"GCSFuse mount command flags: {\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"\",\"MountOptions\":{},\"DirMode\":493,\"FileMode\":420,\"Uid\":-1,\"Gid\":-1,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":true,\"EgressBandwidthLimitBytesPerSecond\":-1,\"OpRateLimitHz\":-1,\"SequentialReadSizeMb\":200,\"MaxRetrySleep\":30000000000,\"StatCacheCapacity\":20460,\"StatCacheTTL\":60000000000,\"TypeCacheTTL\":60000000000,\"HttpClientTimeout\":0,\"MaxRetryDuration\":-1000000000,\"RetryMultiplier\":2,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http1\",\"MaxConnsPerHost\":100,\"MaxIdleConnsPerHost\":100,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"json\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":true,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"}
{"timestamp":{"seconds":1709746106,"nanos":302051319},"severity":"INFO","message":"GCSFuse mount config flags: {\"CreateEmptyFile\":false,\"Severity\":\"INFO\",\"Format\":\"json\",\"FilePath\":\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":512,\"BackupFileCount\":10,\"Compress\":true},\"MaxSizeMB\":-1,\"CacheFileForRangeRead\":false,\"CacheDir\":\"\",\"TtlInSeconds\":-9223372036854775808,\"TypeCacheMaxSizeMB\":4,\"StatCacheMaxSizeMB\":-9223372036854775808,\"EnableEmptyManagedFolders\":false}"}
{"timestamp":{"seconds":1709746106,"nanos":721464755},"severity":"INFO","message":"File system has been successfully mounted."}

JSON Format via config file

ashmeen@ashmeen:~/gcsfuse$ go run ./ --config-file=~/Documents/config.yaml ashmeenbkt /tmp/mnt
{"time":"06/03/2024 05:30:46.926068","severity":"INFO","message":"Value of [config-file] resolved from [~/Documents/config.yaml] to [/usr/local/google/home/ashmeen/Documents/config.yaml]\n"}
{"timestamp":{"seconds":1709746246,"nanos":926277650},"severity":"INFO","message":"Start gcsfuse/unknown (Go version go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto) for app \"\" using mount point: /tmp/mnt\n"}
{"timestamp":{"seconds":1709746246,"nanos":926462020},"severity":"INFO","message":"GCSFuse mount command flags: {\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"/usr/local/google/home/ashmeen/Documents/config.yaml\",\"MountOptions\":{},\"DirMode\":493,\"FileMode\":420,\"Uid\":-1,\"Gid\":-1,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":true,\"EgressBandwidthLimitBytesPerSecond\":-1,\"OpRateLimitHz\":-1,\"SequentialReadSizeMb\":200,\"MaxRetrySleep\":30000000000,\"StatCacheCapacity\":20460,\"StatCacheTTL\":60000000000,\"TypeCacheTTL\":60000000000,\"HttpClientTimeout\":0,\"MaxRetryDuration\":-1000000000,\"RetryMultiplier\":2,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http1\",\"MaxConnsPerHost\":100,\"MaxIdleConnsPerHost\":100,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"json\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":true,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"}
{"timestamp":{"seconds":1709746246,"nanos":926519580},"severity":"INFO","message":"GCSFuse mount config flags: {\"CreateEmptyFile\":false,\"Severity\":\"INFO\",\"Format\":\"json\",\"FilePath\":\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":512,\"BackupFileCount\":10,\"Compress\":true},\"MaxSizeMB\":-1,\"CacheFileForRangeRead\":false,\"CacheDir\":\"\",\"TtlInSeconds\":3600,\"TypeCacheMaxSizeMB\":0,\"StatCacheMaxSizeMB\":10000,\"EnableEmptyManagedFolders\":false}"}
{"timestamp":{"seconds":1709746247,"nanos":248655939},"severity":"INFO","message":"File system has been successfully mounted."}
Text Format via config file

ashmeen@ashmeen:~/gcsfuse$ go run ./ --config-file=~/Documents/config.yaml ashmeenbkt /tmp/mnt
{"time":"06/03/2024 05:31:35.071958","severity":"INFO","message":"Value of [config-file] resolved from [~/Documents/config.yaml] to [/usr/local/google/home/ashmeen/Documents/config.yaml]\n"}
time="06/03/2024 05:31:35.072193" severity=INFO message="Start gcsfuse/unknown (Go version go1.22-20240109-RC01 cl/597041403 +dcbe772469 X:fieldtrack,boringcrypto) for app \"\" using mount point: /tmp/mnt\n"
time="06/03/2024 05:31:35.072323" severity=INFO message="GCSFuse mount command flags: {\"AppName\":\"\",\"Foreground\":false,\"ConfigFile\":\"/usr/local/google/home/ashmeen/Documents/config.yaml\",\"MountOptions\":{},\"DirMode\":493,\"FileMode\":420,\"Uid\":-1,\"Gid\":-1,\"ImplicitDirs\":false,\"OnlyDir\":\"\",\"RenameDirLimit\":0,\"CustomEndpoint\":null,\"BillingProject\":\"\",\"KeyFile\":\"\",\"TokenUrl\":\"\",\"ReuseTokenFromUrl\":true,\"EgressBandwidthLimitBytesPerSecond\":-1,\"OpRateLimitHz\":-1,\"SequentialReadSizeMb\":200,\"MaxRetrySleep\":30000000000,\"StatCacheCapacity\":20460,\"StatCacheTTL\":60000000000,\"TypeCacheTTL\":60000000000,\"HttpClientTimeout\":0,\"MaxRetryDuration\":-1000000000,\"RetryMultiplier\":2,\"LocalFileCache\":false,\"TempDir\":\"\",\"ClientProtocol\":\"http1\",\"MaxConnsPerHost\":100,\"MaxIdleConnsPerHost\":100,\"EnableNonexistentTypeCache\":false,\"StackdriverExportInterval\":0,\"OtelCollectorAddress\":\"\",\"LogFile\":\"\",\"LogFormat\":\"json\",\"ExperimentalEnableJsonRead\":false,\"DebugFuseErrors\":true,\"DebugFuse\":false,\"DebugFS\":false,\"DebugGCS\":false,\"DebugHTTP\":false,\"DebugInvariants\":false,\"DebugMutex\":false}"
time="06/03/2024 05:31:35.072380" severity=INFO message="GCSFuse mount config flags: {\"CreateEmptyFile\":false,\"Severity\":\"INFO\",\"Format\":\"text\",\"FilePath\":\"\",\"LogRotateConfig\":{\"MaxFileSizeMB\":512,\"BackupFileCount\":10,\"Compress\":true},\"MaxSizeMB\":-1,\"CacheFileForRangeRead\":false,\"CacheDir\":\"\",\"TtlInSeconds\":3600,\"TypeCacheMaxSizeMB\":0,\"StatCacheMaxSizeMB\":10000,\"EnableEmptyManagedFolders\":false}"
time="06/03/2024 05:31:35.366242" severity=INFO message="File system has been successfully mounted."
  1. Unit tests - NA
  2. Integration tests - Via KOKORO

@ashmeenkaur ashmeenkaur added the execute-integration-tests Run only integration tests label Mar 6, 2024
@ashmeenkaur ashmeenkaur marked this pull request as ready for review March 6, 2024 18:53
Copy link
Collaborator

@mustvicky mustvicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have UTs for this change? What if we break the new behavior later accidentally

Copy link
Collaborator

@gargnitingoogle gargnitingoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashmeenkaur I left some comment. Please address.

internal/logger/logger.go Outdated Show resolved Hide resolved
internal/logger/logger.go Show resolved Hide resolved
main.go Show resolved Hide resolved
@ashmeenkaur
Copy link
Collaborator Author

Does it make sense to have UTs for this change? What if we break the new behavior later accidentally

Added unit tests for SetLogFormat method, however adding tests for main is difficult and it will essentially be an integration test.

@ashmeenkaur ashmeenkaur removed the execute-integration-tests Run only integration tests label Mar 7, 2024
Copy link
Collaborator

@gargnitingoogle gargnitingoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashmeenkaur I added some more comments. Please address.

main.go Show resolved Hide resolved
internal/logger/logger.go Outdated Show resolved Hide resolved
internal/logger/logger.go Show resolved Hide resolved
internal/logger/logger.go Outdated Show resolved Hide resolved
internal/logger/logger_test.go Outdated Show resolved Hide resolved
@gargnitingoogle
Copy link
Collaborator

@ashmeenkaur Could you please share the link to the passed integration test run?

main.go Outdated Show resolved Hide resolved
@gargnitingoogle gargnitingoogle self-requested a review March 8, 2024 08:34
gargnitingoogle
gargnitingoogle previously approved these changes Mar 8, 2024
Copy link
Collaborator

@gargnitingoogle gargnitingoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nitpick and a fix expected in a future PR.

@ashmeenkaur
Copy link
Collaborator Author

@ashmeenkaur Could you please share the link to the passed integration test run?

Added to the PR description

Co-authored-by: Nitin Garg <113666283+gargnitingoogle@users.noreply.github.com>
gargnitingoogle
gargnitingoogle previously approved these changes Mar 8, 2024
Copy link
Collaborator

@gargnitingoogle gargnitingoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a future non-blocking fix pending.

Copy link
Collaborator

@raj-prince raj-prince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. one minor comment.

@ashmeenkaur ashmeenkaur merged commit 5e6aa1e into master Mar 11, 2024
8 checks passed
@ashmeenkaur ashmeenkaur deleted the fix_log_format_at_init branch March 11, 2024 01:22
Tulsishah pushed a commit that referenced this pull request Mar 15, 2024
* respect log format flag/config for stdout logs.

* add unit test

* review comments

* review comments

* Update main.go

Co-authored-by: Nitin Garg <113666283+gargnitingoogle@users.noreply.github.com>

* review comments

---------

Co-authored-by: Nitin Garg <113666283+gargnitingoogle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants