Skip to content

Commit

Permalink
[Discover] Only show logs profiles for O11y solution view (elastic#19…
Browse files Browse the repository at this point in the history
…9255)

## Summary

This PR updates the current logs data source profiles and log document
profile to only be active in the Observability solution view. It also
restructures some folders to conform to the solution folder conventions
in our docs. Lastly it restructures the functional tests so that the
logs profiles tests only run for Observability serverless projects, and
the core context awareness suite only tests example implementations.

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)
- [ ] This will appear in the **Release Notes** and follow 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
2 people authored and CAWilson94 committed Nov 18, 2024
1 parent be93259 commit a3be2c7
Show file tree
Hide file tree
Showing 60 changed files with 1,305 additions and 1,622 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai
/x-pack/test/functional/apps/dataset_quality @elastic/obs-ux-logs-team
/x-pack/test_serverless/functional/test_suites/observability/dataset_quality @elastic/obs-ux-logs-team
/x-pack/test_serverless/functional/test_suites/observability/ @elastic/obs-ux-logs-team
/x-pack/test_serverless/functional/test_suites/observability/discover @elastic/obs-ux-logs-team @elastic/kibana-data-discovery
/src/plugins/unified_doc_viewer/public/components/doc_viewer_logs_overview @elastic/obs-ux-logs-team
/x-pack/test/api_integration/apis/logs_shared @elastic/obs-ux-logs-team

Expand Down
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
Loading

0 comments on commit a3be2c7

Please sign in to comment.