From d4d8dbcf61d7441598267b6a315933c5c57d32c2 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 23 Jan 2024 15:50:24 -0800 Subject: [PATCH] [2.x] Backport query assist (#1369) Signed-off-by: Joshua Li Co-authored-by: Paul Sebastian --- common/constants/data_sources.ts | 2 + common/constants/explorer.ts | 1 + common/constants/query_assist.ts | 12 + common/constants/shared.ts | 4 + opensearch_dashboards.json | 8 +- public/.DS_Store | Bin 6148 -> 0 bytes .../common/live_tail/live_tail_button.tsx | 12 +- .../__snapshots__/search.test.tsx.snap | 1826 +++++++++-------- .../common/search/__tests__/search.test.tsx | 10 +- .../components/common/search/date_picker.tsx | 49 +- .../components/common/search/query_area.tsx | 83 + .../search/query_assist_summarization.tsx | 111 + public/components/common/search/search.tsx | 525 +++-- .../components/common/search/sql_search.tsx | 4 +- .../icons/query-assistant-logo.svg | 18 + .../__snapshots__/no_results.test.tsx.snap | 236 ++- .../__tests__/no_results.test.tsx | 16 +- .../datasources/datasources_selection.tsx | 28 +- .../explorer/events_views/data_grid.tsx | 138 +- .../event_analytics/explorer/explorer.tsx | 231 ++- .../event_analytics/explorer/no_results.tsx | 129 +- .../query_assist/__tests__/hooks.test.ts | 127 ++ .../query_assist/__tests__/input.test.tsx | 123 ++ .../explorer/query_assist/hooks.ts | 89 + .../explorer/query_assist/input.tsx | 377 ++++ .../__snapshots__/sidebar.test.tsx.snap | 555 +++-- .../sidebar/__tests__/sidebar.test.tsx | 36 +- .../explorer/sidebar/field.tsx | 31 +- .../explorer/sidebar/sidebar.tsx | 10 +- .../components/event_analytics/home/home.tsx | 2 +- .../event_analytics/hooks/use_fetch_events.ts | 71 +- .../hooks/use_fetch_patterns.ts | 10 +- .../hooks/use_fetch_visualizations.ts | 13 +- .../redux/reducers/fetch_reducers.ts | 4 + .../event_analytics/redux/reducers/index.ts | 2 +- .../query_assistant_summarization_slice.ts | 50 + .../redux/slices/query_result_slice.ts | 12 +- .../redux/slices/query_slice.ts | 8 +- .../redux/slices/search_meta_data_slice.ts | 15 +- .../metrics/redux/slices/metrics_slice.ts | 17 +- public/components/metrics/sidebar/sidebar.tsx | 5 +- public/framework/core_refs.ts | 12 +- public/framework/redux/reducers/index.ts | 2 + public/index.ts | 14 +- public/plugin.ts | 61 +- .../data_fetchers/ppl/ppl_data_fetcher.ts | 9 +- .../__tests__/generate_field_context.test.ts | 95 + .../query_assist/generate_field_context.ts | 71 + server/index.ts | 42 +- server/plugin.ts | 20 +- server/routes/index.ts | 41 +- server/routes/query_assist/routes.ts | 158 ++ .../utils/__tests__/agents.test.ts | 125 ++ server/routes/query_assist/utils/agents.ts | 96 + 54 files changed, 4001 insertions(+), 1745 deletions(-) create mode 100644 common/constants/query_assist.ts delete mode 100644 public/.DS_Store create mode 100644 public/components/common/search/query_area.tsx create mode 100644 public/components/common/search/query_assist_summarization.tsx create mode 100644 public/components/datasources/icons/query-assistant-logo.svg create mode 100644 public/components/event_analytics/explorer/query_assist/__tests__/hooks.test.ts create mode 100644 public/components/event_analytics/explorer/query_assist/__tests__/input.test.tsx create mode 100644 public/components/event_analytics/explorer/query_assist/hooks.ts create mode 100644 public/components/event_analytics/explorer/query_assist/input.tsx create mode 100644 public/components/event_analytics/redux/slices/query_assistant_summarization_slice.ts create mode 100644 server/common/helpers/query_assist/__tests__/generate_field_context.test.ts create mode 100644 server/common/helpers/query_assist/generate_field_context.ts create mode 100644 server/routes/query_assist/routes.ts create mode 100644 server/routes/query_assist/utils/__tests__/agents.test.ts create mode 100644 server/routes/query_assist/utils/agents.ts diff --git a/common/constants/data_sources.ts b/common/constants/data_sources.ts index 931f1f7290..7918516628 100644 --- a/common/constants/data_sources.ts +++ b/common/constants/data_sources.ts @@ -5,6 +5,8 @@ export const DATA_SOURCE_NAME_URL_PARAM_KEY = 'datasourceName'; export const DATA_SOURCE_TYPE_URL_PARAM_KEY = 'datasourceType'; +export const OLLY_QUESTION_URL_PARAM_KEY = 'olly_q'; +export const INDEX_URL_PARAM_KEY = 'indexPattern'; export const DEFAULT_DATA_SOURCE_TYPE = 'DEFAULT_INDEX_PATTERNS'; export const DEFAULT_DATA_SOURCE_NAME = 'Default cluster'; export const DEFAULT_DATA_SOURCE_OBSERVABILITY_DISPLAY_NAME = 'OpenSearch'; diff --git a/common/constants/explorer.ts b/common/constants/explorer.ts index 187d5d40c3..d94957c3e8 100644 --- a/common/constants/explorer.ts +++ b/common/constants/explorer.ts @@ -18,6 +18,7 @@ export const RAW_QUERY = 'rawQuery'; export const FINAL_QUERY = 'finalQuery'; export const SELECTED_DATE_RANGE = 'selectedDateRange'; export const INDEX = 'index'; +export const OLLY_QUERY_ASSISTANT = 'ollyQueryAssistant'; export const SELECTED_PATTERN_FIELD = 'selectedPatternField'; export const PATTERN_REGEX = 'patternRegex'; export const FILTERED_PATTERN = 'filteredPattern'; diff --git a/common/constants/query_assist.ts b/common/constants/query_assist.ts new file mode 100644 index 0000000000..04b38c1299 --- /dev/null +++ b/common/constants/query_assist.ts @@ -0,0 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +const QUERY_ASSIST_API_PREFIX = '/api/observability/query_assist'; +export const QUERY_ASSIST_API = { + GENERATE_PPL: `${QUERY_ASSIST_API_PREFIX}/generate_ppl`, + SUMMARIZE: `${QUERY_ASSIST_API_PREFIX}/summarize`, +}; + +export const ML_COMMONS_API_PREFIX = '/_plugins/_ml'; diff --git a/common/constants/shared.ts b/common/constants/shared.ts index 9baffcf101..63437dcfaa 100644 --- a/common/constants/shared.ts +++ b/common/constants/shared.ts @@ -256,3 +256,7 @@ export const S3_DATASOURCE_TYPE = 'S3_DATASOURCE'; export const ASYNC_QUERY_SESSION_ID = 'async-query-session-id'; export const DIRECT_DUMMY_QUERY = 'select 1'; + +export const DEFAULT_START_TIME = 'now-15m'; +export const QUERY_ASSIST_START_TIME = 'now-40y'; +export const QUERY_ASSIST_END_TIME = 'now'; diff --git a/opensearch_dashboards.json b/opensearch_dashboards.json index 98de7b0886..1c41f1eac3 100644 --- a/opensearch_dashboards.json +++ b/opensearch_dashboards.json @@ -18,8 +18,6 @@ "urlForwarding", "visualizations" ], - "optionalPlugins": [ - "managementOverview", - "assistantDashboards" - ] -} \ No newline at end of file + "optionalPlugins": ["managementOverview", "assistantDashboards"], + "configPath": ["observability"] +} diff --git a/public/.DS_Store b/public/.DS_Store deleted file mode 100644 index dbd07c1a1c1d289c1b490405a326e8a55ae29325..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ8r^25S>XVP-t9I?iIMf%5qNN3m_#C4KXMr)UI+aj>emhq98+&f+l(+&Ai>& zd29I<9*>A<`}MjKX+&fWH%Fk~B9M^^Pys6Nqkw%M3f!hP6`=yd49* i9b;qdc*nm7hJ9eJk%`7>a;(5S$@6*vQa;1$mR diff --git a/public/components/common/live_tail/live_tail_button.tsx b/public/components/common/live_tail/live_tail_button.tsx index 0e53152fa3..66bb91591a 100644 --- a/public/components/common/live_tail/live_tail_button.tsx +++ b/public/components/common/live_tail/live_tail_button.tsx @@ -3,13 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -//Define pop over interval options for live tail button in your plugin +// Define pop over interval options for live tail button in your plugin -import { EuiButton } from "@elastic/eui"; -import React, { useMemo } from "react"; -import { LiveTailProps } from "common/types/explorer"; +import { EuiButton } from '@elastic/eui'; +import React, { useMemo } from 'react'; +import { LiveTailProps } from 'common/types/explorer'; -//Live Tail Button +// Live Tail Button export const LiveTailButton = ({ isLiveTailOn, isLiveTailPopoverOpen, @@ -20,7 +20,7 @@ export const LiveTailButton = ({ const liveButton = useMemo(() => { return ( setIsLiveTailPopoverOpen(!isLiveTailPopoverOpen)} data-test-subj={dataTestSubj} diff --git a/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap index 4e2dfbde7a..eb6a831c68 100644 --- a/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap +++ b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap @@ -12,914 +12,1120 @@ exports[`Explorer Search component renders basic component 1`] = ` } } > - +
- +
- - PPL - - } - closePopover={[Function]} - display="inlineBlock" - hasArrow={true} - id="smallContextMenuExample" - isOpen={false} - ownFocus={true} - panelPaddingSize="none" +
-
- - + PPL + , + "value": "PPL", + }, + Object { + "inputDisplay": + DQL + , + "value": "DQL", + }, + ] + } + valueOfSelected="PPL" + > + + PPL + , + "value": "PPL", + }, + Object { + "inputDisplay": + DQL + , + "value": "DQL", + }, + ] + } + value="PPL" + /> + } + isOpen={false} + panelPaddingSize="none" + > + + [Function] + + } + buttonRef={[Function]} + className="euiInputPopover euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={true} + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + panelRef={[Function]} + > + +
+
+ +
+ + PPL + , + "value": "PPL", + }, + Object { + "inputDisplay": + DQL + , + "value": "DQL", + }, + ] + } + value="PPL" + > + + +
+
+ + + + PPL + , + } + } + > + + PPL + + } + > + Select an option: + +
+ PPL +
+
+ , is selected +
+
+
+
+ + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + +
+ - - - -
-
-
-
-
- -
- -
- + + + +
+ + - -