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

xtask: redirect stdout and stderr into log files #231

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

gabriele-0201
Copy link
Contributor

No description provided.

Copy link
Contributor Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

id = "build.log-path"
)]
#[clap(default_value = "xtask/build.log")]
pub log_path: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that these are all flattened into the same Params, how do you differentiate them?

Which one does --log-path X trigger?

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 trick with value_name and id makes the items look like <prefix>-log-path, where the prefix could be zombienet, shim, or sovereign to specify the path where you want to output the logs of the prefix process. This is a workaround, though, and the discussion on how the flags should look like can be found here: #224

@@ -9,27 +10,35 @@ pub fn build(params: BuildParams) -> anyhow::Result<()> {
return Ok(());
}

// Erase the log file if it already exists
std::fs::File::create(&params.log_path)?.set_len(0)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The documentation for create states, quote,

This function will create a file if it does not exist, and will truncate it if it does.
which suggests that set_len may be redundant.

  1. It is possible that the log_path points to a file located in a directory that doesn't exist. In that case, I am pretty sure that create can return an error. The intuitive behavior would be to create all the parent directories leading to the specified file path.
  2. A more high-level consideration, do you think that failure creating of the log file warrants terminating the process? I would say this is not super important, but if it's easy to fix then we could do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Totally right, both are not needed. I will remove set_len
  2. Nice edge case. I didn't think about it yesterday. If I'm correct, there is no option in the File struct to create all the directories, but it needs to be done in two steps with std::fs::create_dir_all
  3. Probably a fallback into the default log position firstly, and if that fails too, maybe just print stuff to stdout? It is absolutely doable!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, if the creation of the folder specified in the path or the file itself is a problem, then stdout is the fallback. Implementing this was a little more complex than expected, but I hope to have come up with a versatile and good enough solution

Copy link
Contributor

@pepyakin pepyakin Feb 15, 2024

Choose a reason for hiding this comment

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

FWIW, I was more thinking of ignoring the failure and discarding output (although maybe with a warning). This is not critical data, you can always re-run the code. I think the criteria here should be the simplicity of the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, okay, then I added a small modification. However, for how the duct is built, even discarding the output would require calling a method on the expression. It would be something like expression.stdout_null().stderr_null().run() instead of expression.stderr_to_stdout().stdout_file(log_file).run().

If you prefer, it would be really easy to switch to discarding the output instead of printing it to stdout in the current implementation, so let me know which one you think is more appropriate!

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's fine for now

.gitignore Outdated
@@ -8,3 +8,4 @@
/demo/sovereign/target
/demo/sovereign/demo-rollup/demo_data
/target
/xtask/*.log
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a good idea to mix logs with the source files.

Recall my suggestion where we could store all the test data files (for zombienet, sovereign demo rollup, and now logs) in a single place. Do you disagree with 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.

Absolutely not! I would really like to have all data in the same place but to be fair, with the current setup, I would not know how to place the zombienet folder, the demo-data folder, and the logs in the same location.

The problem is about the zombienet and logs, but mainly the sovereign rollup as described here: #227

@gabriele-0201 gabriele-0201 force-pushed the gab_xtask_redirect_log branch 4 times, most recently from 2e1b823 to a577f77 Compare February 15, 2024 09:55
@gabriele-0201 gabriele-0201 marked this pull request as ready for review February 15, 2024 09:59
@pepyakin pepyakin merged commit bcd3589 into main Feb 16, 2024
5 checks passed
@pepyakin pepyakin deleted the gab_xtask_redirect_log branch February 16, 2024 11:20
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.

3 participants