Skip to content

Commit

Permalink
[Discover][Obs ai assistant] Set the index pattern on the context api…
Browse files Browse the repository at this point in the history
… to generate correct ES|QL queries etc (#181001)

## Summary

Sets the index pattern correctly in the obs ai assistant. 
The Obs ai assistant is part of Discover in serverless Oblt project and
can also be set up everywhere from the Observability AI Assistant scope
advanced setting. It is a very useful tool for the Discover users and
for moving from KQL to ES|QL world.

This is important for prompts such as:

- Transform the KQL and filters to ES|QL


![meow](https://github.com/elastic/kibana/assets/17003240/e9b1be13-667a-4fdb-addb-fb77e485b99e)

- More

<img width="579" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/91b6b0ac-754f-47f3-98a2-ed09e7be646b">


Other interesting prompts:

- Equivalent of KQL of where filters

<img width="640" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/f203bc5e-a037-49c9-9e6c-5e68c9fcb864">

- Explain the ES|QL query
<img width="658" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/b2f9abfb-577d-4c06-b715-553ebd626e28">


- Run questions on your dataset and unified search bar selection
<img width="687" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/e095ced8-5bf9-4846-ac54-644c4fd8de04">

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
stratoula and kibanamachine authored Apr 30, 2024
1 parent 36493be commit 9edb9d5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/plugins/discover/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"savedObjectsTaggingOss",
"lens",
"noDataPage",
"globalSearch"
"globalSearch",
"observabilityAIAssistant"
],
"requiredBundles": ["kibanaUtils", "kibanaReact", "unifiedSearch", "savedObjects"],
"extraPublicDirs": ["common"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function DiscoverLayout({ stateContainer }: DiscoverLayoutProps) {
filterManager,
history,
spaces,
observabilityAIAssistant,
} = useDiscoverServices();
const pageBackgroundColor = useEuiBackgroundColor('plain');
const globalQueryState = data.query.getState();
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -123,6 +124,7 @@ export interface DiscoverServices {
uiActions: UiActionsStart;
contentClient: ContentClient;
noDataPage?: NoDataPagePluginStart;
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
}

export const buildServices = memoize(
Expand Down Expand Up @@ -203,6 +205,7 @@ export const buildServices = memoize(
uiActions: plugins.uiActions,
contentClient: plugins.contentManagement.client,
noDataPage: plugins.noDataPage,
observabilityAIAssistant: plugins.observabilityAIAssistant,
};
}
);
6 changes: 6 additions & 0 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -166,6 +170,7 @@ export interface DiscoverSetupPlugins {
data: DataPublicPluginSetup;
expressions: ExpressionsSetup;
globalSearch?: GlobalSearchPluginSetup;
observabilityAIAssistant?: ObservabilityAIAssistantPublicSetup;
}

/**
Expand Down Expand Up @@ -196,6 +201,7 @@ export interface DiscoverStartPlugins {
lens: LensPublicStart;
contentManagement: ContentManagementPublicStart;
noDataPage?: NoDataPagePluginStart;
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
}

export type StartRenderServices = Pick<CoreStart, 'analytics' | 'i18n' | 'theme'>;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/discover/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*"]
}

0 comments on commit 9edb9d5

Please sign in to comment.