-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Add support for contextual awareness functional tests (#18…
…5905) ## Summary This PR adds functional test support for the Discover contextual awareness framework, and adds tests for the initial `getCellRenderers` extension point using example profiles. To support this, this PR introduces a new YAML setting called `discover.experimental.enabledProfiles` which can be used to selectively enable profiles both for functional testing and demoing WIP profiles that aren't yet ready for GA. Example usage: ```yml discover.experimental.enabledProfiles: ['example-root-profile', 'example-data-source-profile', 'example-document-profile'] ``` Flaky test runs: - Stateful x50: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6304 - Serverless Observability x50: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6305 - Serverless Search x50: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6306 - Serverless Security x50: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6307 Resolves #184699. ### 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 - [x] [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#kibana-release-notes-process)
- Loading branch information
1 parent
06f7739
commit 57891ff
Showing
35 changed files
with
1,072 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
.../discover/public/context_awareness/profile_providers/example_data_source_profile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { exampleDataSourceProfileProvider } from './profile'; |
83 changes: 83 additions & 0 deletions
83
...scover/public/context_awareness/profile_providers/example_data_source_profile/profile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiBadge } from '@elastic/eui'; | ||
import type { DataTableRecord } from '@kbn/discover-utils'; | ||
import { isOfAggregateQueryType } from '@kbn/es-query'; | ||
import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils'; | ||
import { euiThemeVars } from '@kbn/ui-theme'; | ||
import { capitalize } from 'lodash'; | ||
import React from 'react'; | ||
import { DataSourceType, isDataSourceType } from '../../../../common/data_sources'; | ||
import { DataSourceCategory, DataSourceProfileProvider } from '../../profiles'; | ||
|
||
export const exampleDataSourceProfileProvider: DataSourceProfileProvider = { | ||
profileId: 'example-data-source-profile', | ||
profile: { | ||
getCellRenderers: (prev) => () => ({ | ||
...prev(), | ||
'log.level': (props) => { | ||
const level = getFieldValue(props.row, 'log.level'); | ||
|
||
if (!level) { | ||
return ( | ||
<span | ||
css={{ color: euiThemeVars.euiTextSubduedColor }} | ||
data-test-subj="exampleDataSourceProfileLogLevelEmpty" | ||
> | ||
(None) | ||
</span> | ||
); | ||
} | ||
|
||
const levelMap: Record<string, string> = { | ||
info: 'primary', | ||
debug: 'default', | ||
error: 'danger', | ||
}; | ||
|
||
return ( | ||
<EuiBadge | ||
color={levelMap[level]} | ||
title={level} | ||
data-test-subj="exampleDataSourceProfileLogLevel" | ||
> | ||
{capitalize(level)} | ||
</EuiBadge> | ||
); | ||
}, | ||
}), | ||
}, | ||
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(); | ||
} | ||
|
||
if (indexPattern !== 'my-example-logs') { | ||
return { isMatch: false }; | ||
} | ||
|
||
return { | ||
isMatch: true, | ||
context: { category: DataSourceCategory.Logs }, | ||
}; | ||
}, | ||
}; | ||
|
||
const getFieldValue = (record: DataTableRecord, field: string) => { | ||
const value = record.flattened[field]; | ||
return Array.isArray(value) ? value[0] : value; | ||
}; |
9 changes: 9 additions & 0 deletions
9
...ins/discover/public/context_awareness/profile_providers/example_document_profile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { exampleDocumentProfileProvider } from './profile'; |
32 changes: 32 additions & 0 deletions
32
...s/discover/public/context_awareness/profile_providers/example_document_profile/profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { DataTableRecord } from '@kbn/discover-utils'; | ||
import { DocumentProfileProvider, DocumentType } from '../../profiles'; | ||
|
||
export const exampleDocumentProfileProvider: DocumentProfileProvider = { | ||
profileId: 'example-document-profile', | ||
profile: {}, | ||
resolve: (params) => { | ||
if (getFieldValue(params.record, 'data_stream.type') !== 'logs') { | ||
return { isMatch: false }; | ||
} | ||
|
||
return { | ||
isMatch: true, | ||
context: { | ||
type: DocumentType.Log, | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
const getFieldValue = (record: DataTableRecord, field: string) => { | ||
const value = record.flattened[field]; | ||
return Array.isArray(value) ? value[0] : value; | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { exampleRootProfileProvider } from './profile'; |
42 changes: 42 additions & 0 deletions
42
...ugins/discover/public/context_awareness/profile_providers/example_root_pofile/profile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiBadge } from '@elastic/eui'; | ||
import type { DataTableRecord } from '@kbn/discover-utils'; | ||
import React from 'react'; | ||
import { RootProfileProvider, SolutionType } from '../../profiles'; | ||
|
||
export const exampleRootProfileProvider: RootProfileProvider = { | ||
profileId: 'example-root-profile', | ||
profile: { | ||
getCellRenderers: (prev) => () => ({ | ||
...prev(), | ||
'@timestamp': (props) => { | ||
const timestamp = getFieldValue(props.row, '@timestamp'); | ||
|
||
return ( | ||
<EuiBadge color="hollow" title={timestamp} data-test-subj="exampleRootProfileTimestamp"> | ||
{timestamp} | ||
</EuiBadge> | ||
); | ||
}, | ||
}), | ||
}, | ||
resolve: (params) => { | ||
if (params.solutionNavId != null) { | ||
return { isMatch: false }; | ||
} | ||
|
||
return { isMatch: true, context: { solutionType: SolutionType.Default } }; | ||
}, | ||
}; | ||
|
||
const getFieldValue = (record: DataTableRecord, field: string) => { | ||
const value = record.flattened[field]; | ||
return Array.isArray(value) ? value[0] : value; | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/plugins/discover/public/context_awareness/profile_providers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { registerProfileProviders } from './register_profile_providers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.