Skip to content

Commit

Permalink
[8.x] [Discover] Only show logs profiles for O11y solution view (elas…
Browse files Browse the repository at this point in the history
…tic#199255) (elastic#200477)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Discover] Only show logs profiles for O11y solution view
(elastic#199255)](elastic#199255)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-18T01:24:46Z","message":"[Discover]
Only show logs profiles for O11y solution view (elastic#199255)\n\n##
Summary\r\n\r\nThis PR updates the current logs data source profiles and
log document\r\nprofile to only be active in the Observability solution
view. It also\r\nrestructures some folders to conform to the solution
folder conventions\r\nin our docs. Lastly it restructures the functional
tests so that the\r\nlogs profiles tests only run for Observability
serverless projects, and\r\nthe core context awareness suite only tests
example implementations.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"bedc0d8ba638ce008de7a65e467f4af7562d46d6","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor","Project:OneDiscover"],"number":199255,"url":"https://github.com/elastic/kibana/pull/199255","mergeCommit":{"message":"[Discover]
Only show logs profiles for O11y solution view (elastic#199255)\n\n##
Summary\r\n\r\nThis PR updates the current logs data source profiles and
log document\r\nprofile to only be active in the Observability solution
view. It also\r\nrestructures some folders to conform to the solution
folder conventions\r\nin our docs. Lastly it restructures the functional
tests so that the\r\nlogs profiles tests only run for Observability
serverless projects, and\r\nthe core context awareness suite only tests
example implementations.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"bedc0d8ba638ce008de7a65e467f4af7562d46d6"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199255","number":199255,"mergeCommit":{"message":"[Discover]
Only show logs profiles for O11y solution view (elastic#199255)\n\n##
Summary\r\n\r\nThis PR updates the current logs data source profiles and
log document\r\nprofile to only be active in the Observability solution
view. It also\r\nrestructures some folders to conform to the solution
folder conventions\r\nin our docs. Lastly it restructures the functional
tests so that the\r\nlogs profiles tests only run for Observability
serverless projects, and\r\nthe core context awareness suite only tests
example implementations.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"bedc0d8ba638ce008de7a65e467f4af7562d46d6"}}]}]
BACKPORT-->
  • Loading branch information
davismcphee authored Nov 18, 2024
1 parent 8a49c1f commit dc645a7
Show file tree
Hide file tree
Showing 59 changed files with 1,304 additions and 1,622 deletions.
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

0 comments on commit dc645a7

Please sign in to comment.