-
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.
[One Discover] Push Smart Fields / Virtual Columns down into Discover (…
…#181870) ## Summary Implements **part one** of #181674. The main focus here is to get the code for Smart Fields and Virtual Columns located within Discover. Whilst some hooks have been added to decide what to register / render these should most definitely be treated as "subject to change" once the real data type context awareness lands in Discover. For now these hooks rely on the old extension points to say "yes, this is a logs context". As far as I could see other solutions are not using the extension points that have been temporarily altered here. As this is functionality related to a data type (logs) and not a solution (observability, for example) this is all treated as a first class citizen. Some code has been moved to the `discover-utils`. ## Reviewer notes - Nothing should really have *changed*, this is mostly about verifying that the Smart Fields and Virtual Columns still work as expected when using Logs Explorer (and that core Discover still works as expected). Please also check the Flyout still works as expected as this was rebased on top of https://github.com/elastic/kibana/pull/180262/files and there were some conflicts between file relocation in the two. - There are a couple of components now duplicated in Discover and Logs Explorer as the `actions` column still uses them and hasn't been moved across yet. <img width="306" alt="Screenshot 2024-04-28 at 15 39 15" src="https://github.com/elastic/kibana/assets/471693/7b56df75-8b0b-41a7-8f15-f1066ef269d7"> <img width="1183" alt="Screenshot 2024-04-28 at 15 39 21" src="https://github.com/elastic/kibana/assets/471693/167ab53c-9e86-464d-9622-86d87b311b46"> --------- Co-authored-by: Achyut Jhunjhunwala <[email protected]>
- Loading branch information
1 parent
c4ef9bd
commit 2de84ce
Showing
47 changed files
with
812 additions
and
194 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
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 * from './logs'; |
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,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 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 * from './types'; | ||
export * from './utils'; |
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
7 changes: 4 additions & 3 deletions
7
...lic/utils/get_field_from_flattened_doc.ts → ...ta_types/logs/utils/get_field_from_doc.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
9 changes: 9 additions & 0 deletions
9
packages/kbn-discover-utils/src/data_types/logs/utils/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 * from './get_field_from_doc'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 { fieldConstants } from '@kbn/discover-utils'; | ||
import { SmartFieldGridColumnOptions } from './display_options'; | ||
|
||
export * from '@kbn/discover-utils/src/field_constants'; | ||
|
||
export const LOGS_EXPLORER_PROFILE_ID = 'logs-explorer'; | ||
|
||
// Virtual column fields | ||
export const CONTENT_FIELD = 'content'; | ||
export const RESOURCE_FIELD = 'resource'; | ||
|
||
// Sizing | ||
export const DATA_GRID_COLUMN_WIDTH_SMALL = 240; | ||
export const DATA_GRID_COLUMN_WIDTH_MEDIUM = 320; | ||
export const ACTIONS_COLUMN_WIDTH = 80; | ||
|
||
export const RESOURCE_FIELD_CONFIGURATION: SmartFieldGridColumnOptions = { | ||
type: 'smart-field', | ||
smartField: RESOURCE_FIELD, | ||
fallbackFields: [fieldConstants.HOST_NAME_FIELD, fieldConstants.SERVICE_NAME_FIELD], | ||
width: DATA_GRID_COLUMN_WIDTH_MEDIUM, | ||
}; | ||
|
||
export const CONTENT_FIELD_CONFIGURATION: SmartFieldGridColumnOptions = { | ||
type: 'smart-field', | ||
smartField: CONTENT_FIELD, | ||
fallbackFields: [fieldConstants.MESSAGE_FIELD], | ||
}; | ||
|
||
export const SMART_FALLBACK_FIELDS = { | ||
[CONTENT_FIELD]: CONTENT_FIELD_CONFIGURATION, | ||
[RESOURCE_FIELD]: RESOURCE_FIELD_CONFIGURATION, | ||
}; | ||
|
||
// UI preferences | ||
export const DEFAULT_COLUMNS = [RESOURCE_FIELD_CONFIGURATION, CONTENT_FIELD_CONFIGURATION]; | ||
export const DEFAULT_ROWS_PER_PAGE = 100; | ||
|
||
// List of prefixes which needs to be filtered out for Display in Content Column | ||
export const FILTER_OUT_FIELDS_PREFIXES_FOR_CONTENT = [ | ||
'_', // Filter fields like '_id', '_score' | ||
'@timestamp', | ||
'agent.', | ||
'elastic_agent.', | ||
'data_stream.', | ||
'ecs.', | ||
'host.', | ||
'container.', | ||
'cloud.', | ||
'kubernetes.', | ||
'orchestrator.', | ||
'log.', | ||
'service.', | ||
]; | ||
|
||
export const DEFAULT_ALLOWED_DATA_VIEWS = ['logs', 'auditbeat', 'filebeat', 'winlogbeat']; | ||
export const DEFAULT_ALLOWED_LOGS_DATA_VIEWS = ['logs', 'auditbeat', 'filebeat', 'winlogbeat']; |
14 changes: 14 additions & 0 deletions
14
src/plugins/discover/common/data_types/logs/display_options.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,14 @@ | ||
/* | ||
* 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 interface SmartFieldGridColumnOptions { | ||
type: 'smart-field'; | ||
smartField: 'content' | 'resource'; | ||
fallbackFields: string[]; | ||
width?: number; | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
src/plugins/discover/public/application/main/hooks/grid_customisations/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,28 @@ | ||
/* | ||
* 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 { useMemo } from 'react'; | ||
import { useDiscoverServices } from '../../../../hooks/use_discover_services'; | ||
import { useDiscoverCustomization } from '../../../../customizations'; | ||
import { getLogsVirtualColumnsConfiguration } from './logs'; | ||
|
||
export * from './logs'; | ||
|
||
export const useContextualGridCustomisations = () => { | ||
const { data } = useDiscoverServices(); | ||
// TODO / NOTE: This will eventually rely on Discover's context resolution to determine which fields | ||
// are returned based on the data type. | ||
const isLogsContext = useDiscoverCustomization('data_table')?.logsEnabled; | ||
|
||
const virtualColumnsConfiguration = useMemo(() => { | ||
if (!isLogsContext) return null; | ||
if (isLogsContext) return getLogsVirtualColumnsConfiguration(data); | ||
}, [data, isLogsContext]); | ||
|
||
return virtualColumnsConfiguration; | ||
}; |
31 changes: 31 additions & 0 deletions
31
src/plugins/discover/public/application/main/hooks/grid_customisations/logs.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,31 @@ | ||
/* | ||
* 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 { DataPublicPluginStart } from '@kbn/data-plugin/public'; | ||
import { CONTENT_FIELD, RESOURCE_FIELD } from '../../../../../common/data_types/logs/constants'; | ||
import { renderCell } from '../../../../components/discover_grid/virtual_columns/logs/cell_renderer'; | ||
import { renderColumn } from '../../../../components/discover_grid/virtual_columns/logs/column'; | ||
|
||
export const getLogsVirtualColumnsConfiguration = (data: DataPublicPluginStart) => { | ||
return { | ||
customCellRenderer: createCustomCellRenderer({ data }), | ||
customGridColumnsConfiguration: createCustomGridColumnsConfiguration(), | ||
}; | ||
}; | ||
|
||
export const createCustomCellRenderer = ({ data }: { data: DataPublicPluginStart }) => { | ||
return { | ||
[CONTENT_FIELD]: renderCell(CONTENT_FIELD, { data }), | ||
[RESOURCE_FIELD]: renderCell(RESOURCE_FIELD, { data }), | ||
}; | ||
}; | ||
|
||
export const createCustomGridColumnsConfiguration = () => ({ | ||
[CONTENT_FIELD]: renderColumn(CONTENT_FIELD), | ||
[RESOURCE_FIELD]: renderColumn(RESOURCE_FIELD), | ||
}); |
23 changes: 23 additions & 0 deletions
23
...iscover/public/application/main/hooks/grid_customisations/use_virtual_column_services.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,23 @@ | ||
/* | ||
* 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 createContainer from 'constate'; | ||
import type { DataView } from '@kbn/data-views-plugin/common'; | ||
import { DataPublicPluginStart } from '@kbn/data-plugin/public'; | ||
|
||
export interface UseVirtualColumnServices { | ||
services: { | ||
data: DataPublicPluginStart; | ||
dataView: DataView; | ||
}; | ||
} | ||
|
||
const useVirtualColumns = ({ services }: UseVirtualColumnServices) => services; | ||
|
||
export const [VirtualColumnServiceProvider, useVirtualColumnServiceContext] = | ||
createContainer(useVirtualColumns); |
Oops, something went wrong.