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

Add option to write flux log files #519

Merged
merged 22 commits into from
Dec 20, 2024
Merged

Add option to write flux log files #519

merged 22 commits into from
Dec 20, 2024

Conversation

jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Dec 13, 2024

Summary by CodeRabbit

  • New Features

    • Introduced an optional parameter, flux_log_files, for enhanced logging control in various executor-related functionalities.
    • Added functionality to log standard output and error messages to files when flux_log_files is enabled.
  • Bug Fixes

    • Improved input validation for executor creation processes, ensuring robust checks for the flux_log_files parameter.
  • Documentation

    • Updated method signatures to reflect the addition of the flux_log_files parameter across multiple classes and functions.
    • Added new tests to enhance coverage for the check_flux_log_files function and the logging functionality in the executor.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new optional parameter, flux_log_files, to several components within the executor library. This parameter is added to the Executor class's __init__ and __new__ methods, as well as to the create_file_executor and create_executor functions. Additionally, a new function, check_flux_log_files, is introduced to validate this parameter. The modifications enhance the logging configuration capabilities in various executor-related classes without altering existing functionality.

Changes

File Change Summary
executorlib/__init__.py Added flux_log_files parameter to __init__ and __new__ methods of Executor.
executorlib/cache/executor.py Added flux_log_files parameter to create_file_executor; integrated validation with check_flux_log_files.
executorlib/interactive/executor.py Added flux_log_files parameter to create_executor method; integrated validation for backends.
executorlib/interactive/flux.py Added flux_log_files parameter to FluxPythonSpawner constructor; enhanced logging in bootup method.
executorlib/standalone/inputcheck.py Introduced check_flux_log_files function to validate flux_log_files parameter.
tests/test_shared_input_check.py Added test_check_flux_log_files to test check_flux_log_files function for error handling.
tests/test_executor_backend_flux.py Added test_output_files_cwd and test_output_files_abs to test output file handling in executors.

Possibly related PRs

  • Add option to write flux log files #519: This PR adds the flux_log_files parameter to the Executor class, which is directly related to the changes in the main PR that also introduces this parameter to the Executor class's methods.
  • test working directory #530: This PR introduces a test for the Executor class that verifies functionality when specifying a working directory, which is relevant to the logging and output handling changes made in the main PR.

🐇 In the meadow where bunnies hop,
A new log feature makes us stop!
With flux_log_files now in play,
We capture logs in a brand new way.
So let’s cheer for changes, big and small,
In our code garden, we’re having a ball! 🌼

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7371b7 and 5d0046d.

📒 Files selected for processing (4)
  • executorlib/__init__.py (7 hunks)
  • executorlib/interactive/executor.py (6 hunks)
  • executorlib/interactive/flux.py (4 hunks)
  • tests/test_executor_backend_flux.py (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
executorlib/interactive/flux.py (2)

22-22: Enhance parameter documentation

Consider adding more context about where the log files will be written and their naming convention.

-        flux_log_files (bool, optional): Write flux stdout and stderr files. Defaults to False.
+        flux_log_files (bool, optional): Write flux stdout and stderr to 'flux.out' and 'flux.err' files in the working directory. Defaults to False.

91-93: Consider making log file names configurable

The implementation looks good, but consider making the log file names configurable for better flexibility.

-            jobspec.stderr = os.path.join(self._cwd, "flux.err")
-            jobspec.stdout = os.path.join(self._cwd, "flux.out")
+            jobspec.stderr = os.path.join(self._cwd, self._stderr_filename or "flux.err")
+            jobspec.stdout = os.path.join(self._cwd, self._stdout_filename or "flux.out")
executorlib/standalone/inputcheck.py (1)

158-159: Remove extra blank line

There's an unnecessary double blank line here.

    )

-

def check_pysqa_config_directory(pysqa_config_directory: Optional[str]) -> None:
executorlib/interactive/executor.py (2)

158-158: Add parameter documentation in the function docstring

The new flux_log_files parameter should be documented in the function's docstring to maintain API documentation completeness.


218-218: Consider consolidating flux_log_files validation

The validation of flux_log_files is performed differently between backends:

  • For flux backend: Directly used in resource_dict without validation
  • For other backends: Validated but not used

Consider validating the parameter consistently across all code paths, preferably at the beginning of the function.

 def create_executor(...):
     check_init_function(block_allocation=block_allocation, init_function=init_function)
+    check_flux_log_files(flux_log_files=flux_log_files)
     if flux_executor is not None and backend != "flux_allocation":
         backend = "flux_allocation"

Also applies to: 241-241, 264-264

executorlib/__init__.py (1)

97-97: Document flux_log_files parameter in class docstring

The new flux_log_files parameter should be documented in the class docstring under the Args section to maintain API documentation completeness.

Add the following to the class docstring's Args section:

         flux_executor_nesting (bool): Provide hierarchically nested Flux job scheduler inside the submitted function.
+        flux_log_files (bool): Enable writing of Flux framework log files. Only applicable for Flux backend.
         pysqa_config_directory (str, optional): path to the pysqa config directory (only for pysqa based backend).

Also applies to: 119-119

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1c4ffa and d14ebbd.

📒 Files selected for processing (5)
  • executorlib/__init__.py (5 hunks)
  • executorlib/cache/executor.py (3 hunks)
  • executorlib/interactive/executor.py (5 hunks)
  • executorlib/interactive/flux.py (4 hunks)
  • executorlib/standalone/inputcheck.py (1 hunks)
🔇 Additional comments (4)
executorlib/cache/executor.py (1)

13-13: LGTM!

The changes are well-structured:

  • Import of the new validation function is properly placed
  • Parameter addition follows the existing pattern
  • Validation is correctly placed with other input checks

Also applies to: 92-92, 114-114

executorlib/standalone/inputcheck.py (1)

150-157: LGTM!

The validation function is well-implemented with proper type hints, documentation, and consistent error message pattern.

executorlib/__init__.py (2)

199-199: LGTM: Parameter properly forwarded to all executor creation paths

The flux_log_files parameter is consistently passed through all three executor creation paths:

  1. create_file_executor
  2. _ExecutorWithDependencies
  3. _create_executor

Also applies to: 217-217, 237-237


Line range hint 158-158: Verify log file writing behavior and security implications

Please ensure:

  1. Log files are written to a secure location with appropriate permissions
  2. The feature is properly tested with the Flux backend
  3. No sensitive information is exposed in the logs

Also applies to: 97-97

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d14ebbd and e7371b7.

📒 Files selected for processing (3)
  • executorlib/__init__.py (7 hunks)
  • executorlib/interactive/executor.py (6 hunks)
  • tests/test_shared_input_check.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • executorlib/interactive/executor.py
🔇 Additional comments (4)
tests/test_shared_input_check.py (1)

10-10: LGTM!

The import statement follows the existing pattern and is properly placed in alphabetical order.

executorlib/__init__.py (3)

48-48: LGTM!

The parameter documentation is clear and follows the existing docstring style.


201-201: Verify parameter forwarding to all executor creation functions.

The flux_log_files parameter is forwarded to all executor creation functions. Let's ensure the implementation is complete by verifying:

  1. Parameter validation in each executor creation function
  2. Proper handling in the actual flux executor implementation

Also applies to: 219-219, 239-239

✅ Verification successful

Parameter forwarding and validation for flux_log_files is properly implemented

The verification shows complete implementation chain:

  • Parameter validation through check_flux_log_files() is present in all executor modules (cache, interactive)
  • The parameter is properly forwarded through creation functions
  • The FluxExecutor implementation in executorlib/interactive/flux.py handles the parameter correctly with proper storage and conditional usage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify complete implementation chain

# Check executor creation functions
rg -A 10 "def create_.*executor.*flux_log_files" --type python

# Check flux executor implementation
rg -A 10 "class.*FluxExecutor" --type python

Length of output: 173


Script:

#!/bin/bash
# Let's try without file type filtering since python extension is not recognized
# Check executor creation functions
rg -A 10 "def create_.*executor.*flux_log_files"

# Check flux executor implementation and usage
rg -A 10 "class.*FluxExecutor"

# Also search for flux_log_files usage
rg "flux_log_files"

Length of output: 2425


98-98: Verify flux_log_files parameter implementation in backend executors.

The parameter is properly added to both __init__ and __new__ methods. However, we should verify that this parameter is only used with the flux backend.

Also applies to: 120-120

✅ Verification successful

Based on the search results, I can now generate the final response as we have sufficient evidence about the flux_log_files parameter implementation:

The flux_log_files parameter is properly validated and only used with the flux backend

The codebase implements proper validation through:

  • A dedicated validation function check_flux_log_files() that raises ValueError if the parameter is used with non-flux backends
  • The parameter is only used in executorlib/interactive/flux.py for the Flux executor implementation
  • The validation is called in all executor creation paths
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if flux_log_files parameter is properly validated in backend executors

# Search for flux_log_files parameter usage
rg -A 5 "flux_log_files" --type python

# Search for backend-specific validation
ast-grep --pattern 'if backend == "flux" { $$$ flux_log_files $$$ }'

Length of output: 140


Script:

#!/bin/bash
# Search for flux_log_files parameter usage with correct file type
rg -A 5 "flux_log_files" -t py

# Search for backend validation patterns
rg -A 10 'backend.*=.*"flux"' -t py

# Search for flux backend executor implementation
rg -t py "class.*FluxExecutor"

Length of output: 12535

Comment on lines +71 to +73
def test_check_flux_log_files(self):
with self.assertRaises(ValueError):
check_flux_log_files(flux_log_files=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage with additional test cases.

The current test only verifies that flux_log_files=True raises a ValueError. Consider adding test cases for:

  • flux_log_files=False (valid case)
  • Non-boolean values (invalid case)
 def test_check_flux_log_files(self):
     with self.assertRaises(ValueError):
         check_flux_log_files(flux_log_files=True)
+    # Valid case should not raise
+    check_flux_log_files(flux_log_files=False)
+    # Non-boolean values should raise
+    with self.assertRaises(TypeError):
+        check_flux_log_files(flux_log_files="True")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_check_flux_log_files(self):
with self.assertRaises(ValueError):
check_flux_log_files(flux_log_files=True)
def test_check_flux_log_files(self):
with self.assertRaises(ValueError):
check_flux_log_files(flux_log_files=True)
# Valid case should not raise
check_flux_log_files(flux_log_files=False)
# Non-boolean values should raise
with self.assertRaises(TypeError):
check_flux_log_files(flux_log_files="True")

@jan-janssen jan-janssen marked this pull request as draft December 17, 2024 00:57
@jan-janssen jan-janssen marked this pull request as ready for review December 20, 2024 06:03
@jan-janssen jan-janssen merged commit f16e67a into main Dec 20, 2024
27 checks passed
@jan-janssen jan-janssen deleted the flux_log_files branch December 20, 2024 06:04
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.

1 participant