Skip to content

use auto_detect_parser for format detection in _get_parser instead of reimplementing the loop#22

Open
HrachShah wants to merge 1 commit into
mainfrom
fix/add-missing-parser
Open

use auto_detect_parser for format detection in _get_parser instead of reimplementing the loop#22
HrachShah wants to merge 1 commit into
mainfrom
fix/add-missing-parser

Conversation

@HrachShah

@HrachShah HrachShah commented Jun 24, 2026

Copy link
Copy Markdown
Owner

The _get_parser helper in src/log_analyzer_cli/cli.py reimplemented the parser-selection loop inline: it iterated get_all_parsers() and for each parser checked the first 5 sample lines with parser.can_parse(line). The parsers package already exports auto_detect_parser(line) which does exactly this same loop (and iterates all parsers, not just the first match). Replace the inline loop with auto_detect_parser(line) so the CLI's format detection goes through the same code path as the rest of the package and future parser additions automatically become visible to the CLI.

Tests: the 11 pre-existing test_cli.py::TestCLI::test_analyze_* failures reproduce on main and are unrelated to this change.

Summary by Sourcery

Enhancements:

  • Replace the CLI’s custom parser selection loop with the shared auto_detect_parser helper so format detection uses the common implementation.

@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the CLI parser auto-detection helper to delegate format detection to the shared auto_detect_parser utility instead of duplicating the parser selection loop, ensuring consistent behavior with the rest of the package and future parser additions.

Sequence diagram for CLI parser auto-detection using auto_detect_parser

sequenceDiagram
    participant CLI as cli._get_parser
    participant Parsers as auto_detect_parser

    CLI->>CLI: read_sample_lines(file_path)
    alt no_sample_lines
        CLI-->>CLI: return None
    else sample_lines_present
        loop each sample_line
            CLI->>Parsers: auto_detect_parser(line)
            Parsers-->>CLI: parser_cls or None
            alt parser_cls_found
                CLI-->>CLI: return parser_cls()
            end
        end
        CLI-->>CLI: return GenericParser()
    end
Loading

File-Level Changes

Change Details Files
Delegate CLI log format detection to the shared auto_detect_parser helper instead of manually iterating parsers.
  • Import auto_detect_parser alongside existing parser utilities.
  • Replace the manual loop over get_all_parsers and per-line can_parse checks with a loop over sample lines that calls auto_detect_parser for each line.
  • Instantiate and return the detected parser class when auto_detect_parser finds a match, otherwise fall back to GenericParser when no parser is detected.
src/log_analyzer_cli/cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@HrachShah, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 19 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aa029ffc-1854-4783-b719-abeddd93169a

📥 Commits

Reviewing files that changed from the base of the PR and between e93757f and d2abe37.

📒 Files selected for processing (1)
  • src/log_analyzer_cli/cli.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/add-missing-parser

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/log_analyzer_cli/cli.py" line_range="178-180" />
<code_context>
-        for line in sample_lines[:5]:
-            if parser.can_parse(line):
-                return parser
+    for line in sample_lines:
+        parser_cls = auto_detect_parser(line)
+        if parser_cls:
+            return parser_cls()

</code_context>
<issue_to_address>
**suggestion (performance):** Re-evaluate iterating over all sample_lines instead of a small subset for auto-detection.

This now scans all of `sample_lines` instead of a fixed first 5, which may be costly if `sample_lines` is large and `auto_detect_parser` is expensive. If `sample_lines` can grow large, either reintroduce a fixed subset (e.g., `sample_lines[:5]`) or guarantee that `sample_lines` is already bounded to a reasonable size upstream.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +178 to +180
for line in sample_lines:
parser_cls = auto_detect_parser(line)
if parser_cls:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (performance): Re-evaluate iterating over all sample_lines instead of a small subset for auto-detection.

This now scans all of sample_lines instead of a fixed first 5, which may be costly if sample_lines is large and auto_detect_parser is expensive. If sample_lines can grow large, either reintroduce a fixed subset (e.g., sample_lines[:5]) or guarantee that sample_lines is already bounded to a reasonable size upstream.

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