Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs] Remove AI Assistant specific log index setting #192003

Merged
2 changes: 0 additions & 2 deletions packages/kbn-management/settings/setting_ids/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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,
];
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
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.' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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;
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10319,12 +10319,6 @@
"description": "Non-default value of setting."
}
},
"observability:aiAssistantLogsIndexPattern": {
"type": "keyword",
"_meta": {
"description": "Non-default value of setting."
}
},
"observability:aiAssistantSimulatedFunctionCalling": {
"type": "boolean",
"_meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,12 +25,12 @@ export interface LogCategory {
export async function getLogCategories({
apmEventClient,
esClient,
coreContext,
logSourcesService,
arguments: args,
}: {
apmEventClient: APMEventClient;
esClient: ElasticsearchClient;
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
logSourcesService: LogSourcesService;
arguments: {
start: string;
end: string;
Expand All @@ -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<string>(aiAssistantLogsIndexPattern);
const index = await logSourcesService.getFlattenedLogSources();
const search = getTypedSearch(esClient);

const query = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<CoreRequestHandlerContext, 'uiSettings'>;
logSourcesService: LogSourcesService;
arguments: {
alertStartedAt: string;
alertRuleParameterTimeSize?: number;
Expand All @@ -34,7 +33,7 @@ export async function getLogRateAnalysisForAlert({
};
};
}): ReturnType<typeof fetchLogRateAnalysisForAlert> {
const index = await coreContext.uiSettings.client.get<string>(aiAssistantLogsIndexPattern);
const index = await logSourcesService.getFlattenedLogSources();

const keyValueFilters = getShouldMatchOrNotExistFilter(
Object.entries(args.entities).map(([key, value]) => ({ field: key, value }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,11 +23,12 @@ import { RollupInterval } from '../../../../common/rollup';
export async function getContainerIdFromSignals({
query,
esClient,
coreContext,
logSourcesService,
apmEventClient,
}: {
query: t.TypeOf<typeof alertDetailsContextRt>;
esClient: ElasticsearchClient;
logSourcesService: LogSourcesService;
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
apmEventClient: APMEventClient;
}) {
Expand Down Expand Up @@ -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<CoreRequestHandlerContext, 'uiSettings'>;
logSourcesService: LogSourcesService;
}) {
const index = await coreContext.uiSettings.client.get<string>(aiAssistantLogsIndexPattern);
const index = await logSourcesService.getFlattenedLogSources();
const res = await typedSearch<{ container: { id: string } }, any>(esClient, {
index,
...params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,12 +22,12 @@ import { RollupInterval } from '../../../../common/rollup';
export async function getServiceNameFromSignals({
query,
esClient,
coreContext,
logSourcesService,
apmEventClient,
}: {
query: t.TypeOf<typeof alertDetailsContextRt>;
esClient: ElasticsearchClient;
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
logSourcesService: LogSourcesService;
apmEventClient: APMEventClient;
}) {
if (query['service.name']) {
Expand Down Expand Up @@ -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<CoreRequestHandlerContext, 'uiSettings'>;
logSourcesService: LogSourcesService;
}) {
const index = await coreContext.uiSettings.client.get<string>(aiAssistantLogsIndexPattern);
const index = await logSourcesService.getFlattenedLogSources();
const res = await typedSearch<{ service: { name: string } }, any>(esClient, {
index,
...params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -97,13 +100,14 @@ export const getAlertDetailsContextHandler = (
getServiceNameFromSignals({
query,
esClient,
coreContext,
logSourcesService,
apmEventClient,
}),
getContainerIdFromSignals({
query,
esClient,
coreContext,
logSourcesService,
apmEventClient,
}),
]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { LogSource, LogSourcesService } from './types';
import { flattenLogSources } from './utils';

const LOG_SOURCES: LogSource[] = [{ indexPattern: 'logs-*-*' }];
export const createLogSourcesServiceMock = (
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export interface LogSource {

export interface LogSourcesService {
getLogSources: () => Promise<LogSource[]>;
getFlattenedLogSources: () => Promise<string>;
setLogSources: (sources: LogSource[]) => Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -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(',');
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -18,22 +19,27 @@ export function createLogSourcesServiceFactory(params: RegisterServicesParams) {
): Promise<LogSourcesService> {
const { uiSettings } = params.deps;
const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient);
return {
getLogSources: async () => {
const logSourcesService: LogSourcesService = {
async getLogSources() {
const logSources = await uiSettingsClient.get<string[]>(
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[]) {
return await uiSettingsClient.set(
OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID,
sources.map((source) => source.indexPattern)
);
},
};
return logSourcesService;
},
async getScopedLogSourcesService(request: KibanaRequest): Promise<LogSourcesService> {
const { savedObjects } = params.deps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading