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

Fixes #1595: Add method to process.py to return both return code and logs #1828

Merged
merged 7 commits into from
Feb 15, 2024

Conversation

favilo
Copy link
Contributor

@favilo favilo commented Jan 30, 2024

As requested in #1595

[x] Have you signed the contributor license agreement?
[x] Have you followed the contributor guidelines?
[x] Have you run make check-all successfully?
[x] Did you choose a descriptive title and description for your PR?

  • (Only for maintainers) Did you apply appropriate labels and a milestone?

@gbanasiak gbanasiak requested a review from a team January 31, 2024 09:49
Copy link
Contributor

@gbanasiak gbanasiak left a comment

Choose a reason for hiding this comment

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

LGTM, but #1595 lacks explicit clarification of what's exactly the win. I think we can find it here.

WDYT about using the modified run_subprocess() to avoid the double call in is_branch() as part of this PR? On quick scan that's probably the only improvement in the git module we can make as other methods use different commands in a sequence?

@gbanasiak gbanasiak linked an issue Jan 31, 2024 that may be closed by this pull request
@favilo
Copy link
Contributor Author

favilo commented Jan 31, 2024

LGTM, but #1595 lacks explicit clarification of what's exactly the win. I think we can find it here.

WDYT about using the modified run_subprocess() to avoid the double call in is_branch() as part of this PR? On quick scan that's probably the only improvement in the git module we can make as other methods use different commands in a sequence?

What do you think about the latest change?

@gbanasiak
Copy link
Contributor

gbanasiak commented Feb 1, 2024

What do you think about the latest change?

Thank you for iterating. 21caafa eliminates duplication but made me realize we're missing the logging now which I think should be kept for troubleshooting purposes. We could add snowflake logging at git module level, or add logging option to run_subprocess(). Or, rewrite run_subprocess_with_logging() to be based on subprocess.run() and return CompletedProcess, but this would extend the scope of the PR. Which option do you find the most elegant?

esrally/utils/process.py Outdated Show resolved Hide resolved
@favilo
Copy link
Contributor Author

favilo commented Feb 1, 2024

What do you think about the latest change?

Thank you for iterating. 21caafa eliminates duplication but made me realize we're missing the logging now which I think should be kept for troubleshooting purposes. We could add snowflake logging at git module level, or add logging option to run_subprocess(). Or, rewrite run_subprocess_with_logging() to be based on subprocess.run() and return CompletedProcess, but this would extend the scope of the PR. Which option do you find the most elegant?

Adding logging option to run_subprocess() feels like the least effort solution here. I wouldn't mind having run_subprocess_with_logging() return a Popen object which would also have .returncode and .stdout, but that has a lot more uses, and since we are already logging, do we need to keep track of the output separately?

I could certainly be convinced that the latter one is the correct approach, but maybe not in this small PR?

EDIT: But then again, the original usecase that brought about this change was needing to do exactly that, so I can run through and add a .returncode to all of those uses, and it will make things more obvious what is going on. Of course, adding type signatures here would also help in the long run.

This will be more compatible with the changes, and keep the return type
the same as `run_subprocess()`

- universal_newline was changed to text in recent versions of the
  library
@favilo favilo added enhancement Improves the status quo good first issue Small, contained changes that are good for newcomers labels Feb 2, 2024
@gbanasiak
Copy link
Contributor

IT tests are failing as it turns out run_subprocess_with_logging() is also used in https://github.com/elastic/rally-teams, e.g. here. I wasn't aware of that. This changes the picture considerably. I think we should go for a new method in the process module for backward compatibility. The problem is https://github.com/elastic/rally-teams code can be interpreted by a range of Rally versions.

Copy link
Contributor

@gbanasiak gbanasiak left a comment

Choose a reason for hiding this comment

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

LGTM. Please change the title of the PR as it's no longer relevant. I've left 2 minor comments.

def run_subprocess(command_line):
def run_subprocess(command_line: str) -> int:
"""
Runs the provided command line in a subprocess. All output will be returned in the `CompletedProcess.stdout` field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Runs the provided command line in a subprocess. All output will be returned in the `CompletedProcess.stdout` field.
Runs the provided command line in a subprocess.

Comment on lines 70 to 71
LogLevel = int
FileId = int
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should type definitions be moved to the top of the file?

@favilo favilo changed the title Fixes #1595: Change run_subprocess to return CompletedProcess object Fixes #1595: Add method to process.py to return both return code and logs Feb 13, 2024
@favilo
Copy link
Contributor Author

favilo commented Feb 14, 2024

Huh, I see the IT tests failed, but looking at the logs, I don't actually see any failures noted.

@favilo favilo merged commit ac2cef9 into elastic:master Feb 15, 2024
15 checks passed
@favilo favilo deleted the favilo-1595 branch February 15, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves the status quo good first issue Small, contained changes that are good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return both exit code, and output in process module
2 participants