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

feat(package): Add option to output search results as raw logs. #641

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

gibber9809
Copy link
Contributor

@gibber9809 gibber9809 commented Dec 19, 2024

Description

This PR adds the option to output raw logs from the package search scripts instead of the current PATH:MSG syntax as requested in #625. This makes it easier to feed the output of search into tools like jq.

Validation performed

  • validated that the --raw option results in outputting raw logs
  • validated that omitting the --raw option retains same behaviour as prior

Summary by CodeRabbit

  • New Features

    • Introduced a new command-line argument --raw for outputting search results as raw logs.
  • Bug Fixes

    • Improved formatting of help messages for the --begin-time and --end-time arguments.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request modifies the search.py scripts in two different components to introduce a new --raw command-line argument. This enhancement allows users to output search results in a raw format. The changes primarily involve updating function signatures in the native search script to support a raw_output parameter and adding the corresponding CLI argument. The modifications enable more flexible log output options while maintaining the existing core functionality of the search scripts.

Changes

File Change Summary
components/clp-package-utils/clp_package_utils/scripts/native/search.py - Refactored worker_connection_handler into a nested function with raw_output parameter
- Updated do_search and do_search_without_aggregation to support raw_output
- Added --raw CLI argument in main function
components/clp-package-utils/clp_package_utils/scripts/search.py - Added --raw CLI argument
- Updated search_cmd construction to include raw output option
- Minor formatting improvements to help messages

Possibly Related PRs

Suggested Reviewers

  • kirkrodrigues

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.


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.

@gibber9809 gibber9809 linked an issue Dec 19, 2024 that may be closed by this pull request
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

🧹 Nitpick comments (3)
components/clp-package-utils/clp_package_utils/scripts/search.py (1)

125-126: Consider adding a test for the --raw argument handling.

While the command construction looks correct, we should ensure proper testing coverage for this new feature.

Would you like me to help create a test case for the --raw argument handling?

components/clp-package-utils/clp_package_utils/scripts/native/search.py (2)

86-110: Excellent refactoring of the worker connection handler, eh!

The implementation properly handles raw output formatting through a closure pattern. However, there are a few suggestions for improvement:

  1. Consider adding type hints for better code maintainability
  2. The error handling could be more specific than catching all exceptions

Here's a suggested improvement:

-def get_worker_connection_handler(raw_output: bool):
+def get_worker_connection_handler(raw_output: bool) -> asyncio.Protocol:
     async def worker_connection_handler(reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
         try:
             unpacker = msgpack.Unpacker()
             while True:
                 buf = await reader.read(1024)
                 if b"" == buf:
                     return
                 unpacker.feed(buf)
 
                 for unpacked in unpacker:
                     if raw_output:
                         print(f"{unpacked[1]}", end="")
                     else:
                         print(f"{unpacked[2]}: {unpacked[1]}", end="")
-        except asyncio.CancelledError:
+        except (asyncio.CancelledError, msgpack.UnpackException) as e:
+            logger.error(f"Error processing message: {e}")
             return
         finally:
             writer.close()
 
     return worker_connection_handler

98-104: Consider adding buffering for output performance.

The current implementation prints each message individually, which might not be optimal for performance with large volumes of logs.

Consider buffering the output:

+    buffer = []
+    BUFFER_SIZE = 1000
     for unpacked in unpacker:
         if raw_output:
-            print(f"{unpacked[1]}", end="")
+            buffer.append(f"{unpacked[1]}")
         else:
-            print(f"{unpacked[2]}: {unpacked[1]}", end="")
+            buffer.append(f"{unpacked[2]}: {unpacked[1]}")
+        if len(buffer) >= BUFFER_SIZE:
+            print("".join(buffer), end="")
+            buffer.clear()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 594968a and b54c46e.

📒 Files selected for processing (2)
  • components/clp-package-utils/clp_package_utils/scripts/native/search.py (8 hunks)
  • components/clp-package-utils/clp_package_utils/scripts/search.py (3 hunks)
🔇 Additional comments (5)
components/clp-package-utils/clp_package_utils/scripts/search.py (2)

45-45: Help messages look good, eh!

The help messages for time-related arguments are now properly formatted.

Also applies to: 50-50


64-66: LGTM! The new --raw argument is well-defined.

The argument is properly added with appropriate help text and uses the standard store_true action.

components/clp-package-utils/clp_package_utils/scripts/native/search.py (3)

239-239: Help messages look good!

The time-related argument help messages are properly formatted.

Also applies to: 244-244


263-265: LGTM! The --raw argument is consistently defined.

The argument definition matches the wrapper script implementation.


122-122: Function signatures are properly updated.

The raw_output parameter is consistently propagated through all relevant functions.

Let's verify that all functions using raw output are properly updated:

Also applies to: 136-136, 195-195, 207-207, 297-297

✅ Verification successful

Let me gather more context about the usage of raw_output parameter.


Function signatures are properly updated with raw_output parameter

The verification confirms that:

  • raw_output parameter is correctly defined in all relevant function signatures
  • get_worker_connection_handler accepts and uses raw_output
  • do_search_without_aggregation includes raw_output in its parameters
  • The parameter is properly propagated through function calls:
    • do_search calls do_search_without_aggregation with the correct parameters
    • get_worker_connection_handler is called with raw_output in the server setup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all functions properly handle raw_output parameter

# Search for function definitions and their calls
ast-grep --pattern 'def $FUNC($ARGS) { $$$
  $BODY
}'

# Search for any potential missing raw_output parameter
rg -A 2 'def (do_search|do_search_without_aggregation|get_worker_connection_handler)'

Length of output: 1142


Script:

#!/bin/bash
# Search for the full function signatures and their implementations
rg -A 10 'def (do_search|do_search_without_aggregation|get_worker_connection_handler)' components/clp-package-utils/clp_package_utils/scripts/native/search.py

# Search for calls to these functions to verify parameter passing
rg -B 2 -A 2 '(do_search|do_search_without_aggregation|get_worker_connection_handler)\(' components/clp-package-utils/clp_package_utils/scripts/native/search.py

Length of output: 2239

Copy link
Contributor

@wraymo wraymo left a comment

Choose a reason for hiding this comment

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

Looks good to me

@gibber9809 gibber9809 merged commit 38b79b1 into y-scope:main Dec 19, 2024
8 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.

Add option to print raw logs from search results.
2 participants