From 8ea5257332ddfab66b1f1869c42dffedd89d45da Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Thu, 19 Dec 2024 11:37:08 +0100 Subject: [PATCH] [One Discover] Add AIAssistant prompts to logs overview detail (#204339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📓 Summary Closes #202191 This work brings into the O11y solution contextual experience in Discover the Logs AI Assistant prompts already adopted in LogStream and Logs Explorer, which are now set for deprecation in favour of the unique OneDiscover experience. The AIAssistant is consumed by the `discover-shared` features registry, which registers the features from the logs-shared plugin. Once the codebase for LogStream and Logs Explorer that consume this component is removed, it might make sense to do some clean-up and move the LogsAIAssistant component implementation among the other contextual components (log summary columns, etc...). https://github.com/user-attachments/assets/f97d5a01-3896-4a86-9a3c-443151a9d04e Co-authored-by: Marco Antonio Ghiani (cherry picked from commit 8b3281d4843efff3be4d291453c1aa6a61cd75fc) --- .../accessors/get_doc_viewer.tsx | 18 +++++++++++++++--- .../log_document_profile/accessors/index.ts | 2 +- .../log_document_profile/profile.tsx | 4 ++-- .../log_ai_assistant/log_ai_assistant.tsx | 16 ++++++++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/get_doc_viewer.tsx b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/get_doc_viewer.tsx index 1d433b5272d7b..89bb1166d7a2c 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/get_doc_viewer.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/get_doc_viewer.tsx @@ -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) => { @@ -25,7 +32,12 @@ export const getDocViewer: DocumentProfileProvider['profile']['getDocViewer'] = defaultMessage: 'Log overview', }), order: 0, - component: (props) => , + component: (props) => ( + + ), }); return prevDocViewer.docViewsRegistry(registry); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/index.ts index 6612fbc50e5c6..19941fc188720 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/index.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/accessors/index.ts @@ -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'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/profile.tsx b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/profile.tsx index e92bbb9a59605..7d7662fbf20b4 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/profile.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/observability/log_document_profile/profile.tsx @@ -10,7 +10,7 @@ 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 = ( @@ -18,7 +18,7 @@ export const createObservabilityLogDocumentProfileProvider = ( ): DocumentProfileProvider => ({ profileId: 'observability-log-document-profile', profile: { - getDocViewer, + getDocViewer: createGetDocViewer(services), }, resolve: ({ record, rootContext }) => { if (rootContext.profileId !== OBSERVABILITY_ROOT_PROFILE_ID) { diff --git a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx index 3e1b6fced3337..6e570f5824d17 100644 --- a/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx +++ b/x-pack/plugins/observability_solution/logs_shared/public/components/log_ai_assistant/log_ai_assistant.tsx @@ -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.', @@ -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({ @@ -61,7 +71,9 @@ export const LogAIAssistant = ({ }); }, [getContextualInsightMessages, doc]); - return ( + const hasAtLeastOnePrompt = Boolean(explainLogMessageMessages || similarLogMessageMessages); + + return hasAtLeastOnePrompt ? ( {ObservabilityAIAssistantContextualInsight && explainLogMessageMessages ? ( @@ -82,7 +94,7 @@ export const LogAIAssistant = ({ ) : null} - ); + ) : null; }; // eslint-disable-next-line import/no-default-export