Skip to content

Update visual query build from grafana upstream #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SammyVimes
Copy link

@SammyVimes SammyVimes commented May 25, 2025

Fixes #317

Bringing sources closer to Prometheus Visual Query Builder code
Copied relevant tests
PromQL lezer grammar has also been updated recently, so maybe a good next step should be updating metricsql lezer grammar, this way it will be possible to bring visual query builder's sources even closer to grafana promql's

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the visual query builder’s source by aligning it more closely with upstream Grafana PromQL code while incorporating updates from PromQL lezer grammar. Key changes include adding the ErrorId constant, modifying error handling and label extraction in parsing, updating function argument processing for operations, and updating dependency versions in package.json.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

File Description
src/querybuilder/shared/parsingUtils.ts Adds a new constant ErrorId with explanatory comment
src/querybuilder/parsing.ts Updates parsing logic including error node detection, label extraction, function argument handling, and operation order
src/configuration/ConfigEditor.tsx Adjusts imports in configuration editor by adding FeatureToggles and removing an unused import
package.json Upgrades @lezer/common dependency version
Comments suppressed due to low confidence (2)

src/querybuilder/parsing.ts:223

  • The variable 'body' is used in this conditional but is not defined in the surrounding context. Consider using 'callArgs' consistently or defining 'body' if that is the intended variable.
if (getString(expr, body) === '([' + interval + '])') {

src/querybuilder/parsing.ts:231

  • The switch from unshifting to pushing operations in the query builder changes the order of operations. Verify that this change is intentional and that it maintains the expected natural order in the visual query editor.
visQuery.operations.push(op);

@Loori-R
Copy link
Contributor

Loori-R commented May 27, 2025

FYI: We already have lezer-metricsql located in /packages/lezer-metricsql.

Loori-R
Loori-R previously approved these changes May 27, 2025
Copy link
Contributor

@Loori-R Loori-R left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request! LGTM!

@SammyVimes SammyVimes force-pushed the update-from-grafana branch from ed1b0cc to 76f71b2 Compare May 27, 2025 22:42
@SammyVimes SammyVimes requested review from Copilot and Loori-R May 27, 2025 22:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the visual query builder by aligning parts of its source code more closely with the upstream Grafana implementation and updating dependencies. Key changes include adding and reusing an exported error node identifier, refactoring context usage (switching to an InternalContext with a function call stack), and minor adjustments in parsing logic and regex for label values.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

File Description
src/querybuilder/shared/parsingUtils.ts Exports a new ErrorId constant for error node identification.
src/querybuilder/parsing.ts Refactors context type to InternalContext, adds function call stack management, revises label parsing and binary operation insertion logic, and adjusts error reporting.
src/configuration/ConfigEditor.tsx Updates import statements by removing unused components and adding FeatureToggles.
package.json Upgrades the @lezer/common dependency version.
Comments suppressed due to low confidence (1)

src/querybuilder/parsing.ts:372

  • The logic for computing the insertion index using functionCallStack is not immediately clear; please add an explanatory comment to clarify the intended ordering of binary operations.
let idx = visQuery.operations.length;

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.

Updating query builder from upstream
2 participants