Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,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
Comment on lines +1145 to +1146
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @elastic/kibana-management

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 { 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 => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

@davismcphee davismcphee Dec 11, 2024

Choose a reason for hiding this comment

The 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;
};
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 { createDeprecationLogsDocumentProfileProvider } 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(),
createDeprecationLogsDocumentProfileProvider(),
...createObservabilityLogsDataSourceProfileProviders(providerServices),
];

Expand Down