feat: Add completions for PromQL variables - #2995
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 91147c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile SummaryThis PR adds language-specific PromQL variable completions, integrates them with metric and built-in PromQL suggestions, and adds unit and end-to-end coverage. The new replacement-range handling still misclassifies an existing braced reference when the cursor is directly after its
Confidence Score: 4/5The PR should not merge until accepting a completion at the The completion source classifies reference form using only text before the cursor, so an existing braced reference with the cursor after Files Needing Attention: packages/app/src/components/PromQLEditor/variableCompletionSource.ts and its range tests
|
| Filename | Overview |
|---|---|
| packages/app/src/components/PromQLEditor/variableCompletionSource.ts | Adds reference-aware replacement ranges, but misclassifies a braced reference when its opening brace is immediately after the cursor. |
| packages/app/src/components/PromQLEditor/PromQLEditor.tsx | Registers variable, metric-name, and built-in PromQL completion sources through a reconfigurable autocomplete compartment. |
| packages/app/src/components/SQLEditor/variableCompletions.tsx | Separates SQL and PromQL completion generation and previews each form using language-aware substitution. |
| packages/common-utils/src/variables.ts | Extends shared variable substitution with PromQL-specific default formatting. |
| packages/app/src/components/PromQLEditor/tests/variableCompletionSource.test.ts | Covers suffix preservation and several cursor positions but omits the `$ |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["Cursor in $|{env}"] --> B["Completion source sees only $ before cursor"]
B --> C["Selects bare-reference suffix matcher"]
C --> D["Replacement range covers only $"]
D --> E["Accept ${env} completion"]
E --> F["Query becomes ${env}{env}"]
Reviews (4): Last reviewed commit: "feat: Add completions for PromQL variabl..." | Re-trigger Greptile
| // `${svc}` over a half-typed `${sv}` doesn't leave a stray `}` behind. | ||
| const suffix = context.state.doc | ||
| .sliceString(context.pos) | ||
| .match(VARIABLE_AFTER); | ||
|
|
||
| return { | ||
| from: prefix.from + dollar, |
There was a problem hiding this comment.
Replacement range consumes query suffixes
When a user accepts a completion while editing a reference followed by valid PromQL text, such as ${sv}_total, VARIABLE_AFTER includes the closing brace and _total in the replacement range, causing the suffix to be silently deleted and changing the query.
Knowledge Base Used: Dashboards and visualization
E2E Test Results✅ All tests passed • 318 passed • 1 skipped • 1172s
Tests ran across 4 shards in parallel. |
cd61c57 to
043c588
Compare
043c588 to
edf2a53
Compare
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
Deep Review✅ No critical issues found. The core change — a dedicated CodeMirror completion source for PromQL variable references plus a clean SQL/PromQL split of the variable-completion builders — is correct and well-covered by unit and E2E tests. The refactor preserves the existing SQL completion output (macros, every reference form, and expansion previews are reproduced field-for-field), and the editor wiring correctly re-registers PromQL's own function/keyword source that an Prior review comment — resolved. The earlier P1 ("replacement range consumes query suffixes", e.g. 🔵 P3 nitpicks (2)
Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, previous-comments, agent-native, learnings. Residual risks: Built-in PromQL completions depend on the third-party Testing gaps: Unit tests omit the braced-with-format-then-text case ( |
edf2a53 to
91147c2
Compare
Summary
This PR improves support for variables in promql by adding variable reference completions to the promql editor.
Note that this requires enabling the following feature toggles:
(In the UI)
(In the API)
Screenshots or video
Screen.Recording.2026-08-25.at.12.23.03.PM.mov
How to test
ResourceAttributes['service.instance.id']from the metrics gauge tablehttp_client_duration_milliseconds_count{instance=~"$Instance"}References