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,8 +34,8 @@ 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,
settings.OBSERVABILITY_SEARCH_EXCLUDED_DATA_TIERS,
];
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 @@ -140,11 +140,7 @@ export const IndicesConfigurationPanel = React.memo<{
disabled={isReadOnly}
>
{isKibanaAdvancedSettingFormElement(indicesFormElement) && (
<KibanaAdvancedSettingConfigurationPanel
isLoading={isLoading}
isReadOnly={isReadOnly}
advancedSettingFormElement={indicesFormElement}
/>
<KibanaAdvancedSettingConfigurationPanel />
)}
</EuiCheckableCard>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -43,71 +25,13 @@ export const KibanaAdvancedSettingConfigurationPanel: React.FC<{
delay: 15000,
});

const advancedSettingsHref = useMemo(
() => getKibanaAdvancedSettingsHref(application),
[application]
);

const { isLoadingLogSources, combinedIndices } = useLogSourcesContext();

return (
<>
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.infra.sourceConfiguration.logSourcesSettingTitle"
defaultMessage="Advanced setting"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.infra.sourceConfiguration.logSourcesSettingDescription"
defaultMessage="This value is synchronised with the Kibana log sources advanced setting. It can be changed via the {advancedSettingsLink}."
values={{
advancedSettingsLink: (
<EuiLink
data-test-subj="xpack.infra.sourceConfiguration.logSourcesSettingLink"
href={advancedSettingsHref}
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.logSourcesSettingLinkText"
defaultMessage="advanced settings page"
/>
</EuiLink>
),
}}
/>
}
>
<EuiFormRow
fullWidth
helpText={
<FormattedMessage
id="xpack.infra.sourceConfiguration.logSourcesSettingValue"
defaultMessage="The current setting value"
/>
}
label={
<FormattedMessage
id="xpack.infra.sourceConfiguration.logSourcesSettingLabel"
defaultMessage="Log sources advanced setting"
/>
}
{...getFormRowProps(advancedSettingFormElement)}
>
<EuiFieldText
data-test-subj="logSourcesSettingInput"
fullWidth
disabled={isLoading}
isLoading={isLoadingLogSources}
readOnly={true}
value={combinedIndices}
isInvalid={false}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
</>
<LogSourcesSettingSynchronisationInfo
isLoading={isLoadingLogSources}
logSourcesValue={combinedIndices}
getUrlForApp={application.getUrlForApp}
/>
);
};
Loading