Skip to content

Commit

Permalink
[8.x] [Logs] Remove AI Assistant specific log index setting (#192003) (
Browse files Browse the repository at this point in the history
…#193723)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Logs] Remove AI Assistant specific log index setting
(#192003)](#192003)

<!--- Backport version: 8.9.8 -->

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

<!--BACKPORT [{"author":{"name":"Kerry
Gallagher","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-17T13:26:54Z","message":"[Logs]
Remove AI Assistant specific log index setting (#192003)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/167.\r\n\r\n- Removes
registration of the AI Assistant specific advanced
setting\r\n(`observability:aiAssistantLogsIndexPattern`).\r\n- Replaces
the setting with use of the central log sources
setting\r\n(`observability:logSources`).\r\n- ℹ️ Also registers the
central log sources setting in serverless (this\r\nwas missed
previously).\r\n\r\nDue to the impact that this setting has on
alerts\r\n([Discussion](https://github.com/elastic/logs-dev/issues/170#issuecomment-2229130314))\r\na
migration path from one setting to the other isn't really possible,
as\r\nvalues from the AI Assistant setting could potentially cause
unwanted\r\nalerts. As such these changes opt for the route that we'll
do a straight\r\nswap, and document this in release notes.\r\n\r\nWe
will also need to do a migration on the `config` (for
advanced\r\nsettings) Saved Object to remove instances of the old
setting /\r\nproperty. With the new \"model version\" migration model
[my understanding\r\nis this should happen in a separate
followup\r\nPR](https://github.com/elastic/kibana/blob/main/packages/core/saved-objects/core-saved-objects-server/src/model_version/model_change.ts#L131).\r\n\r\n⚠️
~One potentially open question is whether the custom
management\r\nsection that the AI Assistant mounts when clicking \"AI
Assistant\r\nSettings\" should render the log sources setting? (As this
setting\r\naffects more than just the AI
Assistant).~\r\n[Resolved](https://github.com/elastic/kibana/pull/192003#issuecomment-2352727034)\r\n\r\n![Screenshot
2024-09-05 at 11
53\r\n31](https://github.com/user-attachments/assets/ac3816ca-9021-42f1-9a9c-4c623c6943bb)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"ebe4686e6c53a640d8ff2cfc60a7eeceb132812b","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:deprecation","backport:skip","v9.0.0","Team:Obs
AI
Assistant","ci:project-deploy-observability","Team:obs-ux-logs","Team:obs-ux-infra_services","apm:review"],"number":192003,"url":"https://github.com/elastic/kibana/pull/192003","mergeCommit":{"message":"[Logs]
Remove AI Assistant specific log index setting (#192003)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/167.\r\n\r\n- Removes
registration of the AI Assistant specific advanced
setting\r\n(`observability:aiAssistantLogsIndexPattern`).\r\n- Replaces
the setting with use of the central log sources
setting\r\n(`observability:logSources`).\r\n- ℹ️ Also registers the
central log sources setting in serverless (this\r\nwas missed
previously).\r\n\r\nDue to the impact that this setting has on
alerts\r\n([Discussion](https://github.com/elastic/logs-dev/issues/170#issuecomment-2229130314))\r\na
migration path from one setting to the other isn't really possible,
as\r\nvalues from the AI Assistant setting could potentially cause
unwanted\r\nalerts. As such these changes opt for the route that we'll
do a straight\r\nswap, and document this in release notes.\r\n\r\nWe
will also need to do a migration on the `config` (for
advanced\r\nsettings) Saved Object to remove instances of the old
setting /\r\nproperty. With the new \"model version\" migration model
[my understanding\r\nis this should happen in a separate
followup\r\nPR](https://github.com/elastic/kibana/blob/main/packages/core/saved-objects/core-saved-objects-server/src/model_version/model_change.ts#L131).\r\n\r\n⚠️
~One potentially open question is whether the custom
management\r\nsection that the AI Assistant mounts when clicking \"AI
Assistant\r\nSettings\" should render the log sources setting? (As this
setting\r\naffects more than just the AI
Assistant).~\r\n[Resolved](https://github.com/elastic/kibana/pull/192003#issuecomment-2352727034)\r\n\r\n![Screenshot
2024-09-05 at 11
53\r\n31](https://github.com/user-attachments/assets/ac3816ca-9021-42f1-9a9c-4c623c6943bb)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"ebe4686e6c53a640d8ff2cfc60a7eeceb132812b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192003","number":192003,"mergeCommit":{"message":"[Logs]
Remove AI Assistant specific log index setting (#192003)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/167.\r\n\r\n- Removes
registration of the AI Assistant specific advanced
setting\r\n(`observability:aiAssistantLogsIndexPattern`).\r\n- Replaces
the setting with use of the central log sources
setting\r\n(`observability:logSources`).\r\n- ℹ️ Also registers the
central log sources setting in serverless (this\r\nwas missed
previously).\r\n\r\nDue to the impact that this setting has on
alerts\r\n([Discussion](https://github.com/elastic/logs-dev/issues/170#issuecomment-2229130314))\r\na
migration path from one setting to the other isn't really possible,
as\r\nvalues from the AI Assistant setting could potentially cause
unwanted\r\nalerts. As such these changes opt for the route that we'll
do a straight\r\nswap, and document this in release notes.\r\n\r\nWe
will also need to do a migration on the `config` (for
advanced\r\nsettings) Saved Object to remove instances of the old
setting /\r\nproperty. With the new \"model version\" migration model
[my understanding\r\nis this should happen in a separate
followup\r\nPR](https://github.com/elastic/kibana/blob/main/packages/core/saved-objects/core-saved-objects-server/src/model_version/model_change.ts#L131).\r\n\r\n⚠️
~One potentially open question is whether the custom
management\r\nsection that the AI Assistant mounts when clicking \"AI
Assistant\r\nSettings\" should render the log sources setting? (As this
setting\r\naffects more than just the AI
Assistant).~\r\n[Resolved](https://github.com/elastic/kibana/pull/192003#issuecomment-2352727034)\r\n\r\n![Screenshot
2024-09-05 at 11
53\r\n31](https://github.com/user-attachments/assets/ac3816ca-9021-42f1-9a9c-4c623c6943bb)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"ebe4686e6c53a640d8ff2cfc60a7eeceb132812b"}}]}]
BACKPORT-->
  • Loading branch information
Kerry350 authored Sep 24, 2024
1 parent 8d66d6c commit 527a9b6
Show file tree
Hide file tree
Showing 37 changed files with 215 additions and 244 deletions.
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

0 comments on commit 527a9b6

Please sign in to comment.