-
Notifications
You must be signed in to change notification settings - Fork 713
feat: dashboard custom chart support for promql #8897
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
feat: dashboard custom chart support for promql #8897
Conversation
|
Failed to generate code suggestions for PR |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 345 | 0 | 19 | 1 | 95% | 4m 39s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 345 | 0 | 19 | 1 | 95% | 4m 40s |
d4cca4c to
7f17f9d
Compare
|
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
This PR enables PromQL support for custom chart panels by modifying chart type validation, query type detection, and data structure handling across the dashboard panel system.
Key Changes
- Chart Selection: Added
custom_chartto the list of allowed chart types when in PromQL mode - Query Type Detection: Modified
QueryTypeSelectorto detect the actualqueryTypefor custom charts instead of defaulting tocustom-sql, enabling proper PromQL mode initialization - Query Preservation: When switching to PromQL mode, custom chart queries are now preserved instead of being cleared (non-custom charts still get reset to line charts)
- Data Validation: Added
custom_chartto the list of allowed chart types in panel validation logic - Data Structure Handling: Added conditional data structure checking in
convertPanelData.tsto handle both PromQL (data[0].result) and SQL (data[0]) data formats
Issue Found
- Missing optional chaining on PromQL data check in
convertPanelData.ts:128could cause runtime error ifdata[0]is undefined
Confidence Score: 4/5
- Safe to merge after fixing the optional chaining issue in convertPanelData.ts
- The implementation is sound and properly handles the addition of PromQL support for custom charts. The changes are well-targeted and preserve backwards compatibility. However, there's a missing optional chaining operator that could cause a runtime error in edge cases, which should be fixed before merging.
- web/src/utils/dashboard/convertPanelData.ts - missing optional chaining on data[0].result check
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| web/src/components/dashboards/addPanel/ChartSelection.vue | 5/5 | Added custom_chart to allowed chart types in PromQL mode |
| web/src/components/dashboards/addPanel/QueryTypeSelector.vue | 5/5 | Detects PromQL query type for custom charts and preserves query when switching to PromQL |
| web/src/utils/dashboard/convertDataIntoUnitValue.ts | 5/5 | Added custom_chart to allowed chart types in validation |
| web/src/utils/dashboard/convertPanelData.ts | 4/5 | Added PromQL data structure handling for custom charts; missing optional chaining on PromQL check |
Sequence Diagram
sequenceDiagram
participant User
participant QueryTypeSelector
participant ChartSelection
participant PanelData
participant convertPanelData
participant CustomChart
User->>QueryTypeSelector: Select PromQL mode
QueryTypeSelector->>PanelData: Set queryType = "promql"
QueryTypeSelector->>PanelData: Set customQuery = true
alt Panel type is custom_chart
QueryTypeSelector->>PanelData: Preserve existing query
else Panel type is not custom_chart
QueryTypeSelector->>PanelData: Clear query, set type = "line"
end
User->>ChartSelection: Select chart type
Note over ChartSelection: custom_chart now allowed in PromQL mode
ChartSelection->>PanelData: Update chart type
User->>User: Execute query
User->>convertPanelData: Process data
alt queryType is promql
convertPanelData->>convertPanelData: Check data[0].result.length
convertPanelData->>CustomChart: Pass PromQL data structure
else queryType is sql
convertPanelData->>convertPanelData: Check data[0]?.length
convertPanelData->>CustomChart: Pass SQL data structure
end
CustomChart->>User: Render custom chart
4 files reviewed, 1 comment
| const hasData = | ||
| panelSchema?.queryType === "promql" | ||
| ? data.length > 0 && data[0].result.length > 0 | ||
| : data.length > 0 && data[0]?.length > 0; |
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.
syntax: potential issue with data structure check
The check data[0]?.length > 0 for SQL query type may not work correctly. Based on the codebase, SQL query data appears to be an array where data[0] is itself an array, so checking data[0]?.length > 0 is correct. However, for PromQL data, data[0].result is an array. The current check lacks optional chaining:
| const hasData = | |
| panelSchema?.queryType === "promql" | |
| ? data.length > 0 && data[0].result.length > 0 | |
| : data.length > 0 && data[0]?.length > 0; | |
| const hasData = | |
| panelSchema?.queryType === "promql" | |
| ? data.length > 0 && data[0]?.result?.length > 0 | |
| : data.length > 0 && data[0]?.length > 0; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: web/src/utils/dashboard/convertPanelData.ts
Line: 126:129
Comment:
**syntax:** potential issue with data structure check
The check `data[0]?.length > 0` for SQL query type may not work correctly. Based on the codebase, SQL query data appears to be an array where `data[0]` is itself an array, so checking `data[0]?.length > 0` is correct. However, for PromQL data, `data[0].result` is an array. The current check lacks optional chaining:
```suggestion
const hasData =
panelSchema?.queryType === "promql"
? data.length > 0 && data[0]?.result?.length > 0
: data.length > 0 && data[0]?.length > 0;
```
How can I resolve this? If you propose a fix, please make it concise.
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| 1 test failed | 366 | 345 | 1 | 19 | 1 | 94% | 6m 53s |
Test Failure Analysis
- dashboard-filter.spec.js: Timeout issues during page load and DOM stabilization
- dashboard filter testcases Should display an error message if added the invalid operator: Timeout waiting for page to reach 'networkidle' state.
Root Cause Analysis
- The code changes in QueryTypeSelector.vue may have affected the timing of the page load, leading to the timeout error.
Recommended Actions
- Increase the timeout duration in the test to accommodate longer load times.
- Investigate the impact of recent changes in QueryTypeSelector.vue on the dashboard loading process.
- Add explicit waits for critical elements to ensure the page is fully loaded before proceeding.
7f17f9d to
2e460e9
Compare
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 366 | 344 | 0 | 19 | 3 | 94% | 4m 40s |
No description provided.