forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make link to es deprecation logs more useful (elastic#203487)
## Summary resolves elastic#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]>
- Loading branch information
1 parent
5be7182
commit c423e3e
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ins/discover/public/context_awareness/profile_providers/common/deprecation_logs/consts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
10 changes: 10 additions & 0 deletions
10
...gins/discover/public/context_awareness/profile_providers/common/deprecation_logs/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
73 changes: 73 additions & 0 deletions
73
...scover/public/context_awareness/profile_providers/common/deprecation_logs/profile.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
...ns/discover/public/context_awareness/profile_providers/common/deprecation_logs/profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters