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

[8.x] [Discover] Only show logs profiles for O11y solution view (#199255) #200477

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { createLogsDataSourceProfileProviders } from './create_profile_providers';
export const OBSERVABILITY_ROOT_PROFILE_ID = 'observability-root-profile';
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { createLogDocumentProfileProvider } from './profile';
export { createObservabilityLogDocumentProfileProvider } from './profile';
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@ import { DocViewsRegistry } from '@kbn/unified-doc-viewer';
import {
DataSourceCategory,
DataSourceContext,
DocumentProfileProviderParams,
DocumentType,
RootContext,
SolutionType,
} from '../../../profiles';
import { createContextAwarenessMocks } from '../../../__mocks__';
import { createLogDocumentProfileProvider } from './profile';
import { createObservabilityLogDocumentProfileProvider } from './profile';
import { ContextWithProfileId } from '../../../profile_service';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';

const mockServices = createContextAwarenessMocks().profileProviderServices;

describe('logDocumentProfileProvider', () => {
const logDocumentProfileProvider = createLogDocumentProfileProvider(mockServices);
const ROOT_CONTEXT: RootContext = { solutionType: SolutionType.Default };
const DATA_SOURCE_CONTEXT: DataSourceContext = { category: DataSourceCategory.Logs };
const logDocumentProfileProvider = createObservabilityLogDocumentProfileProvider(mockServices);
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const DATA_SOURCE_CONTEXT: ContextWithProfileId<DataSourceContext> = {
profileId: 'data-source-profile',
category: DataSourceCategory.Logs,
};
const RESOLUTION_MATCH = {
isMatch: true,
context: {
Expand Down Expand Up @@ -99,6 +108,42 @@ describe('logDocumentProfileProvider', () => {
).toEqual(RESOLUTION_MISMATCH);
});

it('does not match records when solution type is not Observability', () => {
const params: Omit<DocumentProfileProviderParams, 'rootContext'> = {
dataSourceContext: DATA_SOURCE_CONTEXT,
record: buildMockRecord('another-index', {
'data_stream.type': ['logs'],
}),
};
expect(
logDocumentProfileProvider.resolve({
...params,
rootContext: ROOT_CONTEXT,
})
).toEqual(RESOLUTION_MATCH);
expect(
logDocumentProfileProvider.resolve({
...params,
rootContext: { profileId: 'other-data-source-profile', solutionType: SolutionType.Default },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
logDocumentProfileProvider.resolve({
...params,
rootContext: { profileId: 'other-data-source-profile', solutionType: SolutionType.Search },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
logDocumentProfileProvider.resolve({
...params,
rootContext: {
profileId: 'other-data-source-profile',
solutionType: SolutionType.Security,
},
})
).toEqual(RESOLUTION_MISMATCH);
});

describe('getDocViewer', () => {
it('adds a log overview doc view to the registry', () => {
const getDocViewer = logDocumentProfileProvider.profile.getDocViewer!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ import { DataTableRecord } from '@kbn/discover-utils';
import { DocumentProfileProvider, DocumentType } from '../../../profiles';
import { ProfileProviderServices } from '../../profile_provider_services';
import { getDocViewer } from './accessors';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';

export const createLogDocumentProfileProvider = (
export const createObservabilityLogDocumentProfileProvider = (
services: ProfileProviderServices
): DocumentProfileProvider => ({
profileId: 'log-document-profile',
profileId: 'observability-log-document-profile',
profile: {
getDocViewer,
},
resolve: ({ record }) => {
resolve: ({ record, rootContext }) => {
if (rootContext.profileId !== OBSERVABILITY_ROOT_PROFILE_ID) {
return { isMatch: false };
}

const isLogRecord = getIsLogRecord(record, services.logsContextService.isLogsIndexPattern);

if (!isLogRecord) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {
createWindowsLogsDataSourceProfileProvider,
} from './sub_profiles';

export const createLogsDataSourceProfileProviders = (providerServices: ProfileProviderServices) => {
export const createObservabilityLogsDataSourceProfileProviders = (
providerServices: ProfileProviderServices
) => {
const logsDataSourceProfileProvider = createLogsDataSourceProfileProvider(providerServices);

return [
Expand Down
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 { createObservabilityLogsDataSourceProfileProviders } from './create_profile_providers';
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import { buildDataTableRecord } from '@kbn/discover-utils';
import type { EuiThemeComputed } from '@elastic/eui';
import { createStubIndexPattern } from '@kbn/data-views-plugin/common/data_view.stub';
import { createDataViewDataSource, createEsqlDataSource } from '../../../../../common/data_sources';
import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles';
import {
DataSourceCategory,
DataSourceProfileProviderParams,
RootContext,
SolutionType,
} from '../../../profiles';
import { createContextAwarenessMocks } from '../../../__mocks__';
import { createLogsDataSourceProfileProvider } from './profile';
import { DataGridDensity } from '@kbn/unified-data-table';
import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield';
import type { ContextWithProfileId } from '../../../profile_service';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';

const mockServices = createContextAwarenessMocks().profileProviderServices;

Expand All @@ -24,7 +31,10 @@ describe('logsDataSourceProfileProvider', () => {
const VALID_INDEX_PATTERN = 'logs-nginx.access-*';
const MIXED_INDEX_PATTERN = 'logs-nginx.access-*,metrics-*';
const INVALID_INDEX_PATTERN = 'my_source-access-*';
const ROOT_CONTEXT: RootContext = { solutionType: SolutionType.Default };
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const RESOLUTION_MATCH = {
isMatch: true,
context: { category: DataSourceCategory.Logs },
Expand Down Expand Up @@ -87,6 +97,34 @@ describe('logsDataSourceProfileProvider', () => {
).toEqual(RESOLUTION_MISMATCH);
});

it('does NOT match data view sources when solution type is not Observability', () => {
const params: Omit<DataSourceProfileProviderParams, 'rootContext'> = {
dataSource: createEsqlDataSource(),
query: { esql: `from ${VALID_INDEX_PATTERN}` },
};
expect(logsDataSourceProfileProvider.resolve({ ...params, rootContext: ROOT_CONTEXT })).toEqual(
RESOLUTION_MATCH
);
expect(
logsDataSourceProfileProvider.resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Default },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
logsDataSourceProfileProvider.resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Search },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
logsDataSourceProfileProvider.resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Security },
})
).toEqual(RESOLUTION_MISMATCH);
});

const dataViewWithLogLevel = createStubIndexPattern({
spec: {
title: VALID_INDEX_PATTERN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ import {
getRowAdditionalLeadingControls,
} from './accessors';
import { extractIndexPatternFrom } from '../../extract_index_pattern_from';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../consts';

export const createLogsDataSourceProfileProvider = (
services: ProfileProviderServices
): DataSourceProfileProvider => ({
profileId: 'logs-data-source-profile',
profileId: 'observability-logs-data-source-profile',
profile: {
getCellRenderers,
getRowIndicatorProvider,
getRowAdditionalLeadingControls,
},
resolve: (params) => {
if (params.rootContext.profileId !== OBSERVABILITY_ROOT_PROFILE_ID) {
return { isMatch: false };
}

const indexPattern = extractIndexPatternFrom(params);

if (!services.logsContextService.isLogsIndexPattern(indexPattern)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import { DataSourceCategory, RootContext, SolutionType } from '../../../../profi
import { createContextAwarenessMocks } from '../../../../__mocks__';
import { createLogsDataSourceProfileProvider } from '../profile';
import { createApacheErrorLogsDataSourceProfileProvider } from './apache_error_logs';
import type { ContextWithProfileId } from '../../../../profile_service';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../../consts';

const ROOT_CONTEXT: RootContext = { solutionType: SolutionType.Default };
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const { profileProviderServices } = createContextAwarenessMocks();
const logsDataSourceProfileProvider = createLogsDataSourceProfileProvider(profileProviderServices);
const dataSourceProfileProvider = createApacheErrorLogsDataSourceProfileProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createApacheErrorLogsDataSourceProfileProvider = (
logsDataSourceProfileProvider: DataSourceProfileProvider
): DataSourceProfileProvider =>
extendProfileProvider(logsDataSourceProfileProvider, {
profileId: 'apache-error-logs-data-source',
profileId: 'observability-apache-error-logs-data-source-profile',
profile: {
getDefaultAppState: createGetDefaultAppState({
defaultColumns: [LOG_LEVEL_COLUMN, CLIENT_IP_COLUMN, MESSAGE_COLUMN],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import { DataSourceCategory, RootContext, SolutionType } from '../../../../profi
import { createContextAwarenessMocks } from '../../../../__mocks__';
import { createLogsDataSourceProfileProvider } from '../profile';
import { createAwsS3accessLogsDataSourceProfileProvider } from './aws_s3access_logs';
import type { ContextWithProfileId } from '../../../../profile_service';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../../consts';

const ROOT_CONTEXT: RootContext = { solutionType: SolutionType.Default };
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const { profileProviderServices } = createContextAwarenessMocks();
const logsDataSourceProfileProvider = createLogsDataSourceProfileProvider(profileProviderServices);
const dataSourceProfileProvider = createAwsS3accessLogsDataSourceProfileProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createAwsS3accessLogsDataSourceProfileProvider = (
logsDataSourceProfileProvider: DataSourceProfileProvider
): DataSourceProfileProvider =>
extendProfileProvider(logsDataSourceProfileProvider, {
profileId: 'aws-s3access-logs-data-source',
profileId: 'observability-aws-s3access-logs-data-source-profile',
profile: {
getDefaultAppState: createGetDefaultAppState({
defaultColumns: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 type { ContextWithProfileId } from '../../../../profile_service';
import { createEsqlDataSource } from '../../../../../../common/data_sources';
import {
DataSourceCategory,
DataSourceProfileProviderParams,
RootContext,
SolutionType,
} from '../../../../profiles';
import { createResolve } from './create_resolve';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../../consts';

describe('createResolve', () => {
const VALID_INDEX_PATTERN = 'valid';
const INVALID_INDEX_PATTERN = 'invalid';
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const RESOLUTION_MATCH = {
isMatch: true,
context: { category: DataSourceCategory.Logs },
};
const RESOLUTION_MISMATCH = {
isMatch: false,
};
const resolve = createResolve(VALID_INDEX_PATTERN);

it('should match a valid index pattern', () => {
const result = resolve({
rootContext: ROOT_CONTEXT,
dataSource: createEsqlDataSource(),
query: { esql: `FROM ${VALID_INDEX_PATTERN}` },
});
expect(result).toEqual(RESOLUTION_MATCH);
});

it('should not match an invalid index pattern', () => {
const result = resolve({
rootContext: ROOT_CONTEXT,
dataSource: createEsqlDataSource(),
query: { esql: `FROM ${INVALID_INDEX_PATTERN}` },
});
expect(result).toEqual(RESOLUTION_MISMATCH);
});

it('should not match when the solution type is not Observability', () => {
const params: Omit<DataSourceProfileProviderParams, 'rootContext'> = {
dataSource: createEsqlDataSource(),
query: { esql: `FROM ${VALID_INDEX_PATTERN}` },
};
expect(
resolve({
...params,
rootContext: ROOT_CONTEXT,
})
).toEqual(RESOLUTION_MATCH);
expect(
resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Default },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Search },
})
).toEqual(RESOLUTION_MISMATCH);
expect(
resolve({
...params,
rootContext: { profileId: 'other-root-profile', solutionType: SolutionType.Security },
})
).toEqual(RESOLUTION_MISMATCH);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import { createRegExpPatternFrom, testPatternAgainstAllowedList } from '@kbn/data-view-utils';
import { DataSourceCategory, DataSourceProfileProvider } from '../../../../profiles';
import { extractIndexPatternFrom } from '../../../extract_index_pattern_from';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../../consts';

export const createResolve = (baseIndexPattern: string): DataSourceProfileProvider['resolve'] => {
const testIndexPattern = testPatternAgainstAllowedList([
createRegExpPatternFrom(baseIndexPattern),
]);

return (params) => {
if (params.rootContext.profileId !== OBSERVABILITY_ROOT_PROFILE_ID) {
return { isMatch: false };
}

const indexPattern = extractIndexPatternFrom(params);

if (!indexPattern || !testIndexPattern(indexPattern)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import { DataSourceCategory, RootContext, SolutionType } from '../../../../profi
import { createContextAwarenessMocks } from '../../../../__mocks__';
import { createLogsDataSourceProfileProvider } from '../profile';
import { createKubernetesContainerLogsDataSourceProfileProvider } from './kubernetes_container_logs';
import { ContextWithProfileId } from '../../../../profile_service';
import { OBSERVABILITY_ROOT_PROFILE_ID } from '../../consts';

const ROOT_CONTEXT: RootContext = { solutionType: SolutionType.Default };
const ROOT_CONTEXT: ContextWithProfileId<RootContext> = {
profileId: OBSERVABILITY_ROOT_PROFILE_ID,
solutionType: SolutionType.Observability,
};
const { profileProviderServices } = createContextAwarenessMocks();
const logsDataSourceProfileProvider = createLogsDataSourceProfileProvider(profileProviderServices);
const dataSourceProfileProvider = createKubernetesContainerLogsDataSourceProfileProvider(
Expand Down
Loading