From 74fdd1b5f25c783ef95b3fddb2eaef03ff597345 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Tue, 30 Apr 2024 15:09:08 +0200 Subject: [PATCH] [Discover][Obs ai assistant] Set the index pattern on the context api to generate correct ES|QL queries etc (#182090) ## Summary Reverting the revert of https://github.com/elastic/kibana/pull/181001#issuecomment-2084827044 the only change is the removal of the ml plugin dependency from the obs-ai-assistant --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- src/plugins/discover/kibana.jsonc | 3 ++- .../main/components/layout/discover_layout.tsx | 11 +++++++++++ src/plugins/discover/public/build_services.ts | 3 +++ src/plugins/discover/public/plugin.tsx | 6 ++++++ src/plugins/discover/tsconfig.json | 3 ++- .../observability_ai_assistant/public/types.ts | 3 --- .../observability_ai_assistant/tsconfig.json | 1 - 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/plugins/discover/kibana.jsonc b/src/plugins/discover/kibana.jsonc index 17693545dd6d0..9b892ee79fe16 100644 --- a/src/plugins/discover/kibana.jsonc +++ b/src/plugins/discover/kibana.jsonc @@ -37,7 +37,8 @@ "savedObjectsTaggingOss", "lens", "noDataPage", - "globalSearch" + "globalSearch", + "observabilityAIAssistant" ], "requiredBundles": ["kibanaUtils", "kibanaReact", "unifiedSearch", "savedObjects"], "extraPublicDirs": ["common"] diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx index 344e0b36c9d0e..a104dc3c9d73b 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx @@ -71,6 +71,7 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { filterManager, history, spaces, + observabilityAIAssistant, } = useDiscoverServices(); const pageBackgroundColor = useEuiBackgroundColor('plain'); const globalQueryState = data.query.getState(); @@ -132,6 +133,16 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) { sort, }); + // The assistant is getting the state from the url correctly + // expect from the index pattern where we have only the dataview id + useEffect(() => { + return observabilityAIAssistant?.service.setScreenContext({ + screenDescription: `The user is looking at the Discover view on the ${ + isPlainRecord ? 'ES|QL' : 'dataView' + } mode. The index pattern is the ${dataView.getIndexPattern()}`, + }); + }, [dataView, isPlainRecord, observabilityAIAssistant?.service]); + const onAddFilter = useCallback( (field: DataViewField | string, values: unknown, operation: '+' | '-') => { const fieldName = typeof field === 'string' ? field : field.name; diff --git a/src/plugins/discover/public/build_services.ts b/src/plugins/discover/public/build_services.ts index fc599bd59620e..7f7bcdee2154b 100644 --- a/src/plugins/discover/public/build_services.ts +++ b/src/plugins/discover/public/build_services.ts @@ -54,6 +54,7 @@ import type { LensPublicStart } from '@kbn/lens-plugin/public'; import type { UiActionsStart } from '@kbn/ui-actions-plugin/public'; import type { SettingsStart } from '@kbn/core-ui-settings-browser'; import type { ContentClient } from '@kbn/content-management-plugin/public'; +import type { ObservabilityAIAssistantPublicStart } from '@kbn/observability-ai-assistant-plugin/public'; import { memoize, noop } from 'lodash'; import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public'; import { DiscoverStartPlugins } from './plugin'; @@ -123,6 +124,7 @@ export interface DiscoverServices { uiActions: UiActionsStart; contentClient: ContentClient; noDataPage?: NoDataPagePluginStart; + observabilityAIAssistant?: ObservabilityAIAssistantPublicStart; } export const buildServices = memoize( @@ -203,6 +205,7 @@ export const buildServices = memoize( uiActions: plugins.uiActions, contentClient: plugins.contentManagement.client, noDataPage: plugins.noDataPage, + observabilityAIAssistant: plugins.observabilityAIAssistant, }; } ); diff --git a/src/plugins/discover/public/plugin.tsx b/src/plugins/discover/public/plugin.tsx index 46cbf95d299b1..902cc0a38e717 100644 --- a/src/plugins/discover/public/plugin.tsx +++ b/src/plugins/discover/public/plugin.tsx @@ -46,6 +46,10 @@ import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public'; import type { LensPublicStart } from '@kbn/lens-plugin/public'; import { TRUNCATE_MAX_HEIGHT, ENABLE_ESQL } from '@kbn/discover-utils'; import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public'; +import type { + ObservabilityAIAssistantPublicSetup, + ObservabilityAIAssistantPublicStart, +} from '@kbn/observability-ai-assistant-plugin/public'; import { PLUGIN_ID } from '../common'; import { registerFeature } from './register_feature'; import { buildServices, UrlTracker } from './build_services'; @@ -166,6 +170,7 @@ export interface DiscoverSetupPlugins { data: DataPublicPluginSetup; expressions: ExpressionsSetup; globalSearch?: GlobalSearchPluginSetup; + observabilityAIAssistant?: ObservabilityAIAssistantPublicSetup; } /** @@ -196,6 +201,7 @@ export interface DiscoverStartPlugins { lens: LensPublicStart; contentManagement: ContentManagementPublicStart; noDataPage?: NoDataPagePluginStart; + observabilityAIAssistant?: ObservabilityAIAssistantPublicStart; } export type StartRenderServices = Pick; diff --git a/src/plugins/discover/tsconfig.json b/src/plugins/discover/tsconfig.json index b10dee36e3fb7..6b576f3a08c1a 100644 --- a/src/plugins/discover/tsconfig.json +++ b/src/plugins/discover/tsconfig.json @@ -83,7 +83,8 @@ "@kbn/deeplinks-analytics", "@kbn/shared-ux-markdown", "@kbn/data-view-utils", - "@kbn/presentation-publishing" + "@kbn/presentation-publishing", + "@kbn/observability-ai-assistant-plugin" ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts index 0567324e164dc..69a1a6821197b 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/public/types.ts @@ -6,7 +6,6 @@ */ import type { LicensingPluginStart } from '@kbn/licensing-plugin/public'; -import type { MlPluginSetup, MlPluginStart } from '@kbn/ml-plugin/public'; import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/public'; import { TriggersAndActionsUIPublicPluginStart } from '@kbn/triggers-actions-ui-plugin/public'; import type { Observable } from 'rxjs'; @@ -104,13 +103,11 @@ export interface ConfigSchema {} export interface ObservabilityAIAssistantPluginSetupDependencies { licensing: {}; security: SecurityPluginSetup; - ml: MlPluginSetup; } export interface ObservabilityAIAssistantPluginStartDependencies { licensing: LicensingPluginStart; security: SecurityPluginStart; - ml: MlPluginStart; triggersActionsUi: TriggersAndActionsUIPublicPluginStart; } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json b/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json index cc66498fa5d4e..b3fe0f8c8f6fc 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json @@ -41,7 +41,6 @@ "@kbn/babel-register", "@kbn/dev-cli-runner", "@kbn/core-analytics-browser", - "@kbn/ml-plugin", "@kbn/expect", "@kbn/apm-synthtrace-client", "@kbn/apm-synthtrace",