-
Notifications
You must be signed in to change notification settings - Fork 715
feat: add $__range variable for dashboard queries
#8917
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
Conversation
|
Failed to generate code suggestions for PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
added three new dashboard query variables ($__range, $__range_s, $__range_ms) to represent the total time window selection, following the existing pattern used for $__interval and $__rate_interval
Critical Issue:
- incorrect unit conversion: divides by 1000000 (microseconds→seconds) when timestamps are in milliseconds (needs division by 1000)
- this will cause all
$__rangevalues to be 1000x smaller than expected (e.g., 7 days becomes ~10 minutes)
Other observations:
- variable replacement logic follows existing patterns correctly
- tests verify variable replacement works but don't validate calculated values
- fallback to "1s" minimum for PromQL compatibility is reasonable
Confidence Score: 0/5
- this PR has a critical unit conversion bug that breaks the core functionality
- the incorrect division by 1000000 instead of 1000 causes all
$__rangecalculations to be off by 1000x, making the feature completely non-functional (7-day range would appear as ~10 minutes) - web/src/composables/dashboard/usePanelDataLoader.ts requires immediate attention to fix unit conversion bug on line 1912
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| web/src/composables/dashboard/usePanelDataLoader.ts | 1/5 | added $__range, $__range_s, and $__range_ms variables with incorrect unit conversion (divides by 1000000 instead of 1000) |
| web/src/composables/dashboard/usePanelDataLoader.spec.ts | 4/5 | added tests for $__range variable replacement in queries, but tests don't validate actual calculated values |
Sequence Diagram
sequenceDiagram
participant User
participant Dashboard
participant usePanelDataLoader
participant replaceQueryValue
participant API
User->>Dashboard: Select time range
Dashboard->>usePanelDataLoader: loadData()
usePanelDataLoader->>usePanelDataLoader: Calculate startISOTimestamp/endISOTimestamp (milliseconds)
usePanelDataLoader->>replaceQueryValue: replaceQueryValue(query, startISOTimestamp, endISOTimestamp)
replaceQueryValue->>replaceQueryValue: Calculate __range_seconds from timestamps
replaceQueryValue->>replaceQueryValue: Format __range using formatRateInterval()
replaceQueryValue->>replaceQueryValue: Create $__range, $__range_s, $__range_ms variables
replaceQueryValue->>replaceQueryValue: Replace variables in query string
replaceQueryValue-->>usePanelDataLoader: Modified query with variables replaced
usePanelDataLoader->>API: Execute query with replaced variables
API-->>usePanelDataLoader: Query results
usePanelDataLoader-->>Dashboard: Update panel data
2 files reviewed, 1 comment
| // calculate range in seconds (total time range of the dashboard) | ||
| // Note: startISOTimestamp and endISOTimestamp are in microseconds (from API) | ||
| const __range_micros = endISOTimestamp - startISOTimestamp; | ||
| const __range_seconds = __range_micros / 1000000; // Convert microseconds to seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: comment says "microseconds" but startISOTimestamp and endISOTimestamp are in milliseconds (from .getTime() on line 1288-1289). division should be by 1000, not 1000000
| // calculate range in seconds (total time range of the dashboard) | |
| // Note: startISOTimestamp and endISOTimestamp are in microseconds (from API) | |
| const __range_micros = endISOTimestamp - startISOTimestamp; | |
| const __range_seconds = __range_micros / 1000000; // Convert microseconds to seconds | |
| // calculate range in seconds (total time range of the dashboard) | |
| // Note: startISOTimestamp and endISOTimestamp are in milliseconds (from Date.getTime()) | |
| const __range_millis = endISOTimestamp - startISOTimestamp; | |
| const __range_seconds = __range_millis / 1000; // Convert milliseconds to seconds |
Prompt To Fix With AI
This is a comment left during a code review.
Path: web/src/composables/dashboard/usePanelDataLoader.ts
Line: 1909:1912
Comment:
**logic:** comment says "microseconds" but `startISOTimestamp` and `endISOTimestamp` are in milliseconds (from `.getTime()` on line 1288-1289). division should be by 1000, not 1000000
```suggestion
// calculate range in seconds (total time range of the dashboard)
// Note: startISOTimestamp and endISOTimestamp are in milliseconds (from Date.getTime())
const __range_millis = endISOTimestamp - startISOTimestamp;
const __range_seconds = __range_millis / 1000; // Convert milliseconds to seconds
```
How can I resolve this? If you propose a fix, please make it concise.
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 346 | 0 | 19 | 1 | 95% | 4m 38s |
17b6cd7 to
52a8f1b
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 342 | 0 | 19 | 5 | 93% | 4m 43s |
52a8f1b to
9ef60cb
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 344 | 0 | 19 | 3 | 94% | 4m 44s |
Add support for $__range variable that represents the dashboard's total time window selection. This complements existing variables like $__interval and $__rate_interval. Variables added: - $__range: formatted time range (e.g., "1h", "24h", "7d") - $__range_s: time range in seconds - $__range_ms: time range in milliseconds The variable dynamically updates when users change the dashboard time range and works with both PromQL and SQL queries. Fixes #8914
9ef60cb to
6fa55cd
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 342 | 0 | 19 | 5 | 93% | 4m 39s |
Add support for $__range variable that represents the dashboard's total time window selection. This complements existing variables like
$__intervaland$__rate_interval.Variables added:
$__range: formatted time range (e.g., "1h", "24h", "7d")$__range_s: time range in seconds$__range_ms: time range in millisecondsThe variable dynamically updates when users change the dashboard time range and works with both PromQL and SQL queries.
Fixes #8914