Skip to content

Conversation

@everettbu
Copy link

Test 4

…7534)

* Loki query splitting: interpolate queries before execution

* Update tests

* Prettier

* shardQuerySplitting: remove unnecessary call
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR refactors the template variable interpolation architecture in the Loki datasource's query splitting functionality. The changes standardize how template variables (like $__interval, $__auto, $step, and user-defined variables) are processed across different query splitting paths.

The key architectural change replaces the interpolateVariablesInQueries() method with the standard Grafana datasource pattern of using applyTemplateVariables() on individual queries. This method takes additional parameters including scoped variables and request filters, enabling more comprehensive variable resolution.

In querySplitting.ts, template variable interpolation is now applied after basic query filtering (removing hidden queries and empty expressions) but before the splitting logic analyzes queries for partitioning strategies. The same pattern is implemented in shardQuerySplitting.ts for consistency.

The changes ensure that template variables are properly resolved before query splitting decisions are made, which is critical for accurate partitioning logic. Functions like querySupportsSplitting(), isLogsQuery(), and various partitioning functions now operate on fully interpolated query expressions rather than raw templates.

Comprehensive test coverage has been added to validate that variables like $__auto and $step are correctly interpolated to their actual values (e.g., '5m') before queries are executed. The test updates reflect the new per-query method call pattern, with call count expectations adjusted accordingly.

Confidence score: 4/5

  • This refactoring improves the consistency and robustness of template variable handling in query splitting
  • The change follows established Grafana datasource patterns and includes proper test coverage
  • The files that need the most attention are the core splitting logic files to ensure the interpolation timing is correct

4 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@github-actions
Copy link
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
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!

@github-actions github-actions bot closed this Sep 12, 2025
@everettbu everettbu reopened this Sep 12, 2025
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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