Skip to content

Conversation

@akshayutture-augment
Copy link

@akshayutture-augment akshayutture-augment commented Nov 14, 2025

Test 4


Replicated from ai-code-review-evaluation/grafana-cursor#4


Note

Interpolates template variables on Loki queries before time- and shard-based splitting, updating tests and mocks accordingly.

  • Loki query splitting (querySplitting.ts):
    • Apply datasource.applyTemplateVariables to targets before filtering and splitting.
  • Shard query splitting (shardQuerySplitting.ts):
    • Build target list with applyTemplateVariables prior to sharding; replace previous interpolation method.
  • Tests:
    • Add/adjust tests to verify interpolation of $__auto and $step before execution for both split and shard-split paths.
    • Update mocks to use applyTemplateVariables and adjust expectations (expressions, steps, call counts, request shapes).

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

…7534)

* Loki query splitting: interpolate queries before execution

* Update tests

* Prettier

* shardQuerySplitting: remove unnecessary call
@akshayutture-augment
Copy link
Author

cursor review

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

Choose a reason for hiding this comment

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

Bug: Template Variables: Double Interpolation Breaks Queries.

Template variables are interpolated twice when shard splitting is enabled. runShardSplitQuery calls applyTemplateVariables on each query, then passes them to runSplitQuery which calls applyTemplateVariables again. This double interpolation can cause variables to be incorrectly replaced multiple times, potentially breaking queries that contain variable-like patterns in their interpolated values.

Fix in Cursor Fix in Web

const queries = request.targets
.filter((query) => !query.hide)
.filter((query) => query.expr)
.map((query) => datasource.applyTemplateVariables(query, request.scopedVars, request.filters));
Copy link

Choose a reason for hiding this comment

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

Bug: Double Interpolation Glitch for Template Variables

Template variables are interpolated twice in the regular query splitting path. The new code calls applyTemplateVariables in runSplitQuery, but DataSourceWithBackend.query() (called via datasource.runQuery) also calls applyTemplateVariables. The old code didn't interpolate in runSplitQuery, relying solely on the backend interpolation. This double interpolation can cause variables to be incorrectly replaced multiple times.

Fix in Cursor Fix in Web

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.

3 participants