Skip to content

Advanced Query Processing Architecture#4

Open
everettbu wants to merge 1 commit into
query-splitting-baselinefrom
query-splitting-enhancements
Open

Advanced Query Processing Architecture#4
everettbu wants to merge 1 commit into
query-splitting-baselinefrom
query-splitting-enhancements

Conversation

@everettbu

@everettbu everettbu commented Jul 26, 2025

Copy link
Copy Markdown

Test 4

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of template variables in queries to ensure they are correctly replaced before execution.
  • Tests

    • Added and updated tests to verify that template variables in query expressions and steps are properly interpolated before queries run.

…7534)

* Loki query splitting: interpolate queries before execution

* Update tests

* Prettier

* shardQuerySplitting: remove unnecessary call
@coderabbitai

coderabbitai Bot commented Jul 26, 2025

Copy link
Copy Markdown

Walkthrough

The changes update the query preparation logic in Loki's query splitting and sharding modules. Queries now have template variables interpolated using applyTemplateVariables per query, replacing previous bulk interpolation methods. Corresponding tests are updated to mock and verify this new interpolation approach, and additional test cases are added to ensure correct variable replacement.

Changes

File(s) Change Summary
public/app/plugins/datasource/loki/querySplitting.ts Refactored to interpolate template variables per query using applyTemplateVariables before splitting.
public/app/plugins/datasource/loki/shardQuerySplitting.ts Updated to use per-query applyTemplateVariables for interpolation instead of bulk interpolation method.
public/app/plugins/datasource/loki/querySplitting.test.ts Added test case to verify interpolation of template variables before query execution.
public/app/plugins/datasource/loki/shardQuerySplitting.test.ts Updated mocks and expectations for new interpolation logic; added test for interpolation before execution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Datasource
    participant QuerySplitter

    User->>Datasource: Submit request with targets (may include template variables)
    Datasource->>QuerySplitter: Call runSplitQuery/runShardSplitQuery with request
    loop For each target in request.targets
        QuerySplitter->>Datasource: applyTemplateVariables(target, scopedVars, filters)
        Datasource-->>QuerySplitter: Interpolated target
    end
    QuerySplitter->>QuerySplitter: Split/interpolate queries as needed
    QuerySplitter-->>Datasource: Prepared queries
    Datasource-->>User: Query results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In burrows deep, the queries leap,
With variables now replaced,
Each hop precise, no step misplaced,
The tests all run, the logic neat—
A bunny’s work, interpolation complete!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:17535) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
error Couldn't find any versions for "@grafana/data" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 dcb853d and 3ba2457.

📒 Files selected for processing (4)
  • public/app/plugins/datasource/loki/querySplitting.test.ts (1 hunks)
  • public/app/plugins/datasource/loki/querySplitting.ts (1 hunks)
  • public/app/plugins/datasource/loki/shardQuerySplitting.test.ts (4 hunks)
  • public/app/plugins/datasource/loki/shardQuerySplitting.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
public/app/plugins/datasource/loki/querySplitting.test.ts (1)
public/app/plugins/datasource/loki/querySplitting.ts (1)
  • runSplitQuery (291-357)
🔇 Additional comments (6)
public/app/plugins/datasource/loki/querySplitting.test.ts (1)

75-88: LGTM! Well-structured test for template variable interpolation.

This test case properly validates the new per-query template variable interpolation behavior. The test setup correctly mocks the datasource's replace method and verifies that template variables ($__auto and $step) are interpolated to concrete values before query execution.

public/app/plugins/datasource/loki/querySplitting.ts (1)

296-299: Excellent improvement to template variable handling.

The change from bulk interpolation to per-query template variable application using applyTemplateVariables is a solid architectural improvement. This approach:

  1. Provides more precise template variable interpolation per query
  2. Properly utilizes scopedVars and filters parameters
  3. Maintains the existing filtering logic while adding interpolation

The implementation is clean and follows the established pattern of chaining operations.

public/app/plugins/datasource/loki/shardQuerySplitting.ts (1)

49-52: Consistent implementation across query splitting mechanisms.

This change properly aligns the shard query splitting approach with the regular query splitting by applying the same per-query template variable interpolation pattern. The consistency between runSplitQuery and runShardSplitQuery is excellent for maintainability and ensures uniform behavior across different query splitting strategies.

public/app/plugins/datasource/loki/shardQuerySplitting.test.ts (3)

56-59: Properly updated mock to reflect API change.

The mock implementation correctly switches from interpolateVariablesInQueries to applyTemplateVariables, maintaining the same transformation logic while adapting to the new per-query processing approach.


84-101: Comprehensive test for template variable interpolation in shard splitting.

This test case effectively validates that template variables are properly interpolated before shard-based query execution. The test correctly verifies that both the query expression and step are interpolated, and that the sharding selector is properly applied to the interpolated query.


112-112: Correctly updated expectation for per-query processing.

The change from expecting 1 call to 5 calls properly reflects the shift from bulk interpolation to individual query processing. This aligns with the implementation change where applyTemplateVariables is now called once per query.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch query-splitting-enhancements

🪧 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 generate unit tests to generate unit tests for 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.

@everettbu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Aug 28, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it has not had any further activity in the last 2 weeks. Thank you for your contributions!

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