Skip to content

ROB-2323 loki free logql tool - #1106

Merged
RoiGlinik merged 9 commits into
masterfrom
ROB-2323-loki-free-logql-tool
Nov 6, 2025
Merged

RoiGlinik merged 9 commits into
masterfrom
ROB-2323-loki-free-logql-tool

Conversation

@RoiGlinik

Copy link
Copy Markdown
Collaborator

added some minimal instructions

@RoiGlinik
RoiGlinik requested a review from Avi-Robusta November 5, 2025 12:25
@coderabbitai

coderabbitai Bot commented Nov 5, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Moves Grafana Loki functionality into a nested grafana/loki package, adds a LokiQuery tool and instructions, updates imports to the new module path, and deletes the previous flat grafana/toolset_grafana_loki implementation and some related tests.

Changes

Cohort / File(s) Summary
Package import update
holmes/plugins/toolsets/__init__.py
Updated import path for GrafanaLokiToolset to grafana.loki.toolset_grafana_loki.
New Loki toolset & query implementation
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
Added GrafanaLokiToolset and LokiQuery tool. Supports parameters query, start, end, limit; converts timestamps to RFC3339, reads Grafana config (base URL, API key, headers), executes Loki LogQL queries, and returns structured results (SUCCESS / NO_DATA / ERROR) with diagnostic URL on error.
Documentation / instructions
holmes/plugins/toolsets/grafana/loki/instructions.jinja2
Added Loki usage instructions covering log retention for deleted K8s objects, search strategies, and an example of Loki labels for Kubernetes logs.
Removed old implementation
holmes/plugins/toolsets/grafana/toolset_grafana_loki.py
Deleted previous flat-file Grafana Loki toolset (config models, GrafanaLokiToolset, fetch_pod_logs, label/config classes, and related logic).
Tests updated / reduced
tests/plugins/toolsets/grafana/test_grafana_loki.py
Updated imports to new module path and to GrafanaConfig, added connectivity-based skip, and removed several query tests (kept health check).

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Toolset as GrafanaLokiToolset
  participant LokiTool as LokiQuery
  participant GrafanaAPI as Grafana/Loki API

  Note over Toolset,LokiTool: New flow — Toolset provides config and wiring for LokiQuery
  User->>Toolset: invoke Loki query (params)
  Toolset->>LokiTool: forward (query, start, end, limit)
  LokiTool->>GrafanaAPI: HTTP request (base_url + api_key) with LogQL & RFC3339 timestamps
  GrafanaAPI-->>LokiTool: 200 + data / 200 empty / error
  alt data returned
    LokiTool-->>Toolset: StructuredToolResult(SUCCESS, JSON data)
  else no data
    LokiTool-->>Toolset: StructuredToolResult(NO_DATA)
  else error
    LokiTool-->>Toolset: StructuredToolResult(ERROR, message, diagnostic_url)
  end
  Toolset-->>User: return StructuredToolResult
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Focus areas:
    • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py — timestamp handling, request construction, error messages, and diagnostic URL.
    • Removal of holmes/plugins/toolsets/grafana/toolset_grafana_loki.py — verify no remaining references.
    • Tests in tests/plugins/toolsets/grafana/test_grafana_loki.py — fixture updates and connectivity skip behavior.
    • holmes/plugins/toolsets/__init__.py — confirm exports and registration after import path change.

Possibly related PRs

Suggested reviewers

  • aantn

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description 'added some minimal instructions' is vague and generic, providing no meaningful information about the substantial changes made to the codebase. Expand the description to clarify the main changes: refactoring the Grafana Loki toolset into a new module structure, removing the old Pod Logging Toolset implementation, and introducing new LogQL query capabilities.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'ROB-2323 loki free logql tool' directly relates to the main change: introducing a Grafana Loki toolset with LogQL query functionality, restructured into a new module path.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ROB-2323-loki-free-logql-tool

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 and usage tips.

@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: 4

🧹 Nitpick comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

84-107: Consider using ClassVar for class-level parameters dict.

The parameters dictionary is shared across all instances and should be annotated with typing.ClassVar to clarify intent and satisfy type checkers.

Apply this diff:

+from typing import Any, cast, Dict, ClassVar
-from typing import Any, cast, Dict
 
 # ... existing code ...
 
 class LokiQuery(Tool):
     toolset: GrafanaLokiToolset
     name: str = "grafana_loki_query"
     description: str = "Run a query against Grafana Loki using LogQL query language."
-    parameters: Dict[str, ToolParameter] = {
+    parameters: ClassVar[Dict[str, ToolParameter]] = {
         "query": ToolParameter(
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bf6393 and 7312b53.

📒 Files selected for processing (5)
  • holmes/plugins/toolsets/__init__.py (1 hunks)
  • holmes/plugins/toolsets/grafana/loki/instructions.jinja2 (1 hunks)
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1 hunks)
  • holmes/plugins/toolsets/grafana/toolset_grafana_loki.py (0 hunks)
  • tests/plugins/toolsets/grafana/test_grafana_loki.py (1 hunks)
💤 Files with no reviewable changes (1)
  • holmes/plugins/toolsets/grafana/toolset_grafana_loki.py
🧰 Additional context used
📓 Path-based instructions (4)
holmes/plugins/toolsets/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/

Files:

  • holmes/plugins/toolsets/grafana/loki/instructions.jinja2
  • holmes/plugins/toolsets/__init__.py
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Use Ruff for formatting and linting (configured in pyproject.toml) for all Python code
Type hints are required; code should pass mypy (configured in pyproject.toml)
ALWAYS place Python imports at the top of the file, not inside functions or methods

Files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
  • holmes/plugins/toolsets/__init__.py
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Only use pytest markers that are defined in pyproject.toml; never introduce undefined markers/tags

Files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Test files should mirror the source structure under tests/

Files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: robusta-dev/holmesgpt PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-05T13:01:12.288Z
Learning: Applies to holmes/plugins/toolsets/**/* : Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/
📚 Learning: 2025-05-15T05:13:43.169Z
Learnt from: nherment
Repo: robusta-dev/holmesgpt PR: 408
File: holmes/plugins/toolsets/kubernetes_logs.py:90-97
Timestamp: 2025-05-15T05:13:43.169Z
Learning: In the Kubernetes logs toolset for Holmes, both current and previous logs are intentionally fetched and combined for each pod, even though this requires more API calls. This design ensures all logs are captured even when pods restart but retain their name, providing complete diagnostic information.

Applied to files:

  • holmes/plugins/toolsets/grafana/loki/instructions.jinja2
📚 Learning: 2025-10-01T06:01:13.215Z
Learnt from: mainred
Repo: robusta-dev/holmesgpt PR: 992
File: holmes/plugins/toolsets/__init__.py:106-109
Timestamp: 2025-10-01T06:01:13.215Z
Learning: In the holmesgpt repository (Python), function-scoped imports are acceptable when dealing with optional dependencies that may be missing on some platforms. For example, PrometheusToolset is imported inside the load_python_toolsets function to avoid import-time failures when DISABLE_PROMETHEUS_TOOLSET is true.

Applied to files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
  • holmes/plugins/toolsets/__init__.py
📚 Learning: 2025-10-05T13:01:12.288Z
Learnt from: CR
Repo: robusta-dev/holmesgpt PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-05T13:01:12.288Z
Learning: Applies to holmes/plugins/toolsets/**/* : Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/

Applied to files:

  • holmes/plugins/toolsets/__init__.py
🧬 Code graph analysis (3)
tests/plugins/toolsets/grafana/test_grafana_loki.py (2)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)
  • GrafanaLokiConfig (39-40)
holmes/plugins/toolsets/logging_utils/logging_api.py (1)
  • FetchPodLogsParams (51-66)
holmes/plugins/toolsets/__init__.py (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)
  • GrafanaLokiToolset (43-77)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (5)
holmes/core/tools.py (8)
  • CallablePrerequisite (521-522)
  • Tool (173-365)
  • ToolInvokeContext (164-170)
  • ToolParameter (155-161)
  • Toolset (534-778)
  • StructuredToolResult (79-103)
  • StructuredToolResultStatus (52-76)
  • _load_llm_instructions (763-768)
holmes/plugins/toolsets/grafana/common.py (2)
  • GrafanaConfig (9-22)
  • get_base_url (52-56)
holmes/plugins/toolsets/grafana/grafana_api.py (1)
  • grafana_health_check (20-42)
holmes/plugins/toolsets/utils.py (3)
  • process_timestamps_to_rfc3339 (75-87)
  • standard_start_datetime_tool_param_description (10-11)
  • toolset_name_for_one_liner (232-236)
holmes/plugins/toolsets/grafana/loki_api.py (1)
  • execute_loki_query (37-62)
🪛 Ruff (0.14.3)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py

84-107: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


112-112: Unused method argument: context

(ARG002)


141-141: Do not catch blind exception: Exception

(BLE001)

⏰ 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). (3)
  • GitHub Check: llm_evals
  • GitHub Check: Pre-commit checks
  • GitHub Check: build
🔇 Additional comments (3)
holmes/plugins/toolsets/__init__.py (1)

37-37: LGTM! Import path correctly updated.

The import path change aligns with the toolset relocation to holmes/plugins/toolsets/grafana/loki/ and follows the coding guideline for toolset structure.

tests/plugins/toolsets/grafana/test_grafana_loki.py (1)

7-11: LGTM! Import paths correctly updated.

The import paths have been properly updated to reflect the new module location at holmes.plugins.toolsets.grafana.loki.toolset_grafana_loki.

holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

112-147: LGTM! Query execution logic is well-structured.

The implementation correctly processes timestamps, executes the Loki query, and returns appropriate structured results with proper error handling.

Comment thread holmes/plugins/toolsets/grafana/loki/instructions.jinja2 Outdated
Comment thread holmes/plugins/toolsets/grafana/loki/instructions.jinja2 Outdated
Comment thread holmes/plugins/toolsets/grafana/loki/instructions.jinja2 Outdated
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py Outdated
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py Outdated
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py Outdated

@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: 1

♻️ Duplicate comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

47-47: Fix typo in description.

The word "quereis" should be "queries" as previously noted.

🧹 Nitpick comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

84-107: Consider adding ClassVar annotation for class-level dict.

The parameters dictionary is a class attribute that's shared across instances. While the current implementation works, adding ClassVar annotation would make the intent clearer and satisfy static analysis.

Apply this diff:

+from typing import Any, cast, ClassVar, Dict
-from typing import Any, cast, Dict

 class LokiQuery(Tool):
     toolset: GrafanaLokiToolset
     name: str = "grafana_loki_query"
     description: str = "Run a query against Grafana Loki using LogQL query language."
-    parameters: Dict[str, ToolParameter] = {
+    parameters: ClassVar[Dict[str, ToolParameter]] = {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7312b53 and ef5c490.

📒 Files selected for processing (2)
  • holmes/plugins/toolsets/grafana/loki/instructions.jinja2 (1 hunks)
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • holmes/plugins/toolsets/grafana/loki/instructions.jinja2
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Use Ruff for formatting and linting (configured in pyproject.toml) for all Python code
Type hints are required; code should pass mypy (configured in pyproject.toml)
ALWAYS place Python imports at the top of the file, not inside functions or methods

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
holmes/plugins/toolsets/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: robusta-dev/holmesgpt PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-05T13:01:12.288Z
Learning: Applies to holmes/plugins/toolsets/**/* : Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/
🧬 Code graph analysis (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (5)
holmes/core/tools.py (6)
  • CallablePrerequisite (521-522)
  • Tool (173-365)
  • ToolInvokeContext (164-170)
  • ToolParameter (155-161)
  • StructuredToolResult (79-103)
  • StructuredToolResultStatus (52-76)
holmes/plugins/toolsets/grafana/common.py (2)
  • GrafanaConfig (9-22)
  • get_base_url (52-56)
holmes/plugins/toolsets/grafana/grafana_api.py (1)
  • grafana_health_check (20-42)
holmes/plugins/toolsets/utils.py (3)
  • process_timestamps_to_rfc3339 (75-87)
  • standard_start_datetime_tool_param_description (10-11)
  • toolset_name_for_one_liner (232-236)
holmes/plugins/toolsets/grafana/loki_api.py (1)
  • execute_loki_query (37-62)
🪛 Ruff (0.14.3)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py

84-107: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


112-112: Unused method argument: context

(ARG002)


141-141: Do not catch blind exception: Exception

(BLE001)

⏰ 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). (3)
  • GitHub Check: llm_evals
  • GitHub Check: Pre-commit checks
  • GitHub Check: build
🔇 Additional comments (2)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (2)

75-77: Respond to earlier question: Yes, this property is used.

The grafana_config property is accessed on line 119 within the LokiQuery._invoke method: config = self.toolset.grafana_config. This property provides type-safe access to the properly typed config.


34-41: Verify whether GrafanaLokiLabelsConfig is used or should be removed.

The labels field defined on line 40 is not accessed anywhere in the loki toolset implementation. While similar label configurations are actively used in other toolsets (datadog, opensearch, coralogix) to specify field names in queries, there is no evidence of this field being used within the loki toolset.

Determine whether this configuration should be:

  • Removed as unused code, or
  • Retained and integrated into the Loki query construction (if LogQL query building needs customizable field names)

Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py Outdated

@Avi-Robusta Avi-Robusta left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

small changes needed, ping me after and ill re-approve

@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: 1

♻️ Duplicate comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

82-97: Reject missing query instead of running a fake fallback.

query is marked required, yet the code silently swaps in {query="no_query_fallback"} if it’s absent. That hides real user errors and can return misleading “no data” responses. Validate the parameter and return an explicit error when it’s missing or blank, then pass the validated value into execute_loki_query.

🧹 Nitpick comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

52-75: Make parameters a ClassVar.

As written, Pydantic treats parameters as a mutable model field; any runtime mutation would bleed across instances and triggers RUF012. Annotate it as a ClassVar (and keep the dict literal) so it’s excluded from instance state.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef5c490 and a04c1c9.

📒 Files selected for processing (2)
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1 hunks)
  • tests/plugins/toolsets/grafana/test_grafana_loki.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Use Ruff for formatting and linting (configured in pyproject.toml) for all Python code
Type hints are required; code should pass mypy (configured in pyproject.toml)
ALWAYS place Python imports at the top of the file, not inside functions or methods

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
  • tests/plugins/toolsets/grafana/test_grafana_loki.py
holmes/plugins/toolsets/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Only use pytest markers that are defined in pyproject.toml; never introduce undefined markers/tags

Files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Test files should mirror the source structure under tests/

Files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
🧠 Learnings (2)
📚 Learning: 2025-10-05T13:01:12.288Z
Learnt from: CR
Repo: robusta-dev/holmesgpt PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-05T13:01:12.288Z
Learning: Applies to holmes/plugins/toolsets/**/*.{yaml,yml} : All toolsets MUST return detailed error messages from underlying APIs, including the exact query/command, time ranges, parameters/filters, and full API error response; for "no data" responses, specify what was searched and where

Applied to files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
📚 Learning: 2025-10-01T06:01:13.215Z
Learnt from: mainred
Repo: robusta-dev/holmesgpt PR: 992
File: holmes/plugins/toolsets/__init__.py:106-109
Timestamp: 2025-10-01T06:01:13.215Z
Learning: In the holmesgpt repository (Python), function-scoped imports are acceptable when dealing with optional dependencies that may be missing on some platforms. For example, PrometheusToolset is imported inside the load_python_toolsets function to avoid import-time failures when DISABLE_PROMETHEUS_TOOLSET is true.

Applied to files:

  • tests/plugins/toolsets/grafana/test_grafana_loki.py
🧬 Code graph analysis (2)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (5)
holmes/core/tools.py (5)
  • Tool (173-365)
  • ToolInvokeContext (164-170)
  • ToolParameter (155-161)
  • StructuredToolResult (79-103)
  • StructuredToolResultStatus (52-76)
holmes/plugins/toolsets/grafana/common.py (1)
  • get_base_url (52-56)
holmes/plugins/toolsets/grafana/base_grafana_toolset.py (1)
  • BaseGrafanaToolset (11-54)
holmes/plugins/toolsets/utils.py (3)
  • process_timestamps_to_rfc3339 (75-87)
  • standard_start_datetime_tool_param_description (10-11)
  • toolset_name_for_one_liner (232-236)
holmes/plugins/toolsets/grafana/loki_api.py (1)
  • execute_loki_query (37-62)
tests/plugins/toolsets/grafana/test_grafana_loki.py (5)
holmes/core/tools.py (1)
  • ToolsetStatusEnum (137-140)
holmes/plugins/toolsets/grafana/grafana_api.py (1)
  • grafana_health_check (20-42)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)
  • GrafanaLokiToolset (31-45)
tests/plugins/toolsets/grafana/conftest.py (1)
  • check_grafana_connectivity (5-30)
holmes/plugins/toolsets/grafana/common.py (1)
  • GrafanaConfig (9-22)
🪛 Ruff (0.14.3)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py

52-75: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


80-80: Unused method argument: context

(ARG002)


109-109: Do not catch blind exception: Exception

(BLE001)

⏰ 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). (3)
  • GitHub Check: Pre-commit checks
  • GitHub Check: llm_evals
  • GitHub Check: build

Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
@RoiGlinik
RoiGlinik requested a review from Avi-Robusta November 5, 2025 20:02
Comment thread tests/plugins/toolsets/grafana/test_grafana_loki.py
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py Outdated
Avi-Robusta
Avi-Robusta previously approved these changes Nov 6, 2025

@Avi-Robusta Avi-Robusta left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just verify evals 100-102, and do the small changes I wrote

@RoiGlinik

Copy link
Copy Markdown
Collaborator Author

@Avi-Robusta I will do the 100-102 evals on a differet PR with new evals for the tool

@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: 2

♻️ Duplicate comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

107-110: Return full query context in NO_DATA response.

The NO_DATA response should include the complete query context (query string, time range, limit) so the LLM understands what was searched. Currently it only returns params.

Based on learnings

Apply this diff:

             else:
                 return StructuredToolResult(
                     status=StructuredToolResultStatus.NO_DATA,
                     params=params,
+                    data={
+                        "message": "No data returned from Loki query",
+                        "query": params.get("query", '{query="no_query_fallback"}'),
+                        "time_range": {"start": start, "end": end},
+                        "limit": params.get("limit") or DEFAULT_LOG_LIMIT,
+                    },
                 )
🧹 Nitpick comments (1)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1)

80-80: Remove unused context parameter or add type ignore.

The context parameter is not used in the method body. Either remove it if not needed, or if it's required by the Tool interface, add # noqa: ARG002 to suppress the linter warning.

If the parameter is required by the interface but unused:

-    def _invoke(self, params: dict, context: ToolInvokeContext) -> StructuredToolResult:
+    def _invoke(self, params: dict, context: ToolInvokeContext) -> StructuredToolResult:  # noqa: ARG002
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a04c1c9 and 4075c90.

📒 Files selected for processing (1)
  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: Use Ruff for formatting and linting (configured in pyproject.toml) for all Python code
Type hints are required; code should pass mypy (configured in pyproject.toml)
ALWAYS place Python imports at the top of the file, not inside functions or methods

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
holmes/plugins/toolsets/**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Toolsets must be located as holmes/plugins/toolsets/{name}.yaml or holmes/plugins/toolsets/{name}/

Files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
🧠 Learnings (1)
📚 Learning: 2025-10-05T13:01:12.288Z
Learnt from: CR
Repo: robusta-dev/holmesgpt PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-05T13:01:12.288Z
Learning: Applies to holmes/plugins/toolsets/**/*.{yaml,yml} : All toolsets MUST return detailed error messages from underlying APIs, including the exact query/command, time ranges, parameters/filters, and full API error response; for "no data" responses, specify what was searched and where

Applied to files:

  • holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
🪛 Ruff (0.14.3)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py

52-75: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


80-80: Unused method argument: context

(ARG002)


111-111: Do not catch blind exception: Exception

(BLE001)

⏰ 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). (3)
  • GitHub Check: llm_evals
  • GitHub Check: Pre-commit checks
  • GitHub Check: build
🔇 Additional comments (4)
holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py (4)

1-28: LGTM!

Imports are properly organized at the top of the file with appropriate type hints, following the coding guidelines.


31-45: LGTM!

The toolset initialization is correct, properly extending BaseGrafanaToolset with appropriate metadata and loading LLM instructions from the jinja template file.


77-78: LGTM!

The one-liner formatting method is concise and correctly structured.


93-95: Consider type ignore for params.get("query") to fix build/test failures.

A past review comment noted that build and tests are failing without a type ignore annotation here. Consider adding it as suggested.

Apply this diff if the type checker is complaining:

                 query=params.get(
-                    "query", '{query="no_query_fallback"}'
+                    "query", '{query="no_query_fallback"}'  # type: ignore
                 ),  # make sure a string returns. fall back to query that will return nothing.

Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
Comment thread holmes/plugins/toolsets/grafana/loki/toolset_grafana_loki.py
@github-actions

github-actions Bot commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Results of HolmesGPT evals

  • ask_holmes: 30/36 test cases were successful, 5 regressions, 1 setup failures
Test suite Test case Status
ask 01_how_many_pods ✅
ask 02_what_is_wrong_with_pod ✅
ask 04_related_k8s_events ✅
ask 05_image_version ✅
ask 09_crashpod ✅
ask 10_image_pull_backoff ✅
ask 110_k8s_events_image_pull ✅
ask 11_init_containers ✅
ask 13a_pending_node_selector_basic ✅
ask 14_pending_resources ✅
ask 15_failed_readiness_probe ✅
ask 17_oom_kill ✅
ask 18_oom_kill_from_issues_history ✅
ask 19_detect_missing_app_details ✅
ask 20_long_log_file_search ❌
ask 24_misconfigured_pvc ✅
ask 24a_misconfigured_pvc_basic ✅
ask 28_permissions_error 🚧
ask 39_failed_toolset ✅
ask 41_setup_argo ✅
ask 42_dns_issues_steps_new_tools ✅
ask 43_current_datetime_from_prompt ✅
ask 45_fetch_deployment_logs_simple ✅
ask 51_logs_summarize_errors ✅
ask 53_logs_find_term ✅
ask 54_not_truncated_when_getting_pods ✅
ask 59_label_based_counting ✅
ask 60_count_less_than ✅
ask 61_exact_match_counting ✅
ask 63_fetch_error_logs_no_errors ✅
ask 79_configmap_mount_issue ✅
ask 83_secret_not_found ✅
ask 86_configmap_like_but_secret ❌
ask 93_calling_datadog[0] ❌
ask 93_calling_datadog[1] ❌
ask 93_calling_datadog[2] ❌

Legend

  • ✅ the test was successful
  • :minus: the test was skipped
  • ⚠️ the test failed but is known to be flaky or known to fail
  • 🚧 the test had a setup failure (not a code regression)
  • 🔧 the test failed due to mock data issues (not a code regression)
  • 🚫 the test was throttled by API rate limits/overload
  • ❌ the test failed and should be fixed before merging the PR

@RoiGlinik
RoiGlinik merged commit 2a86539 into master Nov 6, 2025
8 checks passed
@RoiGlinik
RoiGlinik deleted the ROB-2323-loki-free-logql-tool branch November 6, 2025 08:31
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