Skip to content

Commit

Permalink
[8.x] [One Discover] Add AIAssistant prompts to logs overview detail (e…
Browse files Browse the repository at this point in the history
…lastic#204339) (elastic#204910)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[One Discover] Add AIAssistant prompts to logs overview detail
(elastic#204339)](elastic#204339)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco Antonio
Ghiani","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-19T10:37:08Z","message":"[One
Discover] Add AIAssistant prompts to logs overview detail
(elastic#204339)\n\n## 📓 Summary\r\n\r\nCloses elastic#202191 \r\n\r\nThis work brings
into the O11y solution contextual experience in\r\nDiscover the Logs AI
Assistant prompts already adopted in LogStream and\r\nLogs Explorer,
which are now set for deprecation in favour of the unique\r\nOneDiscover
experience.\r\n\r\nThe AIAssistant is consumed by the `discover-shared`
features registry,\r\nwhich registers the features from the logs-shared
plugin. Once the\r\ncodebase for LogStream and Logs Explorer that
consume this component is\r\nremoved, it might make sense to do some
clean-up and move the\r\nLogsAIAssistant component implementation among
the other contextual\r\ncomponents (log summary columns,
etc...).\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f97d5a01-3896-4a86-9a3c-443151a9d04e\r\n\r\nCo-authored-by:
Marco Antonio Ghiani
<[email protected]>","sha":"8b3281d4843efff3be4d291453c1aa6a61cd75fc","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-logs","Project:OneDiscover"],"title":"[One
Discover] Add AIAssistant prompts to logs overview
detail","number":204339,"url":"https://github.com/elastic/kibana/pull/204339","mergeCommit":{"message":"[One
Discover] Add AIAssistant prompts to logs overview detail
(elastic#204339)\n\n## 📓 Summary\r\n\r\nCloses elastic#202191 \r\n\r\nThis work brings
into the O11y solution contextual experience in\r\nDiscover the Logs AI
Assistant prompts already adopted in LogStream and\r\nLogs Explorer,
which are now set for deprecation in favour of the unique\r\nOneDiscover
experience.\r\n\r\nThe AIAssistant is consumed by the `discover-shared`
features registry,\r\nwhich registers the features from the logs-shared
plugin. Once the\r\ncodebase for LogStream and Logs Explorer that
consume this component is\r\nremoved, it might make sense to do some
clean-up and move the\r\nLogsAIAssistant component implementation among
the other contextual\r\ncomponents (log summary columns,
etc...).\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f97d5a01-3896-4a86-9a3c-443151a9d04e\r\n\r\nCo-authored-by:
Marco Antonio Ghiani
<[email protected]>","sha":"8b3281d4843efff3be4d291453c1aa6a61cd75fc"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204339","number":204339,"mergeCommit":{"message":"[One
Discover] Add AIAssistant prompts to logs overview detail
(elastic#204339)\n\n## 📓 Summary\r\n\r\nCloses elastic#202191 \r\n\r\nThis work brings
into the O11y solution contextual experience in\r\nDiscover the Logs AI
Assistant prompts already adopted in LogStream and\r\nLogs Explorer,
which are now set for deprecation in favour of the unique\r\nOneDiscover
experience.\r\n\r\nThe AIAssistant is consumed by the `discover-shared`
features registry,\r\nwhich registers the features from the logs-shared
plugin. Once the\r\ncodebase for LogStream and Logs Explorer that
consume this component is\r\nremoved, it might make sense to do some
clean-up and move the\r\nLogsAIAssistant component implementation among
the other contextual\r\ncomponents (log summary columns,
etc...).\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f97d5a01-3896-4a86-9a3c-443151a9d04e\r\n\r\nCo-authored-by:
Marco Antonio Ghiani
<[email protected]>","sha":"8b3281d4843efff3be4d291453c1aa6a61cd75fc"}}]}]
BACKPORT-->

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
  • Loading branch information
kibanamachine and tonyghiani authored Dec 19, 2024
1 parent 8a46374 commit f93a9c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ProfileProviderServices } from '../profile_providers/profile_provider_s
import { ProfilesManager } from '../profiles_manager';
import { DiscoverEBTManager } from '../../services/discover_ebt_manager';
import { createLogsContextServiceMock } from '@kbn/discover-utils/src/__mocks__';
import { discoverSharedPluginMock } from '@kbn/discover-shared-plugin/public/mocks';

export const createContextAwarenessMocks = ({
shouldRegisterProviders = true,
Expand Down Expand Up @@ -181,5 +182,6 @@ export const createContextAwarenessMocks = ({
const createProfileProviderServicesMock = () => {
return {
logsContextService: createLogsContextServiceMock(),
discoverShared: discoverSharedPluginMock.createStartContract(),
} as ProfileProviderServices;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import { i18n } from '@kbn/i18n';
import { UnifiedDocViewerLogsOverview } from '@kbn/unified-doc-viewer-plugin/public';
import React from 'react';
import type { DocumentProfileProvider } from '../../../../profiles';
import { ProfileProviderServices } from '../../../profile_provider_services';

export const getDocViewer: DocumentProfileProvider['profile']['getDocViewer'] =
(prev) => (params) => {
export const createGetDocViewer =
(services: ProfileProviderServices): DocumentProfileProvider['profile']['getDocViewer'] =>
(prev) =>
(params) => {
const prevDocViewer = prev(params);

const logsAIAssistantFeature = services.discoverShared.features.registry.getById(
'observability-logs-ai-assistant'
);

return {
...prevDocViewer,
docViewsRegistry: (registry) => {
Expand All @@ -25,7 +32,12 @@ export const getDocViewer: DocumentProfileProvider['profile']['getDocViewer'] =
defaultMessage: 'Log overview',
}),
order: 0,
component: (props) => <UnifiedDocViewerLogsOverview {...props} />,
component: (props) => (
<UnifiedDocViewerLogsOverview
{...props}
renderAIAssistant={logsAIAssistantFeature?.render}
/>
),
});

return prevDocViewer.docViewsRegistry(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { getDocViewer } from './get_doc_viewer';
export { createGetDocViewer } from './get_doc_viewer';
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import { DataTableRecord } from '@kbn/discover-utils';
import { DocumentProfileProvider, DocumentType } from '../../../profiles';
import { ProfileProviderServices } from '../../profile_provider_services';
import { getDocViewer } from './accessors';
import { createGetDocViewer } from './accessors';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';

export const createObservabilityLogDocumentProfileProvider = (
services: ProfileProviderServices
): DocumentProfileProvider => ({
profileId: 'observability-log-document-profile',
profile: {
getDocViewer,
getDocViewer: createGetDocViewer(services),
},
resolve: ({ record, rootContext }) => {
if (rootContext.profileId !== OBSERVABILITY_ROOT_PROFILE_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export const LogAIAssistant = ({
return undefined;
}

const message = doc.fields.find((field) => field.field === 'message')?.value[0];

if (!message) {
return undefined;
}

return getContextualInsightMessages({
message:
'Can you explain what this log message means? Where it could be coming from, whether it is expected and whether it is an issue.',
Expand All @@ -53,6 +59,10 @@ export const LogAIAssistant = ({

const message = doc.fields.find((field) => field.field === 'message')?.value[0];

if (!message) {
return undefined;
}

return getContextualInsightMessages({
message: `I'm looking at a log entry. Can you construct a Kibana KQL query that I can enter in the search bar that gives me similar log entries, based on the message field?`,
instructions: JSON.stringify({
Expand All @@ -61,7 +71,9 @@ export const LogAIAssistant = ({
});
}, [getContextualInsightMessages, doc]);

return (
const hasAtLeastOnePrompt = Boolean(explainLogMessageMessages || similarLogMessageMessages);

return hasAtLeastOnePrompt ? (
<EuiFlexGroup direction="column" gutterSize="m">
{ObservabilityAIAssistantContextualInsight && explainLogMessageMessages ? (
<EuiFlexItem grow={false}>
Expand All @@ -82,7 +94,7 @@ export const LogAIAssistant = ({
</EuiFlexItem>
) : null}
</EuiFlexGroup>
);
) : null;
};

// eslint-disable-next-line import/no-default-export
Expand Down

0 comments on commit f93a9c9

Please sign in to comment.