-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make link to es deprecation logs more useful #203487
Changes from 11 commits
9d3fadd
d53fb5d
3176ad2
da5ae21
452e81d
fa24ee3
a856ab0
13d00f6
82d153f
5af9e88
d660c8d
d344de7
d0e754e
29c7a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { createDeprecationLogsDocumentProfileProvider } from './profile'; | ||
jesuswr marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 { createDeprecationLogsDocumentProfileProvider } from './profile'; | ||
import type { ContextWithProfileId } from '../../../profile_service'; | ||
import { DEPRECATION_LOGS_PROFILE_ID } from './consts'; | ||
|
||
describe('deprecationLogsProfileProvider', () => { | ||
const deprecationLogsProfileProvider = createDeprecationLogsDocumentProfileProvider(); | ||
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, | ||
formatRecord: expect.any(Function), | ||
}, | ||
}; | ||
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,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 { isOfAggregateQueryType } from '@kbn/es-query'; | ||
import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils'; | ||
import { DataSourceCategory } from '../../../profiles'; | ||
import { DataSourceType, isDataSourceType } from '../../../../../common/data_sources'; | ||
import { type DataSourceProfileProvider } from '../../../profiles'; | ||
import { DEPRECATION_LOGS_PATTERN_PREFIX, DEPRECATION_LOGS_PROFILE_ID } from './consts'; | ||
|
||
export const createDeprecationLogsDocumentProfileProvider = (): DataSourceProfileProvider<{ | ||
formatRecord: (flattenedRecord: Record<string, unknown>) => string; | ||
}> => ({ | ||
jesuswr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
profileId: DEPRECATION_LOGS_PROFILE_ID, | ||
profile: { | ||
getDefaultAppState: () => () => ({ | ||
columns: [ | ||
{ name: 'log.level' }, | ||
{ name: 'message' }, | ||
{ name: 'elasticsearch.http.request.x_opaque_id' }, | ||
{ name: 'elasticsearch.cluster.name' }, | ||
{ name: 'elasticsearch.event.category' }, | ||
], | ||
}), | ||
jesuswr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
resolve: (params) => { | ||
let indexPattern: string | undefined; | ||
|
||
if (isDataSourceType(params.dataSource, DataSourceType.Esql)) { | ||
if (!isOfAggregateQueryType(params.query)) { | ||
return { isMatch: false }; | ||
} | ||
|
||
indexPattern = getIndexPatternFromESQLQuery(params.query.esql); | ||
} else if (isDataSourceType(params.dataSource, DataSourceType.DataView) && params.dataView) { | ||
indexPattern = params.dataView.getIndexPattern(); | ||
} | ||
jesuswr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!checkAllIndicesInPatternAreDeprecationLogs(indexPattern)) { | ||
return { isMatch: false }; | ||
} | ||
|
||
return { | ||
isMatch: true, | ||
context: { | ||
category: DataSourceCategory.Logs, | ||
formatRecord: (record) => JSON.stringify(record, null, 2), | ||
jesuswr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
/* | ||
This function returns true if the index pattern belongs to deprecation logs. | ||
It also considers multiple patterns separated by commas. | ||
*/ | ||
const checkAllIndicesInPatternAreDeprecationLogs = (indexPattern: string | undefined): boolean => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davismcphee Should this behaviour be included in the future helper you mentioned in the slack thread? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally forgot we already had a utility for extracting the index pattern, but I also think it would make sense to extract this if we find it's needed for other profiles in the future. |
||
if (!indexPattern) { | ||
return false; | ||
} | ||
const indexPatternArray = indexPattern.split(','); | ||
const result = indexPatternArray.reduce( | ||
(acc, val) => acc && val.startsWith(DEPRECATION_LOGS_PATTERN_PREFIX), | ||
true | ||
); | ||
return result; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @elastic/kibana-management