-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Discover] Add support for contextual awareness functional tests #185905
Merged
davismcphee
merged 14 commits into
elastic:main
from
davismcphee:one-discover-functional-tests
Jun 19, 2024
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ad83b20
Clean up profile service types and add initial enabled profiles imple…
davismcphee 831f324
Add registerProfileProviders and new example profiles
davismcphee 15147b5
Add Discover context awareness functional tests
davismcphee 9403b16
Fix registerProfileProviders async import
davismcphee c50090b
Add registerProfileProviders Jest tests
davismcphee eaf6d04
Add discover.experimental.enabledProfiles to rendering service test
davismcphee 1abc91b
Merge branch 'main' into one-discover-functional-tests
davismcphee 237d7be
Update registerProviders to shouldRegisterProviders
davismcphee 574d67f
Merge branch 'main' into one-discover-functional-tests
davismcphee bfde82e
Merge branch 'main' into one-discover-functional-tests
davismcphee 1aff791
Move logs profile registrations to registerProfileProviders
davismcphee 07a26a8
Simplify profile service handling in plugin.tsx
davismcphee 4fff149
Merge branch 'main' into one-discover-functional-tests
davismcphee de21734
Add missing data-test-subj
davismcphee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'; |
76 changes: 76 additions & 0 deletions
76
...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,76 @@ | ||
/* | ||
* 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 }}>(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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to add
data-test-subj
here as well, since this is also a customized renderer and not the original one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, added here: de21734