Skip to content

chore: move utils functions out of main.py - #672

Merged
aantn merged 2 commits into
masterfrom
create-console-package
Jul 22, 2025
Merged

aantn merged 2 commits into
masterfrom
create-console-package

Conversation

@mainred

@mainred mainred commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

This PR moves the utils functions out of main.go to make utils function importal.

@mainred
mainred marked this pull request as ready for review July 22, 2025 05:13
@coderabbitai

coderabbitai Bot commented Jul 22, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes refactor logging, result handling, and system prompt help text out of the main CLI module into dedicated utility modules. The main CLI file now imports these functionalities from holmes.utils.console, removing its local implementations. No changes are made to the CLI commands' logic or control flow.

Changes

File(s) Change Summary
holmes/main.py Removed local logging, result handling, and help text; now imports init_logging, handle_result, and system_prompt_help from utility modules.
holmes/utils/console/logging.py New module: Adds Verbosity enum, cli_flags_to_verbosity, suppress_noisy_logs, and init_logging functions for logging management.
holmes/utils/console/result.py New module: Adds handle_result function for CLI and Slack result output handling.
holmes/utils/console/consts.py New module: Adds system_prompt_help constant with system prompt usage help text.

Estimated code review effort

2 (~15 minutes)

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
holmes/utils/console/logging.py (2)

12-12: Consider removing or implementing the TODO comment.

The LOG_QUERIES verbosity level is marked as unused. Consider either implementing its functionality or removing it if it's not needed.


61-76: Simplify logging level configuration for VERBOSE mode.

The current implementation sets the level to INFO and then immediately overrides it to DEBUG, which is redundant.

Consider this cleaner approach:

    elif verbosity == Verbosity.VERBOSE:
        logging.basicConfig(
-            level=logging.INFO,
+            level=logging.DEBUG,
            format="%(message)s",
            handlers=[
                RichHandler(
                    show_level=False,
                    markup=True,
                    show_time=False,
                    show_path=False,
                    console=Console(width=None),
                )
            ],
        )
-        logging.getLogger().setLevel(logging.DEBUG)
        suppress_noisy_logs()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fcb521e and 46fd4ee.

📒 Files selected for processing (4)
  • holmes/main.py (1 hunks)
  • holmes/utils/console/consts.py (1 hunks)
  • holmes/utils/console/logging.py (1 hunks)
  • holmes/utils/console/result.py (1 hunks)
🧠 Learnings (2)
📓 Common learnings
Learnt from: nherment
PR: robusta-dev/holmesgpt#610
File: .github/workflows/llm-evaluation.yaml:39-42
Timestamp: 2025-07-08T08:45:41.069Z
Learning: When suggesting improvements to environment variable handling in robusta-dev/holmesgpt, check first if validation logic already exists rather than reimplementing it.
holmes/main.py (2)

Learnt from: nherment
PR: #436
File: tests/llm/utils/mock_utils.py:240-249
Timestamp: 2025-06-05T12:23:27.634Z
Learning: The holmesgpt project uses Python >= 3.10 and prefers modern type hint syntax like list[str], dict[str, int] over importing equivalent types from the typing module like List[str], Dict[str, int].

Learnt from: nherment
PR: #535
File: holmes/plugins/toolsets/bash/bash_toolset.py:207-209
Timestamp: 2025-06-24T05:51:04.543Z
Learning: The init_config method in toolsets should be idempotent - safely callable multiple times without errors. self.config should maintain consistent typing (not alternate between dict and config object types) throughout the object lifecycle.

🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: nherment
PR: robusta-dev/holmesgpt#610
File: .github/workflows/llm-evaluation.yaml:39-42
Timestamp: 2025-07-08T08:45:41.069Z
Learning: When suggesting improvements to environment variable handling in robusta-dev/holmesgpt, check first if validation logic already exists rather than reimplementing it.
holmes/main.py (2)

Learnt from: nherment
PR: #436
File: tests/llm/utils/mock_utils.py:240-249
Timestamp: 2025-06-05T12:23:27.634Z
Learning: The holmesgpt project uses Python >= 3.10 and prefers modern type hint syntax like list[str], dict[str, int] over importing equivalent types from the typing module like List[str], Dict[str, int].

Learnt from: nherment
PR: #535
File: holmes/plugins/toolsets/bash/bash_toolset.py:207-209
Timestamp: 2025-06-24T05:51:04.543Z
Learning: The init_config method in toolsets should be idempotent - safely callable multiple times without errors. self.config should maintain consistent typing (not alternate between dict and config object types) throughout the object lifecycle.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Pre-commit checks
  • GitHub Check: llm_evals
  • GitHub Check: build (3.11)
  • GitHub Check: build (3.12)
  • GitHub Check: build (3.10)
🔇 Additional comments (5)
holmes/utils/console/consts.py (1)

1-2: LGTM! Clean extraction of help text constant.

The system prompt help text is well-structured and clearly explains the different ways to specify system prompts. Moving this to a dedicated constants module improves code organization.

holmes/utils/console/result.py (1)

11-37: LGTM! Well-structured result handling function.

The function correctly handles both CLI and Slack output destinations with proper formatting. The use of markup=False for tool call output is a good practice to prevent interpretation of arbitrary text as Rich markup.

holmes/utils/console/logging.py (1)

28-41: Excellent noise reduction strategy.

The suppress_noisy_logs function properly suppresses verbose logging from third-party libraries, which will improve the user experience by reducing log noise.

holmes/main.py (2)

43-45: LGTM! Clean import of extracted utility functions.

The imports correctly reference the new utility modules that contain the refactored functionality.


221-221: All extracted utility functions are used consistently

All occurrences of init_logging, handle_result, and system_prompt_help in holmes/main.py are imported and invoked correctly, with no remaining local definitions detected:

  • init_logging calls at lines 221, 390, 470, 524, 618, 714, 800, 886, 942, 957
  • handle_result calls at lines 332, 445
  • system_prompt_help references at multiple help entries
  • No def init_logging, def handle_result, def cli_flags_to_verbosity, or def suppress_noisy_logs in this file

LGTM.

@aantn

aantn commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

@mainred can you explain? Why wasn't it importable before?

@mainred

mainred commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator Author

Hey @aantn, what we want to achieve in az cli is like in the following PR
Azure/azure-cli-extensions#8990
We want to re-implement the ask function, while keep at most utils function inside the holmes library as possible.

@aantn
aantn enabled auto-merge (squash) July 22, 2025 08:10
@aantn

aantn commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

Hey @aantn, what we want to achieve in az cli is like in the following PR Azure/azure-cli-extensions#8990 We want to re-implement the ask function, while keep at most utils function inside the holmes library as possible.

Got it, thanks! Approved.

@aantn
aantn merged commit 3a36093 into master Jul 22, 2025
@aantn
aantn deleted the create-console-package branch July 22, 2025 08:18
@github-actions

Copy link
Copy Markdown
Contributor

Results of HolmesGPT evals

  • ask_holmes: 44/66 test cases were successful, 0 regressions
  • investigate: 14/16 test cases were successful, 0 regressions
Test suite Test case Status
ask 01: how_many_pods ✅
ask 02: what_is_wrong_with_pod ✅
ask 03: what_is_the_command_to_port_forward ✅
ask 04: related_k8s_events ✅
ask 05: image_version ✅
ask 06: explain_issue ✅
ask 07: high_latency ✅
ask 08: sock_shop_frontend ⚠️
ask 09: crashpod ✅
ask 10: image_pull_backoff ✅
ask 11: init_containers ✅
ask 12: job_crashing ✅
ask 13: pending_node_selector ✅
ask 14: pending_resources ✅
ask 15: failed_readiness_probe ✅
ask 16: failed_no_toolset_found ✅
ask 17: oom_kill ✅
ask 18: crash_looping_v2 ✅
ask 19: detect_missing_app_details ✅
ask 20: long_log_file_search ✅
ask 21: job_fail_curl_no_svc_account ⚠️
ask 22: high_latency_dbi_down ⚠️
ask 23: app_error_in_current_logs ✅
ask 24: misconfigured_pvc ✅
ask 25: misconfigured_ingress_class ⚠️
ask 26: multi_container_logs ✅
ask 27: permissions_error_no_helm_tools ✅
ask 28: permissions_error_helm_tools_enabled ⚠️
ask 29: events_from_alert_manager ✅
ask 30: basic_promql_graph_cluster_memory ✅
ask 31: basic_promql_graph_pod_memory ✅
ask 32: basic_promql_graph_pod_cpu ✅
ask 33: http_latency_graph ✅
ask 34: memory_graph ✅
ask 35: tempo ✅
ask 36: argocd_find_resource ✅
ask 37: argocd_wrong_namespace ⚠️
ask 38: rabbitmq_split_head ✅
ask 39: failed_toolset ✅
ask 40: disabled_toolset ✅
ask 41: setup_argo ✅
ask 42: dns_issues_result_all_tools ⚠️
ask 42: dns_issues_result_new_tools ⚠️
ask 42: dns_issues_result_old_tools ⚠️
ask 42: dns_issues_steps_new_all_tools ⚠️
ask 42: dns_issues_steps_new_tools ⚠️
ask 42: dns_issues_steps_old_tools ⚠️
ask 43: current_datetime_from_prompt ✅
ask 43: slack_deployment_logs ✅
ask 44: slack_statefulset_logs ⚠️
ask 45: fetch_deployment_logs_simple ✅
ask 46: job_crashing_no_longer_exists ⚠️
ask 47: truncated_logs_context_window ⚠️
ask 48: logs_since_thursday ⚠️
ask 49: logs_since_last_week ⚠️
ask 50: logs_since_specific_date ⚠️
ask 51: logs_summarize_errors ✅
ask 52: logs_login_issues ⚠️
ask 53: logs_find_term ✅
ask 54: not_truncated_when_getting_pods ✅
ask 55: kafka_runbook ⚠️
ask 56: kafka_runbook_no_tool ⚠️
ask 58: counting_pods_by_status ⚠️
ask 59: label_based_counting ✅
ask 60: time_based_filtering ✅
ask 61: exact_match_counting ✅
investigate 01: oom_kill ✅
investigate 02: crashloop_backoff ✅
investigate 03: cpu_throttling ✅
investigate 04: image_pull_backoff ✅
investigate 05: crashpod ✅
investigate 06: job_failure ✅
investigate 07: job_syntax_error ✅
investigate 08: memory_pressure ✅
investigate 09: high_latency ✅
investigate 10: KubeDeploymentReplicasMismatch ✅
investigate 11: KubePodCrashLooping ✅
investigate 12: KubePodNotReady ✅
investigate 13: Watchdog ✅
investigate 14: tempo ✅
investigate 15: dns_resolution ⚠️
investigate 16: dns_resolution_no_tool ⚠️

Legend

  • ✅ the test was successful
  • ⚠️ the test failed but is known to be flaky or known to fail
  • ❌ the test failed and should be fixed before merging the PR

@pavangudiwada pavangudiwada changed the title chore: move utils functions out of main.go chore: move utils functions out of main.py Jul 22, 2025
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.

2 participants