Skip to content

Benchmark: grafana PR 107534 - #14

Open
celmis-codereviewer wants to merge 6 commits into
cr-base-107534from
cr-pr-107534
Open

celmis-codereviewer wants to merge 6 commits into
cr-base-107534from
cr-pr-107534

Conversation

@celmis-codereviewer

Copy link
Copy Markdown

Benchmark reproduction of grafana#107534

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

@celmis-codereviewer celmis-codereviewer left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

💬 COMMENT — findings to consider

Full findings and scope are in the review summary comment on this pull request — one persistent comment, updated in place on every run.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Why: When request.targets contains a query with a template variable that evaluates to an empty string, filter((query) => query.expr) on line 299 evaluates to true before interpolation, causing the resulting query with an empty expr on line 300 to be included in queries instead of being filtered out.

🟡 Query expression filter runs before template variable interpolation

filter((query) => query.expr) is executed before datasource.applyTemplateVariables(...). If a target's expr contains a template variable (such as $variable) that interpolates to an empty string "", the filter evaluates to true on the un-interpolated string. applyTemplateVariables then replaces the variable with "", resulting in a query object with an empty expr being passed to partition and execution instead of being filtered out.

The same defect is at 2 locations: public/app/plugins/datasource/loki/querySplitting.ts:299, public/app/plugins/datasource/loki/shardQuerySplitting.ts:50.

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

agent: defect · rule: defect.logic-error · confidence: 0.85

@celmis-codereviewer

Copy link
Copy Markdown
Author

🤖 Code Review for PR #14

⚙ ADJUSTED — graph context partial (0 of 4 changed files): 4 of 4 changed files have no symbols in the index; 4 of them are not in that checkout at all (public/app/plugins/datasource/loki/querySplitting.test.ts, public/app/plugins/datasource/loki/querySplitting.ts, public/app/plugins/datasource/loki/shardQuerySplitting.test.ts, public/app/plugins/datasource/loki/shardQuerySplitting.ts) — this PR's base is older than the indexed revision, so those files were renamed or deleted before it and no re-index can bring them back; there is nothing to fix.

💬 COMMENT — findings to consider

Findings

  • 🟡 Warning: 1

Scope

  • Files changed: 4
  • Lines: +48 / -15

Performance

  • Analysis time: 85.5s · agents: structural, cve, contract, security, defect · tokens: 16,796/11,704

Powered by Code Analyzer · context: tree-sitter graph + structural, cve, contract, security, defect

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