From 0e7ab20955aa73859883c1f07ab0ed519db563f7 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:49:07 +0100 Subject: [PATCH 1/4] Remove AI Assistant specific setting, replace with central log sources setting. Register log sources setting in serverless. --- .../settings/setting_ids/index.ts | 2 -- .../settings/observability_project/index.ts | 2 +- .../server/collectors/management/schema.ts | 4 --- .../server/collectors/management/types.ts | 1 - src/plugins/telemetry/schema/oss_plugins.json | 6 ---- .../get_log_categories/index.ts | 9 +++--- .../get_log_rate_analysis_for_alert/index.ts | 9 +++--- .../get_container_id_from_signals.ts | 13 ++++---- .../get_service_name_from_signals.ts | 15 +++++---- .../index.ts | 10 ++++-- .../log_sources_service.mocks.ts | 4 +++ .../services/log_sources_service/types.ts | 1 + .../services/log_sources_service/utils.ts | 11 +++++++ .../public/hooks/use_log_sources.ts | 3 +- .../services/log_sources_service/index.ts | 9 ++++-- .../services/log_sources_service/index.ts | 12 +++++-- .../common/ui_settings/settings_keys.ts | 4 ++- .../observability_ai_assistant/tsconfig.json | 1 + .../kibana.jsonc | 3 +- .../server/functions/changes/index.ts | 8 +++-- .../server/types.ts | 2 ++ .../tsconfig.json | 3 +- .../common/ui_settings.ts | 19 ------------ .../settings_tab/settings_tab.test.tsx | 31 +++++++++++++------ .../tsconfig.json | 3 +- .../translations/translations/fr-FR.json | 2 -- .../translations/translations/ja-JP.json | 2 -- .../translations/translations/zh-CN.json | 2 -- .../common/ui/index.ts | 3 +- 29 files changed, 105 insertions(+), 89 deletions(-) create mode 100644 x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/utils.ts diff --git a/packages/kbn-management/settings/setting_ids/index.ts b/packages/kbn-management/settings/setting_ids/index.ts index 9f0c226717079..3510bd0c9f9e3 100644 --- a/packages/kbn-management/settings/setting_ids/index.ts +++ b/packages/kbn-management/settings/setting_ids/index.ts @@ -143,8 +143,6 @@ export const OBSERVABILITY_LOGS_EXPLORER_ALLOWED_DATA_VIEWS_ID = 'observability:logsExplorer:allowedDataViews'; export const OBSERVABILITY_ENTITY_CENTRIC_EXPERIENCE = 'observability:entityCentricExperience'; export const OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID = 'observability:logSources'; -export const OBSERVABILITY_AI_ASSISTANT_LOGS_INDEX_PATTERN_ID = - 'observability:aiAssistantLogsIndexPattern'; export const OBSERVABILITY_AI_ASSISTANT_SIMULATED_FUNCTION_CALLING = 'observability:aiAssistantSimulatedFunctionCalling'; export const OBSERVABILITY_AI_ASSISTANT_SEARCH_CONNECTOR_INDEX_PATTERN = diff --git a/packages/serverless/settings/observability_project/index.ts b/packages/serverless/settings/observability_project/index.ts index bcaab96e8bd0a..605e42933f4f0 100644 --- a/packages/serverless/settings/observability_project/index.ts +++ b/packages/serverless/settings/observability_project/index.ts @@ -33,7 +33,7 @@ export const OBSERVABILITY_PROJECT_SETTINGS = [ settings.OBSERVABILITY_APM_ENABLE_TABLE_SEARCH_BAR, settings.OBSERVABILITY_APM_ENABLE_SERVICE_INVENTORY_TABLE_SEARCH_BAR, settings.OBSERVABILITY_ENTITY_CENTRIC_EXPERIENCE, - settings.OBSERVABILITY_AI_ASSISTANT_LOGS_INDEX_PATTERN_ID, settings.OBSERVABILITY_AI_ASSISTANT_SIMULATED_FUNCTION_CALLING, settings.OBSERVABILITY_AI_ASSISTANT_SEARCH_CONNECTOR_INDEX_PATTERN, + settings.OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID, ]; diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index 8bc81a6f1d497..98cc0504c11f5 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -483,10 +483,6 @@ export const stackManagementSchema: MakeSchemaFrom = { type: 'integer', _meta: { description: 'Non-default value of setting.' }, }, - 'observability:aiAssistantLogsIndexPattern': { - type: 'keyword', - _meta: { description: 'Non-default value of setting.' }, - }, 'observability:aiAssistantSimulatedFunctionCalling': { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts index 9821fd1bad43f..26ee28dd3f4b1 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts @@ -54,7 +54,6 @@ export interface UsageStats { 'observability:apmEnableServiceInventoryTableSearchBar': boolean; 'observability:logsExplorer:allowedDataViews': string[]; 'observability:logSources': string[]; - 'observability:aiAssistantLogsIndexPattern': string; 'observability:aiAssistantSimulatedFunctionCalling': boolean; 'observability:aiAssistantSearchConnectorIndexPattern': string; 'visualization:heatmap:maxBuckets': number; diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index 8563b5beaf57c..c1cb567ab9559 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -10450,12 +10450,6 @@ "description": "Non-default value of setting." } }, - "observability:aiAssistantLogsIndexPattern": { - "type": "keyword", - "_meta": { - "description": "Non-default value of setting." - } - }, "observability:aiAssistantSimulatedFunctionCalling": { "type": "boolean", "_meta": { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts index 41af9a4a0360d..5f36325031ccb 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts @@ -7,8 +7,7 @@ import datemath from '@elastic/datemath'; import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import type { CoreRequestHandlerContext } from '@kbn/core/server'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/server'; +import { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { flattenObject, KeyValuePair } from '../../../../common/utils/flatten_object'; import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; import { PROCESSOR_EVENT, TRACE_ID } from '../../../../common/es_fields/apm'; @@ -26,12 +25,12 @@ export interface LogCategory { export async function getLogCategories({ apmEventClient, esClient, - coreContext, + logSourcesService, arguments: args, }: { apmEventClient: APMEventClient; esClient: ElasticsearchClient; - coreContext: Pick; + logSourcesService: LogSourcesService; arguments: { start: string; end: string; @@ -53,7 +52,7 @@ export async function getLogCategories({ Object.entries(args.entities).map(([key, value]) => ({ field: key, value })) ); - const index = await coreContext.uiSettings.client.get(aiAssistantLogsIndexPattern); + const index = await logSourcesService.getFlattenedLogSources(); const search = getTypedSearch(esClient); const query = { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_rate_analysis_for_alert/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_rate_analysis_for_alert/index.ts index 097eff91ced14..2d367780fc9dd 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_rate_analysis_for_alert/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_rate_analysis_for_alert/index.ts @@ -6,9 +6,8 @@ */ import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import type { CoreRequestHandlerContext } from '@kbn/core/server'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/server'; import { fetchLogRateAnalysisForAlert } from '@kbn/aiops-log-rate-analysis/queries/fetch_log_rate_analysis_for_alert'; +import { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { PROCESSOR_EVENT } from '../../../../common/es_fields/apm'; import { getShouldMatchOrNotExistFilter } from '../utils/get_should_match_or_not_exist_filter'; @@ -17,11 +16,11 @@ import { getShouldMatchOrNotExistFilter } from '../utils/get_should_match_or_not */ export async function getLogRateAnalysisForAlert({ esClient, - coreContext, + logSourcesService, arguments: args, }: { esClient: ElasticsearchClient; - coreContext: Pick; + logSourcesService: LogSourcesService; arguments: { alertStartedAt: string; alertRuleParameterTimeSize?: number; @@ -34,7 +33,7 @@ export async function getLogRateAnalysisForAlert({ }; }; }): ReturnType { - const index = await coreContext.uiSettings.client.get(aiAssistantLogsIndexPattern); + const index = await logSourcesService.getFlattenedLogSources(); const keyValueFilters = getShouldMatchOrNotExistFilter( Object.entries(args.entities).map(([key, value]) => ({ field: key, value })) diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts index 638903e813545..e7f3ace07e2a1 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts @@ -7,12 +7,12 @@ import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { CoreRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/common'; import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries'; import * as t from 'io-ts'; import moment from 'moment'; import { ESSearchRequest } from '@kbn/es-types'; import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; +import { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { ApmDocumentType } from '../../../../common/document_type'; import { APMEventClient, @@ -23,11 +23,12 @@ import { RollupInterval } from '../../../../common/rollup'; export async function getContainerIdFromSignals({ query, esClient, - coreContext, + logSourcesService, apmEventClient, }: { query: t.TypeOf; esClient: ElasticsearchClient; + logSourcesService: LogSourcesService; coreContext: Pick; apmEventClient: APMEventClient; }) { @@ -66,19 +67,19 @@ export async function getContainerIdFromSignals({ return containerId; } - return getContainerIdFromLogs({ params, esClient, coreContext }); + return getContainerIdFromLogs({ params, esClient, logSourcesService }); } async function getContainerIdFromLogs({ params, esClient, - coreContext, + logSourcesService, }: { params: ESSearchRequest['body']; esClient: ElasticsearchClient; - coreContext: Pick; + logSourcesService: LogSourcesService; }) { - const index = await coreContext.uiSettings.client.get(aiAssistantLogsIndexPattern); + const index = await logSourcesService.getFlattenedLogSources(); const res = await typedSearch<{ container: { id: string } }, any>(esClient, { index, ...params, diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts index 284c286766c76..0168431d0ac4e 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts @@ -6,13 +6,12 @@ */ import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { CoreRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/common'; import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries'; import * as t from 'io-ts'; import moment from 'moment'; import { ESSearchRequest } from '@kbn/es-types'; import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; +import type { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { ApmDocumentType } from '../../../../common/document_type'; import { APMEventClient, @@ -23,12 +22,12 @@ import { RollupInterval } from '../../../../common/rollup'; export async function getServiceNameFromSignals({ query, esClient, - coreContext, + logSourcesService, apmEventClient, }: { query: t.TypeOf; esClient: ElasticsearchClient; - coreContext: Pick; + logSourcesService: LogSourcesService; apmEventClient: APMEventClient; }) { if (query['service.name']) { @@ -75,19 +74,19 @@ export async function getServiceNameFromSignals({ return serviceName; } - return getServiceNameFromLogs({ params, esClient, coreContext }); + return getServiceNameFromLogs({ params, esClient, logSourcesService }); } async function getServiceNameFromLogs({ params, esClient, - coreContext, + logSourcesService, }: { params: ESSearchRequest['body']; esClient: ElasticsearchClient; - coreContext: Pick; + logSourcesService: LogSourcesService; }) { - const index = await coreContext.uiSettings.client.get(aiAssistantLogsIndexPattern); + const index = await logSourcesService.getFlattenedLogSources(); const res = await typedSearch<{ service: { name: string } }, any>(esClient, { index, ...params, diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts index e0f3f833a5ae2..84e51675233c9 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts @@ -87,6 +87,9 @@ export const getAlertDetailsContextHandler = ( }), ]); const esClient = coreContext.elasticsearch.client.asCurrentUser; + const logSourcesService = await ( + await resourcePlugins.logsDataAccess.start() + ).services.logSourcesServiceFactory.getScopedLogSourcesService(requestContext.request); const alertStartedAt = query.alert_started_at; const serviceEnvironment = query['service.environment']; @@ -97,13 +100,14 @@ export const getAlertDetailsContextHandler = ( getServiceNameFromSignals({ query, esClient, - coreContext, + logSourcesService, apmEventClient, }), getContainerIdFromSignals({ query, esClient, coreContext, + logSourcesService, apmEventClient, }), ]); @@ -165,7 +169,7 @@ export const getAlertDetailsContextHandler = ( dataFetchers.push(async () => { const { logRateAnalysisType, significantItems } = await getLogRateAnalysisForAlert({ esClient, - coreContext, + logSourcesService, arguments: { alertStartedAt: moment(alertStartedAt).toISOString(), alertRuleParameterTimeSize: query.alert_rule_parameter_time_size @@ -203,7 +207,7 @@ export const getAlertDetailsContextHandler = ( const { logCategories, entities } = await getLogCategories({ apmEventClient, esClient, - coreContext, + logSourcesService, arguments: { start: moment(alertStartedAt).subtract(15, 'minute').toISOString(), end: alertStartedAt, diff --git a/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/log_sources_service.mocks.ts b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/log_sources_service.mocks.ts index 3f1f8b9db5979..8073adc35d627 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/log_sources_service.mocks.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/log_sources_service.mocks.ts @@ -6,6 +6,7 @@ */ import { LogSource, LogSourcesService } from './types'; +import { flattenLogSources } from './utils'; const LOG_SOURCES: LogSource[] = [{ indexPattern: 'logs-*-*' }]; export const createLogSourcesServiceMock = ( @@ -16,6 +17,9 @@ export const createLogSourcesServiceMock = ( async getLogSources() { return Promise.resolve(sources); }, + async getFlattenedLogSources() { + return Promise.resolve(flattenLogSources(sources)); + }, async setLogSources(nextLogSources: LogSource[]) { sources = nextLogSources; return Promise.resolve(); diff --git a/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/types.ts b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/types.ts index 0d4cb51051237..a2c1ae825c285 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/types.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/types.ts @@ -11,5 +11,6 @@ export interface LogSource { export interface LogSourcesService { getLogSources: () => Promise; + getFlattenedLogSources: () => Promise; setLogSources: (sources: LogSource[]) => Promise; } diff --git a/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/utils.ts b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/utils.ts new file mode 100644 index 0000000000000..e6c7faa1c1140 --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_data_access/common/services/log_sources_service/utils.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { LogSource } from './types'; + +export const flattenLogSources = (logSources: LogSource[]) => + logSources.map((source) => source.indexPattern).join(','); diff --git a/x-pack/plugins/observability_solution/logs_data_access/public/hooks/use_log_sources.ts b/x-pack/plugins/observability_solution/logs_data_access/public/hooks/use_log_sources.ts index ff463867a7a77..c69348c4c7275 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/public/hooks/use_log_sources.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/public/hooks/use_log_sources.ts @@ -8,6 +8,7 @@ import createContainer from 'constate'; import { useTrackedPromise } from '@kbn/use-tracked-promise'; import { useState, useEffect, useMemo } from 'react'; +import { flattenLogSources } from '../../common/services/log_sources_service/utils'; import { LogSource, LogSourcesService } from '../../common/services/log_sources_service/types'; export const useLogSources = ({ logSourcesService }: { logSourcesService: LogSourcesService }) => { @@ -35,7 +36,7 @@ export const useLogSources = ({ logSourcesService }: { logSourcesService: LogSou }, [getLogSources]); const combinedIndices = useMemo(() => { - return logSources.map((logSource) => logSource.indexPattern).join(','); + return flattenLogSources(logSources); }, [logSources]); return { diff --git a/x-pack/plugins/observability_solution/logs_data_access/public/services/log_sources_service/index.ts b/x-pack/plugins/observability_solution/logs_data_access/public/services/log_sources_service/index.ts index a75bbd65c26e3..f329907f145ef 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/public/services/log_sources_service/index.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/public/services/log_sources_service/index.ts @@ -6,19 +6,24 @@ */ import { OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID } from '@kbn/management-settings-ids'; +import { flattenLogSources } from '../../../common/services/log_sources_service/utils'; import { LogSource, LogSourcesService } from '../../../common/services/log_sources_service/types'; import { RegisterServicesParams } from '../register_services'; export function createLogSourcesService(params: RegisterServicesParams): LogSourcesService { const { uiSettings } = params.deps; return { - getLogSources: async () => { + async getLogSources() { const logSources = uiSettings.get(OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID); return logSources.map((logSource) => ({ indexPattern: logSource, })); }, - setLogSources: async (sources: LogSource[]) => { + async getFlattenedLogSources() { + const logSources = await this.getLogSources(); + return flattenLogSources(logSources); + }, + async setLogSources(sources: LogSource[]) { await uiSettings.set( OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID, sources.map((source) => source.indexPattern) diff --git a/x-pack/plugins/observability_solution/logs_data_access/server/services/log_sources_service/index.ts b/x-pack/plugins/observability_solution/logs_data_access/server/services/log_sources_service/index.ts index e8907d7537932..925deb53524cd 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/server/services/log_sources_service/index.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/server/services/log_sources_service/index.ts @@ -8,6 +8,7 @@ import type { KibanaRequest } from '@kbn/core-http-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID } from '@kbn/management-settings-ids'; +import { flattenLogSources } from '../../../common/services/log_sources_service/utils'; import { LogSource, LogSourcesService } from '../../../common/services/log_sources_service/types'; import { RegisterServicesParams } from '../register_services'; @@ -18,8 +19,8 @@ export function createLogSourcesServiceFactory(params: RegisterServicesParams) { ): Promise { const { uiSettings } = params.deps; const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); - return { - getLogSources: async () => { + const logSourcesService: LogSourcesService = { + async getLogSources() { const logSources = await uiSettingsClient.get( OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID ); @@ -27,13 +28,18 @@ export function createLogSourcesServiceFactory(params: RegisterServicesParams) { indexPattern: logSource, })); }, - setLogSources: async (sources: LogSource[]) => { + async getFlattenedLogSources() { + const logSources = await this.getLogSources(); + return flattenLogSources(logSources); + }, + async setLogSources(sources: LogSource[]) { return await uiSettingsClient.set( OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID, sources.map((source) => source.indexPattern) ); }, }; + return logSourcesService; }, async getScopedLogSourcesService(request: KibanaRequest): Promise { const { savedObjects } = params.deps; diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/common/ui_settings/settings_keys.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/common/ui_settings/settings_keys.ts index eae50d1116a8f..fdcb34f22ecde 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/common/ui_settings/settings_keys.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/common/ui_settings/settings_keys.ts @@ -5,8 +5,10 @@ * 2.0. */ +import { OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID } from '@kbn/management-settings-ids'; + // AI Assistant -export const aiAssistantLogsIndexPattern = 'observability:aiAssistantLogsIndexPattern'; +export const aiAssistantLogsIndexPattern = OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID; export const aiAssistantSimulatedFunctionCalling = 'observability:aiAssistantSimulatedFunctionCalling'; export const aiAssistantSearchConnectorIndexPattern = 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 cd314e65fec9a..9728a53d9e1df 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json @@ -42,6 +42,7 @@ "@kbn/core-ui-settings-server", "@kbn/server-route-repository-utils", "@kbn/inference-plugin", + "@kbn/management-settings-ids" ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/kibana.jsonc b/x-pack/plugins/observability_solution/observability_ai_assistant_app/kibana.jsonc index 1e02cbd1e7792..1414912d39164 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/kibana.jsonc +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/kibana.jsonc @@ -24,7 +24,8 @@ "ml", "alerting", "features", - "inference" + "inference", + "logsDataAccess" ], "requiredBundles": ["kibanaReact", "esqlDataGrid"], "optionalPlugins": ["cloud"], diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/functions/changes/index.ts b/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/functions/changes/index.ts index 987414214a17b..dc0e26ea9c777 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/functions/changes/index.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/functions/changes/index.ts @@ -7,7 +7,6 @@ import { omit, orderBy } from 'lodash'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import type { AggregationsAutoDateHistogramAggregation } from '@elastic/elasticsearch/lib/api/types'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/server'; import { createElasticsearchClient } from '../../clients/elasticsearch'; import type { FunctionRegistrationParameters } from '..'; import { @@ -25,6 +24,7 @@ export function registerChangesFunction({ logger, context: { core: corePromise }, }, + pluginsStart, }: FunctionRegistrationParameters) { functions.registerFunction( { @@ -41,7 +41,11 @@ export function registerChangesFunction({ const core = await corePromise; - const logsIndexPattern = await core.uiSettings.client.get(aiAssistantLogsIndexPattern); + const logSourcesService = + await pluginsStart.logsDataAccess.services.logSourcesServiceFactory.getLogSourcesService( + core.savedObjects.client + ); + const logsIndexPattern = await logSourcesService.getFlattenedLogSources(); const client = createElasticsearchClient({ client: core.elasticsearch.client.asCurrentUser, diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/types.ts b/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/types.ts index 320459d203f9e..fc39e0b7fb24e 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/types.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/server/types.ts @@ -36,6 +36,7 @@ import type { CloudSetup, CloudStart } from '@kbn/cloud-plugin/server'; import type { SecurityPluginSetup, SecurityPluginStart } from '@kbn/security-plugin/server'; import type { ObservabilityPluginSetup } from '@kbn/observability-plugin/server'; import type { InferenceServerStart, InferenceServerSetup } from '@kbn/inference-plugin/server'; +import type { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/server'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ObservabilityAIAssistantAppServerStart {} @@ -55,6 +56,7 @@ export interface ObservabilityAIAssistantAppPluginStartDependencies { cloud?: CloudStart; serverless?: ServerlessPluginStart; inference: InferenceServerStart; + logsDataAccess: LogsDataAccessPluginStart; } export interface ObservabilityAIAssistantAppPluginSetupDependencies { diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_app/tsconfig.json b/x-pack/plugins/observability_solution/observability_ai_assistant_app/tsconfig.json index 55d965c9c37e3..84fe8f0b93911 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_app/tsconfig.json +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_app/tsconfig.json @@ -72,7 +72,8 @@ "@kbn/esql-datagrid", "@kbn/alerting-comparators", "@kbn/core-lifecycle-browser", - "@kbn/inference-plugin" + "@kbn/inference-plugin", + "@kbn/logs-data-access-plugin" ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/common/ui_settings.ts b/x-pack/plugins/observability_solution/observability_ai_assistant_management/common/ui_settings.ts index f972eb5742a91..3319860de6610 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/common/ui_settings.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/common/ui_settings.ts @@ -9,30 +9,11 @@ import { schema } from '@kbn/config-schema'; import { UiSettingsParams } from '@kbn/core-ui-settings-common'; import { i18n } from '@kbn/i18n'; import { - aiAssistantLogsIndexPattern, aiAssistantSimulatedFunctionCalling, aiAssistantSearchConnectorIndexPattern, } from '@kbn/observability-ai-assistant-plugin/common'; export const uiSettings: Record = { - [aiAssistantLogsIndexPattern]: { - category: ['observability'], - name: i18n.translate( - 'xpack.observabilityAiAssistantManagement.settingsTab.h3.logIndexPatternLabel', - { defaultMessage: 'Logs index pattern' } - ), - value: 'logs-*', - description: i18n.translate( - 'xpack.observabilityAiAssistantManagement.settingsPage.logIndexPatternDescription', - { - defaultMessage: - 'Index pattern used by the AI Assistant when querying for logs. Logs are categorised and used for root cause analysis', - } - ), - schema: schema.string(), - type: 'string', - requiresPageReload: true, - }, [aiAssistantSimulatedFunctionCalling]: { category: ['observability'], name: i18n.translate( diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx index 807bde0557d8d..25ef46ddf03eb 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx @@ -11,9 +11,15 @@ import { render } from '../../../helpers/test_helper'; import { SettingsTab } from './settings_tab'; import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/server'; import { uiSettings } from '../../../../common/ui_settings'; +import { uiSettings as logsDataAccessUiSettings } from '@kbn/logs-data-access-plugin/common/ui_settings'; jest.mock('../../../hooks/use_app_context'); +const testUiSettings = { + ...uiSettings, + ...logsDataAccessUiSettings, +}; + describe('SettingsTab', () => { it('should offer a way to configure Observability AI Assistant visibility in apps', () => { const navigateToAppMock = jest.fn(() => Promise.resolve()); @@ -61,20 +67,28 @@ describe('SettingsTab', () => { settings: { client: { set: settingsClientSet, - getAll: () => uiSettings, + getAll: () => testUiSettings, + validateValue: () => Promise.resolve({ successfulValidation: true, valid: true }), }, }, }, }); await waitFor(() => expect(container.querySelector('.euiLoadingSpinner')).toBeNull()); + fireEvent.change( + getByTestId(`management-settings-editField-${aiAssistantLogsIndexPattern}`), + { + target: { value: 'observability-ai-assistant-*' }, + } + ); - fireEvent.input(getByTestId(`management-settings-editField-${aiAssistantLogsIndexPattern}`), { - target: { value: 'observability-ai-assistant-*' }, - }); + await waitFor(() => + expect( + getByTestId('observabilityAiAssistantManagementBottomBarActionsButton') + ).toBeInTheDocument() + ); fireEvent.click(getByTestId('observabilityAiAssistantManagementBottomBarActionsButton')); - await waitFor(() => expect(windowLocationReloadMock).toHaveBeenCalledTimes(1)); }); @@ -83,10 +97,9 @@ describe('SettingsTab', () => { }); it('calls the settings client with correct args', async () => { - expect(settingsClientSet).toBeCalledWith( - aiAssistantLogsIndexPattern, - 'observability-ai-assistant-*' - ); + expect(settingsClientSet).toBeCalledWith(aiAssistantLogsIndexPattern, [ + 'observability-ai-assistant-*', + ]); }); }); }); diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/tsconfig.json b/x-pack/plugins/observability_solution/observability_ai_assistant_management/tsconfig.json index 54a428c60315e..d8a03acbae61b 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/tsconfig.json +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/tsconfig.json @@ -20,7 +20,8 @@ "@kbn/management-settings-components-field-row", "@kbn/observability-shared-plugin", "@kbn/config-schema", - "@kbn/core-ui-settings-common" + "@kbn/core-ui-settings-common", + "@kbn/logs-data-access-plugin" ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index fddb13aa197df..d55d41d0dd5b1 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -33060,7 +33060,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.goToFeatureControlsButtonLabel": "Aller dans les espaces", "xpack.observabilityAiAssistantManagement.settingsPage.h2.settingsLabel": "Paramètres", "xpack.observabilityAiAssistantManagement.settingsPage.knowledgeBaseLabel": "Base de connaissances", - "xpack.observabilityAiAssistantManagement.settingsPage.logIndexPatternDescription": "Modèle d'index utilisé par l'assistant d'IA lorsqu'il recherche des logs. Les logs sont classés par catégories et utilisés pour l'analyse des causes premières", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnector": "Connecteurs Search", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnectorIndexPatternDescription": "Modèle d'index utilisé par l’assistant d’IA lors de l'interrogation des index des connecteurs de recherche (une partie de la base de connaissances). L'index de chaque connecteur de recherche sera interrogé par défaut", "xpack.observabilityAiAssistantManagement.settingsPage.settingsLabel": "Paramètres", @@ -33068,7 +33067,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.showAIAssistantDescriptionLabel": "Affichez/masquez le bouton de l'Assistant d'IA et les informations contextuelles dans les applications d'Observability en cochant ou en décochant la fonctionnalité Assistant d'IA dans Espaces > > Fonctionnalités.", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingDescription": "[version d'évaluation technique] Utilisez l'appel de fonction simulé. L’appel de fonction simulé ne nécessite pas la prise en charge de l'API pour les fonctions ou les outils, mais il peut réduire les performances. L'appel de fonction simulé est actuellement toujours activé pour les connecteurs non-OpenAI, indépendamment de ce paramètre.", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingLabel": "Simuler un appel de fonction", - "xpack.observabilityAiAssistantManagement.settingsTab.h3.logIndexPatternLabel": "Modèle d'indexation des logs", "xpack.observabilityAiAssistantManagement.settingsTab.h3.searchConnectorIndexPatternLabel": "Modèle d'indexation de connecteur de recherche", "xpack.observabilityAiAssistantManagement.span.expandRowLabel": "Développer la ligne", "xpack.observabilityLogsExplorer.alertsPopover.buttonLabel": "Alertes", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 42f9a5fa9125b..e8913402a2191 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -33047,7 +33047,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.goToFeatureControlsButtonLabel": "スペースに移動", "xpack.observabilityAiAssistantManagement.settingsPage.h2.settingsLabel": "設定", "xpack.observabilityAiAssistantManagement.settingsPage.knowledgeBaseLabel": "ナレッジベース", - "xpack.observabilityAiAssistantManagement.settingsPage.logIndexPatternDescription": "ログのクエリを実行するときにAI Assistantによって使用されるインデックスパターン。ログは分類され、根本原因分析で使用されます。", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnector": "検索コネクター", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnectorIndexPatternDescription": "検索コネクターインデックス(ナレッジベースの一部)をクエリするときに、AI Assistantによって使用されるインデックスパターン。デフォルトでは、すべての検索コネクターのインデックスに対してクエリが実行されます。", "xpack.observabilityAiAssistantManagement.settingsPage.settingsLabel": "設定", @@ -33055,7 +33054,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.showAIAssistantDescriptionLabel": "オブザーバビリティアプリでAI Assistantボタンと状況に応じたインサイトのオン/オフを切り替えるには、[スペース]>[]>[機能]でAI Assistant機能のチェックをオンまたはオフにします。", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingDescription": "[technical preview] シミュレートされた関数呼び出しを使用します。シミュレートされた関数呼び出しでは、関数またはツールのAPIサポートは必要ありませんが、パフォーマンスが低下する可能性があります。現在、シミュレートされた関数呼び出しは、この設定に関係なく、非OpenAIコネクターで常に有効です。", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingLabel": "関数呼び出しをシミュレート", - "xpack.observabilityAiAssistantManagement.settingsTab.h3.logIndexPatternLabel": "ログインデックスパターン", "xpack.observabilityAiAssistantManagement.settingsTab.h3.searchConnectorIndexPatternLabel": "検索コネクターインデックスパターン", "xpack.observabilityAiAssistantManagement.span.expandRowLabel": "行を展開", "xpack.observabilityLogsExplorer.alertsPopover.buttonLabel": "アラート", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 5d43e6030af81..35fd3c4e9a609 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -33087,7 +33087,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.goToFeatureControlsButtonLabel": "前往工作区", "xpack.observabilityAiAssistantManagement.settingsPage.h2.settingsLabel": "设置", "xpack.observabilityAiAssistantManagement.settingsPage.knowledgeBaseLabel": "知识库", - "xpack.observabilityAiAssistantManagement.settingsPage.logIndexPatternDescription": "AI 助手查询日志时使用的索引模式。日志将进行归类并用于根本原因分析", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnector": "搜索连接器", "xpack.observabilityAiAssistantManagement.settingsPage.searchConnectorIndexPatternDescription": "查询搜索连接器索引(知识库的一部分)时 AI 助手使用的索引模式。默认情况下,将查询每个搜索连接器的索引", "xpack.observabilityAiAssistantManagement.settingsPage.settingsLabel": "设置", @@ -33095,7 +33094,6 @@ "xpack.observabilityAiAssistantManagement.settingsPage.showAIAssistantDescriptionLabel": "通过在“工作区 > > 功能”中选中或取消选中 AI 助手功能,在 Observability 应用中打开或关闭 AI 助手按钮和上下文洞察。", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingDescription": "[技术预览] 使用模拟函数调用。模拟函数调用不需要函数或工具的 API 支持,但可能会降低性能。无论此设置如何,当前会始终对非 OpenAI 连接器启用模拟函数调用。", "xpack.observabilityAiAssistantManagement.settingsPage.simulatedFunctionCallingLabel": "模拟函数调用", - "xpack.observabilityAiAssistantManagement.settingsTab.h3.logIndexPatternLabel": "日志索引模式", "xpack.observabilityAiAssistantManagement.settingsTab.h3.searchConnectorIndexPatternLabel": "搜索连接器索引模式", "xpack.observabilityAiAssistantManagement.span.expandRowLabel": "展开行", "xpack.observabilityLogsExplorer.alertsPopover.buttonLabel": "告警", diff --git a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts index a5d2802dfbcc5..ea894a36c59f4 100644 --- a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts +++ b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts @@ -57,8 +57,7 @@ const pages = { settings: { settingsPage: 'aiAssistantSettingsPage', managementLink: 'aiAssistantManagementSelection', - logsIndexPatternInput: - 'management-settings-editField-observability:aiAssistantLogsIndexPattern', + logsIndexPatternInput: 'management-settings-editField-observability:logSources', saveButton: 'observabilityAiAssistantManagementBottomBarActionsButton', aiAssistantCard: 'aiAssistantSelectionPageObservabilityCard', }, From f678118b195ea81c81c606a4f202d3b394a726f4 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:00:37 +0100 Subject: [PATCH 2/4] Make Log sources setting disabled --- ...a_advanced_setting_configuration_panel.tsx | 98 +++---------------- .../components/logs_sources_setting.tsx | 81 +++++++++++++++ .../logs_data_access/public/index.ts | 1 + .../logs_data_access/tsconfig.json | 4 +- .../observability_ai_assistant/tsconfig.json | 1 - .../kibana.jsonc | 2 +- .../settings_tab/settings_tab.test.tsx | 64 +----------- .../components/settings_tab/ui_settings.tsx | 11 ++- .../translations/translations/fr-FR.json | 4 +- .../translations/translations/ja-JP.json | 4 +- .../translations/translations/zh-CN.json | 4 +- 11 files changed, 113 insertions(+), 161 deletions(-) create mode 100644 x-pack/plugins/observability_solution/logs_data_access/public/components/logs_sources_setting.tsx diff --git a/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/kibana_advanced_setting_configuration_panel.tsx b/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/kibana_advanced_setting_configuration_panel.tsx index 49636e4171f2f..a095b2825cd3e 100644 --- a/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/kibana_advanced_setting_configuration_panel.tsx +++ b/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/kibana_advanced_setting_configuration_panel.tsx @@ -5,33 +5,15 @@ * 2.0. */ -import { EuiDescribedFormGroup, EuiFieldText, EuiFormRow } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; -import React, { useMemo } from 'react'; +import React from 'react'; import { useTrackPageview } from '@kbn/observability-shared-plugin/public'; -import { LogSourcesKibanaAdvancedSettingReference } from '@kbn/logs-shared-plugin/common'; -import { ApplicationStart } from '@kbn/core-application-browser'; -import { EuiLink } from '@elastic/eui'; -import { useLogSourcesContext } from '@kbn/logs-data-access-plugin/public'; +import { + LogSourcesSettingSynchronisationInfo, + useLogSourcesContext, +} from '@kbn/logs-data-access-plugin/public'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; -import { FormElement } from './form_elements'; -import { getFormRowProps } from './form_field_props'; -import { FormValidationError } from './validation_errors'; -function getKibanaAdvancedSettingsHref(application: ApplicationStart) { - return application.getUrlForApp('management', { - path: `/kibana/settings?query=${encodeURIComponent('Log sources')}`, - }); -} - -export const KibanaAdvancedSettingConfigurationPanel: React.FC<{ - isLoading: boolean; - isReadOnly: boolean; - advancedSettingFormElement: FormElement< - LogSourcesKibanaAdvancedSettingReference, - FormValidationError - >; -}> = ({ isLoading, isReadOnly, advancedSettingFormElement }) => { +export const KibanaAdvancedSettingConfigurationPanel: React.FC = () => { const { services: { application }, } = useKibanaContextForPlugin(); @@ -43,71 +25,13 @@ export const KibanaAdvancedSettingConfigurationPanel: React.FC<{ delay: 15000, }); - const advancedSettingsHref = useMemo( - () => getKibanaAdvancedSettingsHref(application), - [application] - ); - const { isLoadingLogSources, combinedIndices } = useLogSourcesContext(); return ( - <> - - - - } - description={ - - - - ), - }} - /> - } - > - - } - label={ - - } - {...getFormRowProps(advancedSettingFormElement)} - > - - - - + ); }; diff --git a/x-pack/plugins/observability_solution/logs_data_access/public/components/logs_sources_setting.tsx b/x-pack/plugins/observability_solution/logs_data_access/public/components/logs_sources_setting.tsx new file mode 100644 index 0000000000000..0b970ecbb2d25 --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_data_access/public/components/logs_sources_setting.tsx @@ -0,0 +1,81 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { EuiDescribedFormGroup, EuiFieldText, EuiFormRow, EuiLink } from '@elastic/eui'; +import { ApplicationStart } from '@kbn/core-application-browser'; +import { FormattedMessage } from '@kbn/i18n-react'; +import React, { useMemo } from 'react'; + +export const LogSourcesSettingSynchronisationInfo: React.FC<{ + isLoading: boolean; + logSourcesValue: string; + getUrlForApp: ApplicationStart['getUrlForApp']; + title?: string; +}> = ({ isLoading, logSourcesValue, getUrlForApp, title }) => { + const advancedSettingsHref = useMemo( + () => + getUrlForApp('management', { + path: `/kibana/settings?query=${encodeURIComponent('Log sources')}`, + }), + [getUrlForApp] + ); + + return ( + <> + + {title ?? ( + + )} + + } + description={ + + + + ), + }} + /> + } + > + + } + > + + + + + ); +}; diff --git a/x-pack/plugins/observability_solution/logs_data_access/public/index.ts b/x-pack/plugins/observability_solution/logs_data_access/public/index.ts index cc09500ef0a84..ed8facea9b91b 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/public/index.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/public/index.ts @@ -16,6 +16,7 @@ export type { LogsDataAccessPluginSetup, LogsDataAccessPluginStart }; import { LogsDataAccessPluginSetupDeps, LogsDataAccessPluginStartDeps } from './types'; export { LogSourcesProvider, useLogSourcesContext } from './hooks/use_log_sources'; +export { LogSourcesSettingSynchronisationInfo } from './components/logs_sources_setting'; export const plugin: PluginInitializer< LogsDataAccessPluginSetup, diff --git a/x-pack/plugins/observability_solution/logs_data_access/tsconfig.json b/x-pack/plugins/observability_solution/logs_data_access/tsconfig.json index fb2457edd993f..ff67c2f1c8f30 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/tsconfig.json +++ b/x-pack/plugins/observability_solution/logs_data_access/tsconfig.json @@ -22,6 +22,8 @@ "@kbn/logging", "@kbn/core-saved-objects-api-server", "@kbn/es-query", - "@kbn/use-tracked-promise" + "@kbn/use-tracked-promise", + "@kbn/core-application-browser", + "@kbn/i18n-react" ] } 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 512932abce027..d9c747731073b 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.json @@ -44,7 +44,6 @@ "@kbn/serverless", "@kbn/core-elasticsearch-server", "@kbn/core-ui-settings-server", - "@kbn/server-route-repository-utils", "@kbn/inference-plugin", "@kbn/management-settings-ids" ], diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/kibana.jsonc b/x-pack/plugins/observability_solution/observability_ai_assistant_management/kibana.jsonc index 03d217d84e94f..ddf00c84c0ac3 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/kibana.jsonc +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/kibana.jsonc @@ -9,6 +9,6 @@ "configPath": ["xpack", "observabilityAiAssistantManagement"], "requiredPlugins": ["management", "observabilityAIAssistant", "observabilityShared"], "optionalPlugins": ["actions", "home", "serverless", "enterpriseSearch"], - "requiredBundles": ["kibanaReact"] + "requiredBundles": ["kibanaReact", "logsDataAccess"] } } diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx index 25ef46ddf03eb..2bed5aed37160 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/settings_tab.test.tsx @@ -6,20 +6,12 @@ */ import React from 'react'; -import { fireEvent, waitFor } from '@testing-library/react'; +import { fireEvent } from '@testing-library/react'; import { render } from '../../../helpers/test_helper'; import { SettingsTab } from './settings_tab'; -import { aiAssistantLogsIndexPattern } from '@kbn/observability-ai-assistant-plugin/server'; -import { uiSettings } from '../../../../common/ui_settings'; -import { uiSettings as logsDataAccessUiSettings } from '@kbn/logs-data-access-plugin/common/ui_settings'; jest.mock('../../../hooks/use_app_context'); -const testUiSettings = { - ...uiSettings, - ...logsDataAccessUiSettings, -}; - describe('SettingsTab', () => { it('should offer a way to configure Observability AI Assistant visibility in apps', () => { const navigateToAppMock = jest.fn(() => Promise.resolve()); @@ -48,58 +40,4 @@ describe('SettingsTab', () => { path: '/insightsAndAlerting/triggersActionsConnectors/connectors', }); }); - - describe('allows updating the AI Assistant settings', () => { - const windowLocationReloadMock = jest.fn(); - const windowLocationOriginal = window.location; - const settingsClientSet = jest.fn(); - - beforeEach(async () => { - Object.defineProperty(window, 'location', { - value: { - reload: windowLocationReloadMock, - }, - writable: true, - }); - - const { getByTestId, container } = render(, { - coreStart: { - settings: { - client: { - set: settingsClientSet, - getAll: () => testUiSettings, - validateValue: () => Promise.resolve({ successfulValidation: true, valid: true }), - }, - }, - }, - }); - - await waitFor(() => expect(container.querySelector('.euiLoadingSpinner')).toBeNull()); - fireEvent.change( - getByTestId(`management-settings-editField-${aiAssistantLogsIndexPattern}`), - { - target: { value: 'observability-ai-assistant-*' }, - } - ); - - await waitFor(() => - expect( - getByTestId('observabilityAiAssistantManagementBottomBarActionsButton') - ).toBeInTheDocument() - ); - - fireEvent.click(getByTestId('observabilityAiAssistantManagementBottomBarActionsButton')); - await waitFor(() => expect(windowLocationReloadMock).toHaveBeenCalledTimes(1)); - }); - - afterEach(() => { - window.location = windowLocationOriginal; - }); - - it('calls the settings client with correct args', async () => { - expect(settingsClientSet).toBeCalledWith(aiAssistantLogsIndexPattern, [ - 'observability-ai-assistant-*', - ]); - }); - }); }); diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/ui_settings.tsx b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/ui_settings.tsx index 5be8456954d64..a8c20a641f042 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/ui_settings.tsx +++ b/x-pack/plugins/observability_solution/observability_ai_assistant_management/public/routes/components/settings_tab/ui_settings.tsx @@ -17,10 +17,10 @@ import { FieldRow, FieldRowProvider } from '@kbn/management-settings-components- import { EuiSpacer } from '@elastic/eui'; import { isEmpty } from 'lodash'; import { i18n } from '@kbn/i18n'; +import { LogSourcesSettingSynchronisationInfo } from '@kbn/logs-data-access-plugin/public'; import { useKibana } from '../../../hooks/use_kibana'; const settingsKeys = [ - aiAssistantLogsIndexPattern, aiAssistantSimulatedFunctionCalling, aiAssistantSearchConnectorIndexPattern, aiAssistantPreferredAIAssistantType, @@ -31,7 +31,7 @@ export function UISettings() { docLinks, settings, notifications, - application: { capabilities }, + application: { capabilities, getUrlForApp }, } = useKibana().services; const { fields, handleFieldChange, unsavedChanges, saveAll, isSaving, cleanUnsavedChanges } = @@ -84,6 +84,13 @@ export function UISettings() { ); })} + + + {!isEmpty(unsavedChanges) && ( Date: Mon, 16 Sep 2024 14:20:07 +0100 Subject: [PATCH 3/4] Remove unused props --- .../pages/logs/settings/indices_configuration_panel.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/indices_configuration_panel.tsx b/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/indices_configuration_panel.tsx index 0aad03315c8e1..8f42b4cf1bc6a 100644 --- a/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/indices_configuration_panel.tsx +++ b/x-pack/plugins/observability_solution/infra/public/pages/logs/settings/indices_configuration_panel.tsx @@ -140,11 +140,7 @@ export const IndicesConfigurationPanel = React.memo<{ disabled={isReadOnly} > {isKibanaAdvancedSettingFormElement(indicesFormElement) && ( - + )} From 38a829dd6e49f96239da33096592f3ab51003126 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:18:08 +0100 Subject: [PATCH 4/4] Amend tests to use a different advanced setting --- .../common/ui/index.ts | 2 ++ .../settings_security.spec.ts | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts index ea894a36c59f4..2c6852988cde5 100644 --- a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts +++ b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts @@ -58,6 +58,8 @@ const pages = { settingsPage: 'aiAssistantSettingsPage', managementLink: 'aiAssistantManagementSelection', logsIndexPatternInput: 'management-settings-editField-observability:logSources', + searchConnectorIndexPatternInput: + 'management-settings-editField-observability:aiAssistantSearchConnectorIndexPattern', saveButton: 'observabilityAiAssistantManagementBottomBarActionsButton', aiAssistantCard: 'aiAssistantSelectionPageObservabilityCard', }, diff --git a/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts b/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts index ef87707c62a2c..96f2ff4b00f7f 100644 --- a/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts +++ b/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts @@ -58,20 +58,21 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail(ui.pages.settings.settingsPage); }); it('allows updating of an advanced setting', async () => { - const testLogsIndexPattern = 'my-logs-index-pattern'; - const logsIndexPatternInput = await testSubjects.find( - ui.pages.settings.logsIndexPatternInput + const testSearchConnectorIndexPattern = 'my-logs-index-pattern'; + const searchConnectorIndexPatternInput = await testSubjects.find( + ui.pages.settings.searchConnectorIndexPatternInput ); - await logsIndexPatternInput.clearValue(); - await logsIndexPatternInput.type(testLogsIndexPattern); + await searchConnectorIndexPatternInput.clearValue(); + await searchConnectorIndexPatternInput.type(testSearchConnectorIndexPattern); const saveButton = await testSubjects.find(ui.pages.settings.saveButton); await saveButton.click(); await browser.refresh(); - const logsIndexPatternInputValue = await logsIndexPatternInput.getAttribute('value'); - expect(logsIndexPatternInputValue).to.be(testLogsIndexPattern); + const searchConnectorIndexPatternInputValue = + await searchConnectorIndexPatternInput.getAttribute('value'); + expect(searchConnectorIndexPatternInputValue).to.be(testSearchConnectorIndexPattern); // reset the value - await logsIndexPatternInput.clearValue(); - await logsIndexPatternInput.type('logs-*'); + await searchConnectorIndexPatternInput.clearValue(); + await searchConnectorIndexPatternInput.type('logs-*'); await saveButton.click(); }); }); @@ -114,10 +115,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail(ui.pages.settings.settingsPage); }); it('has disabled inputs', async () => { - const logsIndexPatternInput = await testSubjects.find( - ui.pages.settings.logsIndexPatternInput + const searchConnectorIndexPatternInput = await testSubjects.find( + ui.pages.settings.searchConnectorIndexPatternInput ); - expect(await logsIndexPatternInput.getAttribute('disabled')).to.be('true'); + expect(await searchConnectorIndexPatternInput.getAttribute('disabled')).to.be('true'); }); }); describe('observabilityAIAssistant privilege with no aiAssistantManagementSelection privilege', () => {