Skip to content

fix: fix several check error introduced by old code #565

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mainred
Copy link
Collaborator

@mainred mainred commented Jun 25, 2025

These check failures are annoying. They only appear only when there's new check errors in the code, which brings extra effort to distinguish which checks are really brought the new code.

holmes/plugins/toolsets/service_discovery.py:27: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
holmes/plugins/toolsets/service_discovery.py:32: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
holmes/plugins/toolsets/prometheus/prometheus.py:548: error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes  [str-bytes-safe]
holmes/plugins/toolsets/prometheus/prometheus.py:694: error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes  [str-bytes-safe]
holmes/plugins/toolsets/grafana/loki_api.py:51: error: Argument "params" to "get" has incompatible type "dict[str, object]"; expected "SupportsItems[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | Iterable[tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None]] | str | bytes | None"  [arg-type]
holmes/plugins/sources/pagerduty/__init__.py:130: error: Item "None" of "Response | None" has no attribute "text"  [union-attr]
holmes/plugins/sources/opsgenie/__init__.py:32: error: Argument "params" to "get" has incompatible type "dict[str, object]"; expected "SupportsItems[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | Iterable[tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None]] | str | bytes | None"  [arg-type]
holmes/plugins/sources/prometheus/plugin.py:73: error: Argument 1 to "HTTPBasicAuth" has incompatible type "str | None"; expected "bytes | str"  [arg-type]
holmes/plugins/sources/prometheus/plugin.py:73: error: Argument 2 to "HTTPBasicAuth" has incompatible type "str | None"; expected "bytes | str"  [arg-type]

Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Walkthrough

The changes primarily involve reorganizing import statements for clarity and adding # type: ignore comments to suppress type checking warnings. Minor error handling improvements were made to prevent potential attribute errors, and error message formatting was refined for consistency. No changes were made to the signatures or logic of public entities.

Changes

File(s) Change Summary
holmes/plugins/sources/opsgenie/init.py Reorganized and expanded import statements; explicitly typed params in fetch_issues method.
holmes/plugins/sources/pagerduty/init.py Improved error handling in write_back_result to avoid attribute errors when logging request exceptions.
holmes/plugins/sources/prometheus/plugin.py Adjusted import order; added # type: ignore to HTTPBasicAuth instantiation for type checker suppression.
holmes/plugins/toolsets/grafana/loki_api.py Moved requests import; added # type: ignore to params in requests.get call.
holmes/plugins/toolsets/prometheus/prometheus.py Changed error message formatting to convert response.content to string in _invoke methods.
holmes/plugins/toolsets/service_discovery.py Reordered Kubernetes client imports; added # type: ignore to service listing call.

Sequence Diagram(s)

No sequence diagram generated as the changes are limited to import reordering, type annotations, and minor error handling adjustments without significant control flow modifications.


📜 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 6ec537c and e8aab07.

📒 Files selected for processing (6)
  • holmes/plugins/sources/opsgenie/__init__.py (2 hunks)
  • holmes/plugins/sources/pagerduty/__init__.py (1 hunks)
  • holmes/plugins/sources/prometheus/plugin.py (2 hunks)
  • holmes/plugins/toolsets/grafana/loki_api.py (2 hunks)
  • holmes/plugins/toolsets/prometheus/prometheus.py (2 hunks)
  • holmes/plugins/toolsets/service_discovery.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (3.12)
  • GitHub Check: build (3.10)
  • GitHub Check: build (3.11)
  • GitHub Check: llm_evals
🔇 Additional comments (13)
holmes/plugins/toolsets/grafana/loki_api.py (2)

2-4: LGTM: Import reordering improves organization.

The import reorganization follows good practices by grouping imports (stdlib, third-party, local) and the # type: ignore comment on the requests import is appropriate for suppressing common typing issues with the requests library.


52-52: Appropriate type ignore for requests params.

The # type: ignore comment correctly suppresses type checking warnings for the params argument. The requests library has complex typing for the params parameter that can cause false positives with mypy.

holmes/plugins/toolsets/service_discovery.py (2)

4-8: LGTM: Import reordering and type ignores for Kubernetes client.

The import reorganization improves code organization, and the # type: ignore comments are appropriate for the Kubernetes Python client library, which has known typing issues and incomplete type annotations.


28-28: Appropriate type ignore for Kubernetes API call.

The # type: ignore comment correctly suppresses type checking warnings for the Kubernetes client API call. The kubernetes client library has known typing issues with their API methods.

holmes/plugins/sources/prometheus/plugin.py (2)

10-10: LGTM: Minor import reordering.

The import reordering maintains good organization and doesn't affect functionality.


73-73: Appropriate type ignore for HTTPBasicAuth.

The # type: ignore comment correctly suppresses type checking warnings. Even though self.username and self.password are typed as Optional[str], the preceding conditional check on line 72 ensures they are not None when passed to HTTPBasicAuth.

holmes/plugins/sources/pagerduty/__init__.py (1)

129-135: Excellent defensive programming improvement.

The error handling now safely checks if e.response is not None before accessing e.response.text. This prevents potential AttributeError exceptions since requests.RequestException can have a None response attribute in cases like connection timeouts or DNS failures.

holmes/plugins/toolsets/prometheus/prometheus.py (2)

548-548: Good fix for byte string handling in error messages.

Converting response.content to string explicitly with str() prevents issues with byte strings in formatted strings and ensures proper error message formatting.


694-694: Consistent error message improvement.

Same improvement as line 548 - converting response.content to string ensures proper formatting in error messages and avoids byte string representation issues.

holmes/plugins/sources/opsgenie/__init__.py (4)

2-3: LGTM! Good addition of typing imports.

Adding explicit typing imports improves static type checking and follows Python typing best practices.


4-5: Appropriate use of type ignore comments.

The # type: ignore comments are correctly applied to suppress type checking warnings for third-party libraries that may not have proper type stubs or have type checking issues.


7-7: Good import organization.

Moving the Issue import to group it with other local imports improves code organization and readability.


31-31: Excellent fix for the requests params type issue.

The explicit type annotation Dict[str, Union[int, str]] correctly addresses the type checking error mentioned in the PR objectives where the params argument to HTTP request methods was receiving incompatible dictionary types. This ensures the params are properly typed for the requests library.

✨ 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.

Copy link
Contributor

Results of HolmesGPT evals

Test suite Test case Status
ask_holmes 01_how_many_pods ⚠️
ask_holmes 02_what_is_wrong_with_pod
ask_holmes 03_what_is_the_command_to_port_forward
ask_holmes 04_related_k8s_events
ask_holmes 05_image_version
ask_holmes 06_explain_issue
ask_holmes 07_high_latency
ask_holmes 08_sock_shop_frontend ⚠️
ask_holmes 09_crashpod
ask_holmes 10_image_pull_backoff
ask_holmes 11_init_containers
ask_holmes 12_job_crashing
ask_holmes 13_pending_node_selector
ask_holmes 14_pending_resources
ask_holmes 15_failed_readiness_probe
ask_holmes 16_failed_no_toolset_found
ask_holmes 17_oom_kill
ask_holmes 18_crash_looping_v2
ask_holmes 19_detect_missing_app_details
ask_holmes 20_long_log_file_search
ask_holmes 21_job_fail_curl_no_svc_account ⚠️
ask_holmes 22_high_latency_dbi_down ⚠️
ask_holmes 23_app_error_in_current_logs
ask_holmes 24_misconfigured_pvc
ask_holmes 25_misconfigured_ingress_class ⚠️
ask_holmes 26_multi_container_logs ⚠️
ask_holmes 27_permissions_error_no_helm_tools
ask_holmes 28_permissions_error_helm_tools_enabled
ask_holmes 29_events_from_alert_manager
ask_holmes 30_basic_promql_graph_cluster_memory
ask_holmes 31_basic_promql_graph_pod_memory
ask_holmes 32_basic_promql_graph_pod_cpu
ask_holmes 33_http_latency_graph
ask_holmes 34_memory_graph
ask_holmes 35_tempo
ask_holmes 36_argocd_find_resource
ask_holmes 37_argocd_wrong_namespace ⚠️
ask_holmes 38_rabbitmq_split_head
ask_holmes 39_failed_toolset
ask_holmes 40_disabled_toolset
ask_holmes 41_setup_argo
ask_holmes 42_dns_issues_result_all_tools ⚠️
ask_holmes 42_dns_issues_result_new_tools ⚠️
ask_holmes 42_dns_issues_result_old_tools ⚠️
ask_holmes 42_dns_issues_steps_new_all_tools ⚠️
ask_holmes 42_dns_issues_steps_new_tools ⚠️
ask_holmes 42_dns_issues_steps_old_tools ⚠️
ask_holmes 43_current_datetime_from_prompt
ask_holmes 43_slack_deployment_logs
ask_holmes 44_slack_statefulset_logs
ask_holmes 45_fetch_deployment_logs_simple
ask_holmes 46_job_crashing_no_longer_exists ⚠️
ask_holmes 47_truncated_logs_context_window ⚠️
ask_holmes 48_logs_since_thursday ⚠️
ask_holmes 49_logs_since_last_week
ask_holmes 50_logs_since_specific_date ⚠️
ask_holmes 51_logs_summarize_errors ⚠️
ask_holmes 52_logs_login_issues ⚠️
ask_holmes 53_logs_find_term
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 ⚠️

Legend

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

@@ -70,7 +70,7 @@ def __fetch_issues_from_api(self) -> List[PrometheusAlert]:
logging.info(f"Filtering alerts by {self.label_filter}")

if self.username is not None or self.password is not None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we check both var are not None? so that we don't have to add type ignore but not sure if an empty password and a valid name work.

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