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

create the log file along with its parent directory if not present #12675

Merged
merged 27 commits into from
Mar 22, 2024

Conversation

bharath-123
Copy link
Contributor

@bharath-123 bharath-123 commented Jul 31, 2023

What type of PR is this?
Enhancement

What does this PR do? Why is it needed?
Currently, when we specify a log file for the beacon chain node and if the log file parent directories are not present then we don't create the directory and error out. This PR adds support to create the parent directories if not present.

Which issues(s) does this PR fix?

Fixes (#12496)

Other notes for review

nisdas and others added 4 commits March 6, 2023 18:03
* Use Epoch boundary cache to retrieve balances

* save boundary states before inserting to forkchoice

* move up last block save

* remove boundary checks on balances

* fix ordering

---------

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
@bharath-123 bharath-123 requested a review from a team as a code owner July 31, 2023 07:00
if err := os.MkdirAll(filepath.Dir(logFileName), params.BeaconIoConfig().ReadWriteExecutePermissions); err != nil {
return err
}
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWriteExecutePermissions) // #nosec G304
Copy link
Member

Choose a reason for hiding this comment

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

This changes the file permissions. Does the log file need +x?

Suggested change
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWriteExecutePermissions) // #nosec G304
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWritePermissions) // #nosec G304

Copy link
Contributor Author

@bharath-123 bharath-123 Jul 31, 2023

Choose a reason for hiding this comment

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

will fix this. that was not an intended change. The ReadWriteExecute is mainly for the directory to create a file within it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the log file doesnt require +x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be resolved now

@@ -20,6 +21,9 @@ func addLogWriter(w io.Writer) {
// ConfigurePersistentLogging adds a log-to-file writer. File content is identical to stdout.
func ConfigurePersistentLogging(logFileName string) error {
logrus.WithField("logFileName", logFileName).Info("Logs will be made persistent")
if err := os.MkdirAll(filepath.Dir(logFileName), params.BeaconIoConfig().ReadWriteExecutePermissions); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

please use from our io/file package to create these paths, it is the standard method we use across prysm for our file i/o operations

Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

Can you add a regression test for this ?

@bharath-123 bharath-123 force-pushed the create-log-file branch 2 times, most recently from 4caf378 to 2920247 Compare August 21, 2023 20:43
@@ -24,3 +27,58 @@ func TestMaskCredentialsLogging(t *testing.T) {
require.Equal(t, MaskCredentialsLogging(test.url), test.maskedUrl)
}
}

func TestConfigurePersistantLogging(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

For temporary directories for tests use t.TempDir() , this gets cleaned up by the test runner after the test is executed.

prestonvanloon
prestonvanloon previously approved these changes Mar 22, 2024
prestonvanloon
prestonvanloon previously approved these changes Mar 22, 2024
@prestonvanloon prestonvanloon added this pull request to the merge queue Mar 22, 2024
Merged via the queue into prysmaticlabs:develop with commit 3d22302 Mar 22, 2024
17 checks passed
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