Skip to content

Commit

Permalink
Catch crash logs in stderr log file for background process (#2503)
Browse files Browse the repository at this point in the history
* catch crash logs in log file

* lint fix

* lint fix

* lint fix

* lint fix

* fix lint

* fix lint

* create log file only instead of logger

* lint fix

* small fox

* remove unnecessary changes

* remove unnecessary changes

* test changes

* create .dump file to capture crash

* remove unnecessary change

* change var name

* lint fix

* test cfix

* test fix

* test fix

* lint fix

* small fix

* small fix

* replace stdout instead of stderr

* replace stdout instead of stderr

* remove capturing in os.stderr

* remove capturing in os.stderr

* Update tools/integration_tests/log_rotation/log_rotation_test.go

Co-authored-by: Kislay Kishore <[email protected]>

---------

Co-authored-by: Kislay Kishore <[email protected]>
  • Loading branch information
Tulsishah and kislaykishore authored Sep 26, 2024
1 parent b908a3c commit 4f40a8f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
10 changes: 9 additions & 1 deletion cmd/legacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,16 @@ func Mount(newConfig *cfg.Config, bucketName, mountPoint string) (err error) {
// programme is running as daemon process.
env = append(env, fmt.Sprintf("%s=true", logger.GCSFuseInBackgroundMode))

// logfile.stderr will capture the standard error (stderr) output of the gcsfuse background process.
var stderrFile *os.File
if newConfig.Logging.FilePath != "" {
stderrFileName := string(newConfig.Logging.FilePath) + ".stderr"
if stderrFile, err = os.OpenFile(stderrFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644); err != nil {
return err
}
}
// Run.
err = daemonize.Run(path, args, env, os.Stdout)
err = daemonize.Run(path, args, env, os.Stdout, stderrFile)
if err != nil {
return fmt.Errorf("daemonize.Run: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/fsouza/fake-gcs-server v1.49.3
github.com/google/uuid v1.6.0
github.com/googleapis/gax-go/v2 v2.13.0
github.com/jacobsa/daemonize v0.0.0-20160101105449-e460293e890f
github.com/jacobsa/daemonize v0.0.0-20240917082746-f35568b6c3ec
github.com/jacobsa/fuse v0.0.0-20240607092844-7285af0d05b0
github.com/jacobsa/oglematchers v0.0.0-20150720000706-141901ea67cd
github.com/jacobsa/oglemock v0.0.0-20150831005832-e94d794d06ff
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9FCCAVRQ=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
github.com/jacobsa/daemonize v0.0.0-20160101105449-e460293e890f h1:X+tnaqoCcBgAwSTJtoYW6p0qKiuPyMfofEHEFUf2kdU=
github.com/jacobsa/daemonize v0.0.0-20160101105449-e460293e890f/go.mod h1:Ip4fOwzCrnDVuluHBd7FXIMb7SHOKfkt9/UDrYSZvqI=
github.com/jacobsa/daemonize v0.0.0-20240917082746-f35568b6c3ec h1:xsRGrfdnjvJtEMD2ouh8gOGIeDF9LrgXjo+9Q69RVzI=
github.com/jacobsa/daemonize v0.0.0-20240917082746-f35568b6c3ec/go.mod h1:Ip4fOwzCrnDVuluHBd7FXIMb7SHOKfkt9/UDrYSZvqI=
github.com/jacobsa/fuse v0.0.0-20240607092844-7285af0d05b0 h1:IWVMQZZvWN+9FeRwWnZAINYNrsr3yyCWI2BcddQBDvk=
github.com/jacobsa/fuse v0.0.0-20240607092844-7285af0d05b0/go.mod h1:JYi9iIxdYNgxmMgLwtSHO/hmVnP2kfX1oc+mtx+XWLA=
github.com/jacobsa/oglematchers v0.0.0-20150720000706-141901ea67cd h1:9GCSedGjMcLZCrusBZuo4tyKLpKUPenUUqi34AkuFmA=
Expand Down
3 changes: 2 additions & 1 deletion tools/integration_tests/log_rotation/log_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const (
logDirName = "gcsfuse_integration_test_logs"
maxFileSizeMB = 2
activeLogFileCount = 1
stderrLogFileCount = 1
backupLogFileCount = 2
logFileCount = activeLogFileCount + backupLogFileCount
logFileCount = activeLogFileCount + backupLogFileCount + stderrLogFileCount // Adding 1 for stderr logs file
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestLogRotation(t *testing.T) {
validateLogFileSize(t, dirEntries[i])
} else if strings.Contains(dirEntries[i].Name(), "txt.gz") {
rotatedCompressedFileCtr++
} else {
} else if !strings.Contains(dirEntries[i].Name(), ".stderr") {
rotatedUncompressedFileCtr++
validateLogFileSize(t, dirEntries[i])
}
Expand Down

0 comments on commit 4f40a8f

Please sign in to comment.