Skip to content

Advanced Query Processing Architecture - #7

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

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

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Jan 22, 2026

Copy link
Copy Markdown

Test 4nn

Summary by CodeRabbit

  • Bug Fixes

    • Fixed template variable interpolation in Loki queries. Variables such as $__auto and time intervals are now properly substituted before query execution on a per-query basis, ensuring accurate query processing and results.
  • Tests

    • Added and updated test coverage to verify template variable interpolation occurs correctly before query execution.

✏️ Tip: You can customize this high-level summary in your review settings.

nn---n*Replicated from [ai-code-review-evaluation/grafana-coderabbit#4](https://github.com/ai-code-review-evaluation/grafana-coderabbit/pull/4)*

Note

Medium Risk
Touches core Loki query execution paths for time- and shard-splitting; incorrect interpolation could subtly change queries sent to Loki, but changes are small and covered by added/updated tests.

Overview
Ensures Loki query splitting paths interpolate template variables before executing sub-requests by applying datasource.applyTemplateVariables() to each target up front (including step), instead of relying on later/batch interpolation.

Updates shard-splitting to use the same per-query interpolation approach and adjusts tests accordingly, adding coverage for $__auto/$step replacement and verifying interpolated expr/step values are what runQuery receives.

Written by Cursor Bugbot for commit 3ba2457. Configure here.

…7534)

* Loki query splitting: interpolate queries before execution

* Update tests

* Prettier

* shardQuerySplitting: remove unnecessary call
@ShashankFC

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

.filter((query) => query.expr)
.filter((query) => !query.hide);
.filter((query) => !query.hide)
.map((query) => datasource.applyTemplateVariables(query, request.scopedVars, request.filters));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shard path applies templates twice

Medium Severity

runShardSplitQuery() now applies applyTemplateVariables() before delegating to runSplitQuery(), which also applies applyTemplateVariables(). This double interpolation makes shard-split requests non-idempotent, especially for request.filters, where ad hoc filters can be appended repeatedly to already-interpolated expr values.

Additional Locations (1)

Fix in Cursor Fix in Web

.filter((query) => query.expr)
.filter((query) => !query.hide);
.filter((query) => !query.hide)
.map((query) => datasource.applyTemplateVariables(query, request.scopedVars, request.filters));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty interpolated expressions are still executed

Medium Severity

The new interpolation flow filters query.expr before calling applyTemplateVariables(). If interpolation resolves an expression to an empty string, that target is no longer removed and can continue through split execution, leading to invalid empty expr queries being scheduled.

Additional Locations (1)

Fix in Cursor Fix in Web

@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 Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants