Skip to content

Commit

Permalink
[8.x] Make link to es deprecation logs more useful (elastic#203487) (e…
Browse files Browse the repository at this point in the history
…lastic#203785)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Make link to es deprecation logs more useful
(elastic#203487)](elastic#203487)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Jesus
Wahrman","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-11T12:40:27Z","message":"Make
link to es deprecation logs more useful (elastic#203487)\n\n##
Summary\r\n\r\nresolves
https://github.com/elastic/kibana/issues/201538\r\n\r\nAdded a profile
to the deprecation logs so by default it shows the\r\ncolumns. Decided
to allow this behaviour if the pattern contains\r\nmultiple patterns for
deprecation logs like:\r\n`.logs-deprecation.abc,.logs-deprecation.def`
, this can be easily\r\nchanged if we prefer not to do it this
way.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c423e3e9d3bd61041d4e10e72cef01ea663ca5bf","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor"],"title":"Make
link to es deprecation logs more
useful","number":203487,"url":"https://github.com/elastic/kibana/pull/203487","mergeCommit":{"message":"Make
link to es deprecation logs more useful (elastic#203487)\n\n##
Summary\r\n\r\nresolves
https://github.com/elastic/kibana/issues/201538\r\n\r\nAdded a profile
to the deprecation logs so by default it shows the\r\ncolumns. Decided
to allow this behaviour if the pattern contains\r\nmultiple patterns for
deprecation logs like:\r\n`.logs-deprecation.abc,.logs-deprecation.def`
, this can be easily\r\nchanged if we prefer not to do it this
way.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c423e3e9d3bd61041d4e10e72cef01ea663ca5bf"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203487","number":203487,"mergeCommit":{"message":"Make
link to es deprecation logs more useful (elastic#203487)\n\n##
Summary\r\n\r\nresolves
https://github.com/elastic/kibana/issues/201538\r\n\r\nAdded a profile
to the deprecation logs so by default it shows the\r\ncolumns. Decided
to allow this behaviour if the pattern contains\r\nmultiple patterns for
deprecation logs like:\r\n`.logs-deprecation.abc,.logs-deprecation.def`
, this can be easily\r\nchanged if we prefer not to do it this
way.\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c423e3e9d3bd61041d4e10e72cef01ea663ca5bf"}}]}]
BACKPORT-->

Co-authored-by: Jesus Wahrman <[email protected]>
  • Loading branch information
kibanamachine and jesuswr authored Dec 11, 2024
1 parent 0870986 commit 5a6fcab
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,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
Expand Down
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", 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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<RootContext> = {
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);
});
});
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,6 +134,7 @@ const createRootProfileProviders = (providerServices: ProfileProviderServices) =
*/
const createDataSourceProfileProviders = (providerServices: ProfileProviderServices) => [
createExampleDataSourceProfileProvider(),
createDeprecationLogsDataSourceProfileProvider(),
...createObservabilityLogsDataSourceProfileProviders(providerServices),
];

Expand Down

0 comments on commit 5a6fcab

Please sign in to comment.