Skip to content

Commit c423e3e

Browse files
Make link to es deprecation logs more useful (#203487)
## Summary resolves #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 <[email protected]>
1 parent 5be7182 commit c423e3e

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ x-pack/test_serverless/api_integration/test_suites/common/platform_security @ela
11441144
/x-pack/test_serverless/functional/test_suites/common/examples/unified_field_list_examples @elastic/kibana-data-discovery
11451145
/x-pack/test_serverless/functional/test_suites/common/management/data_views @elastic/kibana-data-discovery
11461146
src/plugins/discover/public/context_awareness/profile_providers/security @elastic/kibana-data-discovery @elastic/security-threat-hunting-investigations
1147+
# TODO: this deprecation_logs folder should be owned by kibana management team after 9.0
1148+
src/plugins/discover/public/context_awareness/profile_providers/common/deprecation_logs @elastic/kibana-data-discovery @elastic/kibana-core
11471149
src/plugins/discover/public/context_awareness/profile_providers/observability @elastic/kibana-data-discovery @elastic/obs-ux-logs-team
11481150

11491151
# Platform Docs
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
export const DEPRECATION_LOGS_PROFILE_ID = 'deprecation-logs-profile';
11+
export const DEPRECATION_LOGS_PATTERN_PREFIX = '.logs-deprecation';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
export { createDeprecationLogsDataSourceProfileProvider } from './profile';
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { createStubIndexPattern } from '@kbn/data-views-plugin/common/data_view.stub';
11+
import { createDataViewDataSource } from '../../../../../common/data_sources';
12+
import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles';
13+
import { createDeprecationLogsDataSourceProfileProvider } from './profile';
14+
import type { ContextWithProfileId } from '../../../profile_service';
15+
import { DEPRECATION_LOGS_PROFILE_ID } from './consts';
16+
17+
describe('deprecationLogsProfileProvider', () => {
18+
const deprecationLogsProfileProvider = createDeprecationLogsDataSourceProfileProvider();
19+
const VALID_INDEX_PATTERN = '.logs-deprecation.elasticsearch-default';
20+
const VALID_MIXED_INDEX_PATTERN =
21+
'.logs-deprecation.elasticsearch-default,.logs-deprecation.abc,.logs-deprecation.def';
22+
const INVALID_MIXED_INDEX_PATTERN = '.logs-deprecation.elasticsearch-default,metrics-*';
23+
const INVALID_INDEX_PATTERN = 'my_source-access-*';
24+
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
25+
profileId: DEPRECATION_LOGS_PROFILE_ID,
26+
solutionType: SolutionType.Default,
27+
};
28+
const RESOLUTION_MATCH = {
29+
isMatch: true,
30+
context: {
31+
category: DataSourceCategory.Logs,
32+
},
33+
};
34+
const RESOLUTION_MISMATCH = {
35+
isMatch: false,
36+
};
37+
38+
it('should match data view sources with an allowed index pattern', () => {
39+
const result = deprecationLogsProfileProvider.resolve({
40+
rootContext: ROOT_CONTEXT,
41+
dataSource: createDataViewDataSource({ dataViewId: VALID_INDEX_PATTERN }),
42+
dataView: createStubIndexPattern({ spec: { title: VALID_INDEX_PATTERN } }),
43+
});
44+
expect(result).toEqual(RESOLUTION_MATCH);
45+
});
46+
47+
it('should match data view sources with a mixed pattern containing allowed index patterns', () => {
48+
const result = deprecationLogsProfileProvider.resolve({
49+
rootContext: ROOT_CONTEXT,
50+
dataSource: createDataViewDataSource({ dataViewId: VALID_MIXED_INDEX_PATTERN }),
51+
dataView: createStubIndexPattern({ spec: { title: VALID_MIXED_INDEX_PATTERN } }),
52+
});
53+
expect(result).toEqual(RESOLUTION_MATCH);
54+
});
55+
56+
it('should NOT match data view sources with not allowed index pattern', () => {
57+
const result = deprecationLogsProfileProvider.resolve({
58+
rootContext: ROOT_CONTEXT,
59+
dataSource: createDataViewDataSource({ dataViewId: INVALID_INDEX_PATTERN }),
60+
dataView: createStubIndexPattern({ spec: { title: INVALID_INDEX_PATTERN } }),
61+
});
62+
expect(result).toEqual(RESOLUTION_MISMATCH);
63+
});
64+
65+
it('should NOT match data view sources with a mixed pattern containing not allowed index patterns', () => {
66+
const result = deprecationLogsProfileProvider.resolve({
67+
rootContext: ROOT_CONTEXT,
68+
dataSource: createDataViewDataSource({ dataViewId: INVALID_MIXED_INDEX_PATTERN }),
69+
dataView: createStubIndexPattern({ spec: { title: INVALID_MIXED_INDEX_PATTERN } }),
70+
});
71+
expect(result).toEqual(RESOLUTION_MISMATCH);
72+
});
73+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { DataSourceCategory } from '../../../profiles';
11+
import { type DataSourceProfileProvider } from '../../../profiles';
12+
import { DEPRECATION_LOGS_PATTERN_PREFIX, DEPRECATION_LOGS_PROFILE_ID } from './consts';
13+
import { extractIndexPatternFrom } from '../../extract_index_pattern_from';
14+
15+
export const createDeprecationLogsDataSourceProfileProvider =
16+
(): DataSourceProfileProvider<{}> => ({
17+
profileId: DEPRECATION_LOGS_PROFILE_ID,
18+
profile: {
19+
getDefaultAppState: () => () => ({
20+
columns: [
21+
{ name: 'log.level', width: 150 },
22+
{ name: 'message' },
23+
{ name: 'elasticsearch.http.request.x_opaque_id', width: 250 },
24+
{ name: 'elasticsearch.cluster.name', width: 250 },
25+
{ name: 'elasticsearch.event.category', width: 250 },
26+
],
27+
}),
28+
},
29+
resolve: (params) => {
30+
const indexPattern = extractIndexPatternFrom(params);
31+
32+
if (!checkAllIndicesInPatternAreDeprecationLogs(indexPattern)) {
33+
return { isMatch: false };
34+
}
35+
36+
return {
37+
isMatch: true,
38+
context: {
39+
category: DataSourceCategory.Logs,
40+
},
41+
};
42+
},
43+
});
44+
45+
/*
46+
This function returns true if the index pattern belongs to deprecation logs.
47+
It also considers multiple patterns separated by commas.
48+
*/
49+
const checkAllIndicesInPatternAreDeprecationLogs = (indexPattern: string | null): boolean => {
50+
if (!indexPattern) {
51+
return false;
52+
}
53+
const indexPatternArray = indexPattern.split(',');
54+
const result = indexPatternArray.reduce(
55+
(acc, val) => acc && val.startsWith(DEPRECATION_LOGS_PATTERN_PREFIX),
56+
true
57+
);
58+
return result;
59+
};

src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from './profile_provider_services';
2929
import type { DiscoverServices } from '../../build_services';
3030
import { createObservabilityRootProfileProvider } from './observability/observability_root_profile';
31+
import { createDeprecationLogsDataSourceProfileProvider } from './common/deprecation_logs';
3132

3233
/**
3334
* Register profile providers for root, data source, and document contexts to the profile profile services
@@ -133,6 +134,7 @@ const createRootProfileProviders = (providerServices: ProfileProviderServices) =
133134
*/
134135
const createDataSourceProfileProviders = (providerServices: ProfileProviderServices) => [
135136
createExampleDataSourceProfileProvider(),
137+
createDeprecationLogsDataSourceProfileProvider(),
136138
...createObservabilityLogsDataSourceProfileProviders(providerServices),
137139
];
138140

0 commit comments

Comments
 (0)