feat(elasticsearch): add ES SQL query mode with SQL builder - #2293
Conversation
- Gate DSL/SQL switching behind cluster is_sql_supported (plus only) - Support Builder/Code edit modes via shared SQLBuilderModal - Preserve sql syntax in dashboard migrator and query contract - Strip editor-only fields (editMode, builderConfig, stale sql/keys) on submit
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (27)
📝 WalkthroughWalkthroughElasticsearch and OpenSearch queries now support SQL syntax in dashboards, alerts, graph previews, and recording rules. The changes add SQL editors, a SQL builder, capability checks, SQL-aware serialization, migration handling, validation, tests, and translations. ChangesElasticsearch SQL support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant QueryEditor
participant SQLBuilderModal
participant ElasticsearchService
participant DashboardRenderer
User->>QueryEditor: Select SQL mode
QueryEditor->>SQLBuilderModal: Open Builder
SQLBuilderModal->>ElasticsearchService: Build SQL query
ElasticsearchService-->>SQLBuilderModal: Return SQL and builder configuration
SQLBuilderModal-->>QueryEditor: Update SQL, mode, and keys
QueryEditor->>DashboardRenderer: Submit serialized SQL target
DashboardRenderer->>ElasticsearchService: Execute SQL data request
ElasticsearchService-->>DashboardRenderer: Return query data
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…query type - Extract inline valueKey validation into hasESValueKey helper in dashboard datasource registry, using native type narrowing for safer checks. - Add optional ref field to esSQLDsQuery query type to match existing usage in GraphPreview and align with esLogsQuery.
editMode records the SQL Builder/Code view state and must be saved with the rule config so it can be restored on re-edit. It is no longer omitted from the query payload; query APIs do not consume it. builderConfig stays stripped as Builder draft state, and ES DSL queries still clear leftover sql/keys.
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed issues that can break TypeScript builds and/or cause UI/query payload inconsistencies when SQL is not supported.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an Elasticsearch SQL query mode (Plus-only) with a shared SQL Builder modal, and updates dashboard + alert-rule query contracts/migration so SQL mode can be persisted and executed consistently.
Changes:
- Introduce a reusable
SQLBuilderModaland integrate SQL (DSL/SQL + Builder/Code) switching into Dashboard and AlertRule Elasticsearch query editors. - Extend ES datasource query payloads/contracts (incl.
refsupport) and preservesyntax: 'sql'across dashboard migration/serialization. - Add/extend i18n strings and regression tests for the updated query contract + form submission behavior.
File summaries
| File | Description |
|---|---|
| src/plugins/elasticsearch/services.ts | Extend ES query request typing (adds optional ref). |
| src/plugins/elasticsearch/RecordingRules/Queries/index.tsx | Add ES SQL query config UI for recording rules (Plus-only, SQL-supported clusters). |
| src/plugins/elasticsearch/locale/zh_HK.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/zh_CN.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/ru_RU.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/pt_BR.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/ko_KR.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/ja_JP.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/id_ID.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/fr_FR.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/es_ES.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/locale/en_US.ts | Add SQL/builder/dashboard-mode translation keys. |
| src/plugins/elasticsearch/index.tsx | Export ES recording-rule query builder entry point. |
| src/plugins/elasticsearch/components/SQLBuilderModal.tsx | New shared SQL builder modal component (Plus query builder integration). |
| src/plugins/elasticsearch/AlertRule/Queries/Query.tsx | Add DSL/SQL switching + Builder/Code UX for ES alert-rule queries. |
| src/plugins/elasticsearch/AlertRule/Queries/index.tsx | Gate ES SQL support by cluster capability and pass into query UI. |
| src/plugins/elasticsearch/AlertRule/GraphPreview.tsx | Add SQL preview execution path for ES alert rules. |
| src/plugins/doris/RecordingRules/Queries/index.tsx | Comment clarification for builder switch behavior (no functional change). |
| src/plugins/doris/Dashboard/QueryBuilder.tsx | Comment clarification for builder switch behavior (no functional change). |
| src/plugins/doris/AlertRule/Query.tsx | Comment clarification for builder switch behavior (no functional change). |
| src/pages/dashboard/Renderer/datasource/registry.ts | Update readiness + serialization for ES SQL and strip builder-only fields. |
| src/pages/dashboard/Renderer/datasource/contract.test.ts | Add contract coverage for ES SQL timeSeries/raw request building. |
| src/pages/dashboard/Editor/QueryEditor/Elasticsearch/QueryPanel.tsx | Add DSL/SQL switching + Builder/Code UX for ES dashboard queries. |
| src/pages/dashboard/Detail/utils/dashboardMigrator.ts | Preserve syntax: 'sql' during v4 migration for ES/OpenSearch. |
| src/pages/dashboard/Detail/utils/dashboardMigrator.test.ts | Add/adjust tests to ensure SQL syntax is preserved during migration. |
| src/pages/alertRules/Form/utils.ts | Strip builderConfig/stale SQL fields on submit while preserving desired SQL state. |
| src/pages/alertRules/Form/utils.test.ts | Add regression tests for new ES SQL submission behavior. |
Review details
- Files reviewed: 27/27 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const hasESValueKey = (keys: unknown) => { | ||
| if (!keys || typeof keys !== 'object' || Array.isArray(keys) || !('valueKey' in keys)) return false; | ||
| const valueKey = keys.valueKey; | ||
| return Array.isArray(valueKey) ? valueKey.length > 0 : typeof valueKey === 'string' && valueKey.trim().length > 0; | ||
| }; |
| useEffect(() => { | ||
| setSupportsSQL(false); | ||
| if (!IS_PLUS || !datasourceValue) return; | ||
| getESClusterInfo({ cate: esDatasourceCate, datasource_id: datasourceValue }) | ||
| .then((info) => setSupportsSQL(info?.is_sql_supported ?? false)) | ||
| .catch(() => setSupportsSQL(false)); | ||
| }, [datasourceValue, esDatasourceCate]); |
| const names = ['rule_config', 'queries']; | ||
| const queries = Form.useWatch(names); | ||
| const savedSyntax = Form.useWatch([...names, field.name, 'syntax']); | ||
| const syntax = supportsSQL && savedSyntax === 'sql' ? 'sql' : 'dsl'; | ||
| const indexType = Form.useWatch([...names, field.name, 'index_type']); | ||
| const indexValue = Form.useWatch([...names, field.name, 'index']); | ||
| const indexPatternId = Form.useWatch([...names, field.name, 'index_pattern']); | ||
| const query = queries?.[field.name]; | ||
| const editMode = query?.editMode ?? 'code'; | ||
| const [builderModalVisible, setBuilderModalVisible] = useState(false); | ||
| const form = Form.useFormInstance(); | ||
| const curIndexValue = useMemo(() => { |
| search_mode: esIndexMode !== 'all' ? esIndexMode : 'indices', | ||
| query: { range }, | ||
| }); | ||
| }, [visible, builderConfig, range, form]); |
| } | ||
| // Builder configuration is editor state used to reopen the builder. The | ||
| // datasource query APIs only need the generated query fields. | ||
| delete payload.builderConfig; |
|
每日 i18n Review(2026-09-09)发现本 PR 新增的 |
Summary by CodeRabbit