From c423e3e9d3bd61041d4e10e72cef01ea663ca5bf Mon Sep 17 00:00:00 2001 From: Jesus Wahrman <41008968+jesuswr@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:40:27 +0100 Subject: [PATCH] Make link to es deprecation logs more useful (#203487) ## Summary resolves https://github.com/elastic/kibana/issues/201538 Added a profile to the deprecation logs so by default it shows the columns. Decided to allow this behaviour if the pattern contains multiple patterns for deprecation logs like: `.logs-deprecation.abc,.logs-deprecation.def` , this can be easily changed if we prefer not to do it this way. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .github/CODEOWNERS | 2 + .../common/deprecation_logs/consts.ts | 11 +++ .../common/deprecation_logs/index.ts | 10 +++ .../common/deprecation_logs/profile.test.ts | 73 +++++++++++++++++++ .../common/deprecation_logs/profile.ts | 59 +++++++++++++++ .../register_profile_providers.ts | 2 + 6 files changed, 157 insertions(+) create mode 100644 src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/consts.ts create mode 100644 src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/index.ts create mode 100644 src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.test.ts create mode 100644 src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 087ffceddc04c..df1caa990abd4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1144,6 +1144,8 @@ x-pack/test_serverless/api_integration/test_suites/common/platform_security @ela /x-pack/test_serverless/functional/test_suites/common/examples/unified_field_list_examples @elastic/kibana-data-discovery /x-pack/test_serverless/functional/test_suites/common/management/data_views @elastic/kibana-data-discovery src/plugins/discover/public/context_awareness/profile_providers/security @elastic/kibana-data-discovery @elastic/security-threat-hunting-investigations +# TODO: this deprecation_logs folder should be owned by kibana management team after 9.0 +src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs @elastic/kibana-data-discovery @elastic/kibana-core src/plugins/discover/public/context_awareness/profile_providers/observability @elastic/kibana-data-discovery @elastic/obs-ux-logs-team # Platform Docs diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/consts.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/consts.ts new file mode 100644 index 0000000000000..1e6e0b1b2e9db --- /dev/null +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/consts.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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export const DEPRECATION_LOGS_PROFILE_ID = 'deprecation-logs-profile'; +export const DEPRECATION_LOGS_PATTERN_PREFIX = '.logs-deprecation'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/index.ts new file mode 100644 index 0000000000000..8110f3371ce81 --- /dev/null +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/index.ts @@ -0,0 +1,10 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { createDeprecationLogsDataSourceProfileProvider } from './profile'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.test.ts new file mode 100644 index 0000000000000..c961f310f6e5a --- /dev/null +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.test.ts @@ -0,0 +1,73 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { createStubIndexPattern } from '@kbn/data-views-plugin/common/data_view.stub'; +import { createDataViewDataSource } from '../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; +import { createDeprecationLogsDataSourceProfileProvider } from './profile'; +import type { ContextWithProfileId } from '../../../profile_service'; +import { DEPRECATION_LOGS_PROFILE_ID } from './consts'; + +describe('deprecationLogsProfileProvider', () => { + const deprecationLogsProfileProvider = createDeprecationLogsDataSourceProfileProvider(); + const VALID_INDEX_PATTERN = '.logs-deprecation.elasticsearch-default'; + const VALID_MIXED_INDEX_PATTERN = + '.logs-deprecation.elasticsearch-default,.logs-deprecation.abc,.logs-deprecation.def'; + const INVALID_MIXED_INDEX_PATTERN = '.logs-deprecation.elasticsearch-default,metrics-*'; + const INVALID_INDEX_PATTERN = 'my_source-access-*'; + const ROOT_CONTEXT: ContextWithProfileId = { + profileId: DEPRECATION_LOGS_PROFILE_ID, + solutionType: SolutionType.Default, + }; + const RESOLUTION_MATCH = { + isMatch: true, + context: { + category: DataSourceCategory.Logs, + }, + }; + const RESOLUTION_MISMATCH = { + isMatch: false, + }; + + it('should match data view sources with an allowed index pattern', () => { + const result = deprecationLogsProfileProvider.resolve({ + rootContext: ROOT_CONTEXT, + dataSource: createDataViewDataSource({ dataViewId: VALID_INDEX_PATTERN }), + dataView: createStubIndexPattern({ spec: { title: VALID_INDEX_PATTERN } }), + }); + expect(result).toEqual(RESOLUTION_MATCH); + }); + + it('should match data view sources with a mixed pattern containing allowed index patterns', () => { + const result = deprecationLogsProfileProvider.resolve({ + rootContext: ROOT_CONTEXT, + dataSource: createDataViewDataSource({ dataViewId: VALID_MIXED_INDEX_PATTERN }), + dataView: createStubIndexPattern({ spec: { title: VALID_MIXED_INDEX_PATTERN } }), + }); + expect(result).toEqual(RESOLUTION_MATCH); + }); + + it('should NOT match data view sources with not allowed index pattern', () => { + const result = deprecationLogsProfileProvider.resolve({ + rootContext: ROOT_CONTEXT, + dataSource: createDataViewDataSource({ dataViewId: INVALID_INDEX_PATTERN }), + dataView: createStubIndexPattern({ spec: { title: INVALID_INDEX_PATTERN } }), + }); + expect(result).toEqual(RESOLUTION_MISMATCH); + }); + + it('should NOT match data view sources with a mixed pattern containing not allowed index patterns', () => { + const result = deprecationLogsProfileProvider.resolve({ + rootContext: ROOT_CONTEXT, + dataSource: createDataViewDataSource({ dataViewId: INVALID_MIXED_INDEX_PATTERN }), + dataView: createStubIndexPattern({ spec: { title: INVALID_MIXED_INDEX_PATTERN } }), + }); + expect(result).toEqual(RESOLUTION_MISMATCH); + }); +}); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.ts new file mode 100644 index 0000000000000..4d220892aea29 --- /dev/null +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.ts @@ -0,0 +1,59 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { DataSourceCategory } from '../../../profiles'; +import { type DataSourceProfileProvider } from '../../../profiles'; +import { DEPRECATION_LOGS_PATTERN_PREFIX, DEPRECATION_LOGS_PROFILE_ID } from './consts'; +import { extractIndexPatternFrom } from '../../extract_index_pattern_from'; + +export const createDeprecationLogsDataSourceProfileProvider = + (): DataSourceProfileProvider<{}> => ({ + profileId: DEPRECATION_LOGS_PROFILE_ID, + profile: { + getDefaultAppState: () => () => ({ + columns: [ + { name: 'log.level', width: 150 }, + { name: 'message' }, + { name: 'elasticsearch.http.request.x_opaque_id', width: 250 }, + { name: 'elasticsearch.cluster.name', width: 250 }, + { name: 'elasticsearch.event.category', width: 250 }, + ], + }), + }, + resolve: (params) => { + const indexPattern = extractIndexPatternFrom(params); + + if (!checkAllIndicesInPatternAreDeprecationLogs(indexPattern)) { + return { isMatch: false }; + } + + return { + isMatch: true, + context: { + category: DataSourceCategory.Logs, + }, + }; + }, + }); + +/* + This function returns true if the index pattern belongs to deprecation logs. + It also considers multiple patterns separated by commas. +*/ +const checkAllIndicesInPatternAreDeprecationLogs = (indexPattern: string | null): boolean => { + if (!indexPattern) { + return false; + } + const indexPatternArray = indexPattern.split(','); + const result = indexPatternArray.reduce( + (acc, val) => acc && val.startsWith(DEPRECATION_LOGS_PATTERN_PREFIX), + true + ); + return result; +}; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts index b0ee4318dde2e..88c7628e9273a 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts @@ -28,6 +28,7 @@ import { } from './profile_provider_services'; import type { DiscoverServices } from '../../build_services'; import { createObservabilityRootProfileProvider } from './observability/observability_root_profile'; +import { createDeprecationLogsDataSourceProfileProvider } from './common/deprecation_logs'; /** * Register profile providers for root, data source, and document contexts to the profile profile services @@ -133,6 +134,7 @@ const createRootProfileProviders = (providerServices: ProfileProviderServices) = */ const createDataSourceProfileProviders = (providerServices: ProfileProviderServices) => [ createExampleDataSourceProfileProvider(), + createDeprecationLogsDataSourceProfileProvider(), ...createObservabilityLogsDataSourceProfileProviders(providerServices), ];