Skip to content

ROB-1284: unified logging api coralogix - #429

Merged
nherment merged 7 commits into
rob-1267_unified_tool_logs_apifrom
rob-1284_unified_logging_api_coralogix
May 20, 2025
Merged

nherment merged 7 commits into
rob-1267_unified_tool_logs_apifrom
rob-1284_unified_logging_api_coralogix

Conversation

@nherment

@nherment nherment commented May 19, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor

    • Streamlined the Coralogix log fetching toolset for improved modularity and configuration handling.
    • Unified and simplified log query parameter handling and query construction.
    • Updated log formatting to remove timestamp prefixes, showing only raw log messages.
    • Aligned Coralogix log fetching instructions with other log sources for consistency.
    • Introduced structured configuration models and log retrieval methodology options for Coralogix integration.
  • Tests

    • Enhanced integration tests for Coralogix log fetching, adding new scenarios and fixtures.
    • Updated and expanded unit tests to reflect new parameter structures and log formatting.
    • Improved environment validation and test modularity.
  • Chores

    • Added a .gitignore rule to exclude test output files in fixture directories.

@coderabbitai

coderabbitai Bot commented May 19, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes refactor and simplify the Coralogix log fetching toolset and its integration with the rest of the system. Strongly typed Pydantic models are introduced for configuration and parameters, replacing ad-hoc dictionaries. Query construction and log formatting are streamlined, and test coverage is improved with new fixtures and parameterized integration tests. Prompt templates and fixtures are also updated for consistency.

Changes

File(s) Change Summary
holmes/plugins/prompts/_fetch_logs.jinja2 Replaced detailed Coralogix log-fetching instructions with a default prompt template inclusion, aligning with other log sources.
holmes/plugins/toolsets/coralogix/api.py Refactored to use FetchPodLogsParams for query construction and execution; updated function signatures; removed unused imports and legacy parameter/label logic.
holmes/plugins/toolsets/coralogix/toolset_coralogix_logs.py Replaced custom toolset and tool classes with a BasePodLoggingToolset-based implementation; centralized configuration, parameter parsing, and log fetching; removed detailed tool parameter logic.
holmes/plugins/toolsets/coralogix/utils.py Added Pydantic models (CoralogixConfig, CoralogixLabelsConfig), a retrieval methodology enum, and improved datetime normalization; removed label extraction and multiline log formatting utilities.
tests/plugins/toolsets/coralogix/fixtures/.gitignore Added rule to ignore .actual files in the fixtures directory.
tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt Removed all timestamp prefixes from log entries, leaving only raw log messages.
tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt.actual Deleted file containing raw log entries with timestamps and error messages.
tests/plugins/toolsets/coralogix/test_coralogix_integration.py Refactored and expanded integration tests; introduced fixtures, centralized environment checks, added parameterized log-fetching tests, and improved structure.
tests/plugins/toolsets/coralogix/test_coralogix_unit.py Updated to use new parameter models and query structure; removed legacy test fixtures and updated test cases to reflect new parameterization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CoralogixLogsToolset
    participant CoralogixConfig
    participant Coralogix API

    User->>CoralogixLogsToolset: fetch_logs(FetchPodLogsParams)
    CoralogixLogsToolset->>CoralogixConfig: Access configuration
    CoralogixLogsToolset->>Coralogix API: Query logs (with params)
    Coralogix API-->>CoralogixLogsToolset: Return log results
    CoralogixLogsToolset-->>User: StructuredToolResult (logs, status)
Loading

Suggested reviewers

  • moshemorad
    """

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 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 016aec1 and 707ef3b.

📒 Files selected for processing (1)
  • holmes/plugins/toolsets/coralogix/api.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • holmes/plugins/toolsets/coralogix/api.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (3.12)
  • GitHub Check: build (3.11)
  • GitHub Check: build (3.10)
  • GitHub Check: build (3.12)
  • GitHub Check: build (3.9)
  • GitHub Check: build (3.11)
  • GitHub Check: build (3.10)
  • GitHub Check: build (3.9)
  • GitHub Check: llm_evals
✨ Finishing Touches
  • 📝 Generate Docstrings

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

@nherment
nherment changed the base branch from master to rob-1267_unified_tool_logs_api May 19, 2025 05:53
@nherment
nherment marked this pull request as ready for review May 19, 2025 10:22

@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 (1)
tests/plugins/toolsets/coralogix/test_coralogix_integration.py (1)

91-98: Consider adding additional assertions for returned data

While the basic query test checks for success and the presence of the search term, consider adding assertions about other expected properties of the returned data structure.

 def test_basic_query(coralogix_logs_toolset):
     result = coralogix_logs_toolset.fetch_logs(
         FetchLogsParams(namespace=TEST_NAMESPACE, pod_name=TEST_POD_NAME)
     )
     print(result.data)
     assert result.status == ToolResultStatus.SUCCESS, result.error
     assert not result.error
     assert TEST_SEARCH_TERM in result.data
+    assert result.url, "URL should be present in the result"
+    assert result.invocation, "Query string should be present in the invocation field"
+    assert "link:" in result.data, "Data should contain a link section"
+    assert "query:" in result.data, "Data should contain a query section"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between da8f140 and 1e5edb0.

📒 Files selected for processing (9)
  • holmes/plugins/prompts/_fetch_logs.jinja2 (1 hunks)
  • holmes/plugins/toolsets/coralogix/api.py (4 hunks)
  • holmes/plugins/toolsets/coralogix/toolset_coralogix_logs.py (2 hunks)
  • holmes/plugins/toolsets/coralogix/utils.py (4 hunks)
  • tests/plugins/toolsets/coralogix/fixtures/.gitignore (1 hunks)
  • tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt (1 hunks)
  • tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt.actual (0 hunks)
  • tests/plugins/toolsets/coralogix/test_coralogix_integration.py (2 hunks)
  • tests/plugins/toolsets/coralogix/test_coralogix_unit.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt.actual
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/plugins/toolsets/coralogix/test_coralogix_unit.py (3)
holmes/plugins/toolsets/logging_api.py (1)
  • FetchLogsParams (27-33)
tests/plugins/toolsets/coralogix/test_coralogix_integration.py (1)
  • coralogix_config (46-57)
holmes/plugins/toolsets/coralogix/api.py (1)
  • build_query_string (56-66)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: llm_evals
🔇 Additional comments (27)
tests/plugins/toolsets/coralogix/fixtures/.gitignore (1)

1-2: LGTM: Appropriate gitignore pattern for test artifacts

Adding .gitignore to exclude .actual files from version control is a good practice. These files are generated during test execution when comparing expected vs actual output, as seen in the unit tests.

holmes/plugins/prompts/_fetch_logs.jinja2 (1)

19-19: Good simplification of Coralogix log prompt

Standardizing the Coralogix prompt to use the same _default_log_prompt.jinja2 template as other logging systems creates consistency across different log sources. This aligns with the broader refactoring of the Coralogix toolset to use a more unified logging API.

tests/plugins/toolsets/coralogix/fixtures/formatted_logs.txt (1)

1-124: Format simplification looks good

The timestamp prefixes have been removed from the log lines while preserving the actual log content. This aligns with the changes to stringify_flattened_logs function that now omits timestamp metadata for cleaner log representation.

tests/plugins/toolsets/coralogix/test_coralogix_unit.py (5)

16-16: Good update to import the new Pydantic model

Replacing the import of FetchLogs with FetchLogsParams from the logging_api module aligns with the architecture changes that moved to strongly typed Pydantic models for parameter handling.


103-104: Test case updated correctly for new parameter structure

The test parameters have been properly updated to use the new Kubernetes-centric keys (namespace, pod_name) instead of the previous resource-centric approach, matching the refactored API.


108-110: Test case properly refactored for new parameter structure

The test case has been correctly updated to use the standardized parameter names and structure, with namespace and pod_name as the primary identifiers.


116-119: Matching parameter added correctly in test case

The test case properly includes the new match parameter which allows filtering logs by content, a useful addition to the API.


125-129: Good test function improvement

The test function has been improved by:

  1. Using the new FetchLogsParams Pydantic model to validate parameters
  2. Adding debug print statements for easier troubleshooting when tests fail

This makes the tests more robust and easier to debug.

holmes/plugins/toolsets/coralogix/toolset_coralogix_logs.py (4)

30-42: Good implementation of BaseLoggingToolset inheritance

The new CoralogixLogsToolset class properly inherits from BaseLoggingToolset with good initialization parameters. This follows a clean OOP approach and standardizes the logging interface across the application.


50-57: Well-implemented prerequisites check

Good validation approach using the Pydantic model for configuration. The method properly handles empty configs and missing API keys with appropriate error messages.


59-61: Good encapsulation of config property

Using a property method provides clean access to the configuration while maintaining good encapsulation principles.


63-101: Well-structured fetch_logs method

The method provides proper error handling and uses the strongly typed FetchLogsParams model for better type safety. The use of a structured result with appropriate status codes, error messages, and data formatting enhances API consistency.

holmes/plugins/toolsets/coralogix/api.py (5)

15-15: Good integration with unified logging API

Importing FetchLogsParams from the common logging API module aligns with the unified logging strategy.


22-22: Appropriate adjustment to default log count

Good update of the default log count to match Coralogix's actual default value with a clear explanatory comment.


56-66: Improved query string construction with strong typing

The function now uses strongly typed parameters instead of dictionaries, which improves type safety and makes the code more maintainable. The query construction is clean with appropriate filtering logic.


69-75: Simplified timestamp handling

Clean refactoring to work directly with the strongly typed parameters instead of dictionary lookups, which reduces potential errors.


78-90: Consistent use of typed parameters across API functions

All API functions have been updated to consistently use the FetchLogsParams model and CoralogixConfig model, which improves code consistency and reduces the chance of errors from mismatched parameter handling.

Also applies to: 94-95, 119-120

holmes/plugins/toolsets/coralogix/utils.py (5)

22-25: Good use of Pydantic for label configuration

Creating a dedicated model for label keys with meaningful defaults improves configuration clarity and maintainability.


28-33: Well-defined enum for log retrieval strategies

Using an enum for log retrieval methodologies provides type safety and self-documentation for the available options.


36-43: Comprehensive configuration model

The CoralogixConfig model properly encapsulates all necessary configuration parameters with appropriate defaults, which improves validation and usage.


57-61: Improved docstring for normalize_datetime

The updated docstring clearly explains the function's purpose, handling of edge cases, and compatibility considerations.


102-107: Simplified log formatting

The streamlined approach to log formatting (removing timestamps and indentation) makes the output cleaner and more consistent with the unified logging strategy.

tests/plugins/toolsets/coralogix/test_coralogix_integration.py (5)

1-4: Helpful module documentation

Good addition of a docstring explaining the purpose of these integration tests and how to configure them for manual execution.


18-29: Improved test skip management

Well-organized approach to handling environment variables with a centralized list and module-level skip marker. This reduces code duplication and makes test dependencies clearer.


36-42: Good test parameterization

Using constants for test parameters improves readability and makes it easier to update test criteria. The comment explaining the expected result from the date range is particularly helpful.


45-57: Well-structured test fixtures

The fixtures provide clean test setup with appropriate error handling and type annotations. The defensive approach in coralogix_config is a good practice for robust testing.

Also applies to: 60-65


91-98: Comprehensive test coverage for log fetching

The three log fetching tests cover different parameter combinations and verify both success conditions and content expectations. The assertions and parsing logic are clear and thorough.

Also applies to: 101-115, 117-135

@nherment
nherment requested a review from moshemorad May 19, 2025 11:53
@github-actions

Copy link
Copy Markdown
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 ⚠️
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_kube_controller_manager_down ⚠️
investigate 11_KubeDeploymentReplicasMismatch ✅
investigate 12_KubePodCrashLooping ✅
investigate 13_KubePodNotReady ✅
investigate 14_Watchdog ✅
investigate 15_tempo ✅

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

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