Skip to content

Commit

Permalink
[8.x] [One Discover] Add summary column for logs contextual experience (
Browse files Browse the repository at this point in the history
#192567) (#194389)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[One Discover] Add summary column for logs contextual experience
(#192567)](#192567)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Marco Antonio
Ghiani","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-30T09:08:03Z","message":"[One
Discover] Add summary column for logs contextual experience
(#192567)\n\n## 📓 Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/165\r\n\r\nThis work
introduces a Summary column as a replacement for the Document\r\none for
the Discover logs contextual experience.\r\n> We also decided to port
this change as a replacement for the\r\n**resource** and **content**
virtual columns in Logs Explorer to have a\r\nbetter alignment between
the 2 apps.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/3dfca483-768e-471c-8735-d5fc8bbd5d00\r\n\r\n##
💡 Reviewer hints\r\n\r\nI left notes through the changes to help answer
some questions.\r\n\r\nThe notable changes on this PR are:\r\n- Rename
`Document` column to `Summary`.\r\n- Refactor `resource` and `content`
virtual columns into a single\r\n`Summary` column, which replaces the
default Summary content for the\r\nlogs' contextual experience.\r\n-
Provide support for the plugin services to the context
awareness\r\nprofiles.\r\n- Disable virtual columns (clean up will go in
a follow-up work) in Logs\r\nExplorer and rely on the Summary column as
the default selection.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco
Antonio Ghiani <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Davis McPhee
<[email protected]>","sha":"36a73ce52e2ca14c2d46c3a6504ebaa53fed9f98","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["v9.0.0","release_note:feature","Team:DataDiscovery","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-logs","Project:OneDiscover"],"title":"[One
Discover] Add summary column for logs contextual
experience","number":192567,"url":"https://github.com/elastic/kibana/pull/192567","mergeCommit":{"message":"[One
Discover] Add summary column for logs contextual experience
(#192567)\n\n## 📓 Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/165\r\n\r\nThis work
introduces a Summary column as a replacement for the Document\r\none for
the Discover logs contextual experience.\r\n> We also decided to port
this change as a replacement for the\r\n**resource** and **content**
virtual columns in Logs Explorer to have a\r\nbetter alignment between
the 2 apps.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/3dfca483-768e-471c-8735-d5fc8bbd5d00\r\n\r\n##
💡 Reviewer hints\r\n\r\nI left notes through the changes to help answer
some questions.\r\n\r\nThe notable changes on this PR are:\r\n- Rename
`Document` column to `Summary`.\r\n- Refactor `resource` and `content`
virtual columns into a single\r\n`Summary` column, which replaces the
default Summary content for the\r\nlogs' contextual experience.\r\n-
Provide support for the plugin services to the context
awareness\r\nprofiles.\r\n- Disable virtual columns (clean up will go in
a follow-up work) in Logs\r\nExplorer and rely on the Summary column as
the default selection.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco
Antonio Ghiani <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Davis McPhee
<[email protected]>","sha":"36a73ce52e2ca14c2d46c3a6504ebaa53fed9f98"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192567","number":192567,"mergeCommit":{"message":"[One
Discover] Add summary column for logs contextual experience
(#192567)\n\n## 📓 Summary\r\n\r\nCloses
https://github.com/elastic/logs-dev/issues/165\r\n\r\nThis work
introduces a Summary column as a replacement for the Document\r\none for
the Discover logs contextual experience.\r\n> We also decided to port
this change as a replacement for the\r\n**resource** and **content**
virtual columns in Logs Explorer to have a\r\nbetter alignment between
the 2 apps.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/3dfca483-768e-471c-8735-d5fc8bbd5d00\r\n\r\n##
💡 Reviewer hints\r\n\r\nI left notes through the changes to help answer
some questions.\r\n\r\nThe notable changes on this PR are:\r\n- Rename
`Document` column to `Summary`.\r\n- Refactor `resource` and `content`
virtual columns into a single\r\n`Summary` column, which replaces the
default Summary content for the\r\nlogs' contextual experience.\r\n-
Provide support for the plugin services to the context
awareness\r\nprofiles.\r\n- Disable virtual columns (clean up will go in
a follow-up work) in Logs\r\nExplorer and rely on the Summary column as
the default selection.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco
Antonio Ghiani <[email protected]>\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Davis McPhee
<[email protected]>","sha":"36a73ce52e2ca14c2d46c3a6504ebaa53fed9f98"}}]}]
BACKPORT-->

Co-authored-by: Marco Antonio Ghiani <[email protected]>
  • Loading branch information
kibanamachine and tonyghiani authored Sep 30, 2024
1 parent a2a135d commit a17659f
Show file tree
Hide file tree
Showing 92 changed files with 1,482 additions and 1,327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const degradedDocButtonLabelWhenPresent = i18n.translate(
'discover.customControl.degradedDocPresent',
{
defaultMessage:
"This document couldn't be parsed correctly. Not all fields are properly populated",
"This document couldn't be parsed correctly. Not all fields are properly populated.",
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface LogsContextService {
}

export interface LogsContextServiceDeps {
logsDataAccessPlugin?: LogsDataAccessPluginStart;
logsDataAccess?: LogsDataAccessPluginStart;
}

export const DEFAULT_ALLOWED_LOGS_BASE_PATTERNS = [
Expand All @@ -31,13 +31,11 @@ export const DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP = createRegExpPatternFrom
DEFAULT_ALLOWED_LOGS_BASE_PATTERNS
);

export const createLogsContextService = async ({
logsDataAccessPlugin,
}: LogsContextServiceDeps) => {
export const createLogsContextService = async ({ logsDataAccess }: LogsContextServiceDeps) => {
let logSources: string[] | undefined;

if (logsDataAccessPlugin) {
const logSourcesService = logsDataAccessPlugin.services.logSourcesService;
if (logsDataAccess) {
const logSourcesService = logsDataAccess.services.logSourcesService;
logSources = (await logSourcesService.getLogSources())
.map((logSource) => logSource.indexPattern)
.join(',') // TODO: Will be replaced by helper in: https://github.com/elastic/kibana/pull/192003
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './get_field_from_doc';
export * from './get_log_level_color';
export * from './get_log_level_coalesed_value';
5 changes: 4 additions & 1 deletion packages/kbn-discover-utils/src/utils/get_field_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import { DataTableRecord } from '../types';

export const getFieldValue = (record: DataTableRecord, field: string) => {
export const getFieldValue = <TRecord extends DataTableRecord, TField extends string>(
record: TRecord,
field: TField & keyof TRecord['flattened']
): TRecord['flattened'][TField] => {
const value = record.flattened[field];
return Array.isArray(value) ? value[0] : value;
};
18 changes: 4 additions & 14 deletions packages/kbn-discover-utils/src/utils/get_log_document_overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getLogDocumentOverview(
): LogDocumentOverview {
const formatField = <T extends keyof LogDocumentOverview>(field: T) => {
return (
field in doc.flattened
doc.flattened[field] !== undefined && doc.flattened[field] !== null
? formatFieldValue(
doc.flattened[field],
doc.raw,
Expand All @@ -32,19 +32,9 @@ export function getLogDocumentOverview(
const levelArray = doc.flattened[fieldConstants.LOG_LEVEL_FIELD];
const level =
Array.isArray(levelArray) && levelArray.length ? levelArray[0].toLowerCase() : levelArray;
const messageArray = doc.flattened[fieldConstants.MESSAGE_FIELD];
const message =
Array.isArray(messageArray) && messageArray.length ? messageArray[0] : messageArray;
const errorMessageArray = doc.flattened[fieldConstants.ERROR_MESSAGE_FIELD];
const errorMessage =
Array.isArray(errorMessageArray) && errorMessageArray.length
? errorMessageArray[0]
: errorMessageArray;
const eventOriginalArray = doc.flattened[fieldConstants.EVENT_ORIGINAL_FIELD];
const eventOriginal =
Array.isArray(eventOriginalArray) && eventOriginalArray.length
? eventOriginalArray[0]
: eventOriginalArray;
const message = formatField(fieldConstants.MESSAGE_FIELD);
const errorMessage = formatField(fieldConstants.ERROR_MESSAGE_FIELD);
const eventOriginal = formatField(fieldConstants.EVENT_ORIGINAL_FIELD);
const timestamp = formatField(fieldConstants.TIMESTAMP_FIELD);

// Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getFieldFromDoc, LogDocument, StackTraceFields } from '..';
import { getFieldValue, LogDocument, StackTraceFields } from '..';
import {
ERROR_EXCEPTION_STACKTRACE,
ERROR_LOG_STACKTRACE,
ERROR_STACK_TRACE,
} from '../field_constants';

export const getStacktraceFields = (doc: LogDocument): StackTraceFields => {
const errorStackTrace = getFieldFromDoc(doc, ERROR_STACK_TRACE);
const errorExceptionStackTrace = getFieldFromDoc(doc, ERROR_EXCEPTION_STACKTRACE);
const errorLogStackTrace = getFieldFromDoc(doc, ERROR_LOG_STACKTRACE);
const errorStackTrace = getFieldValue(doc, ERROR_STACK_TRACE);
const errorExceptionStackTrace = getFieldValue(doc, ERROR_EXCEPTION_STACKTRACE);
const errorLogStackTrace = getFieldValue(doc, ERROR_LOG_STACKTRACE);

return {
[ERROR_STACK_TRACE]: errorStackTrace,
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-unified-data-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export {
RowHeightSettings,
type RowHeightSettingsProps,
} from './src/components/row_height_settings';
export { getDisplayedColumns } from './src/utils/columns';
export { getDisplayedColumns, SOURCE_COLUMN } from './src/utils/columns';
export { getTextBasedColumnsMeta } from './src/utils/get_columns_meta';
export { ROWS_HEIGHT_OPTIONS, DataGridDensity } from './src/constants';

export { JSONCodeEditorCommonMemoized } from './src/components/json_code_editor/json_code_editor_common';
export { SourceDocument } from './src/components/source_document';

export * from './src/types';
export * as columnActions from './src/components/actions/columns';
Expand All @@ -37,3 +38,6 @@ export {
getRenderCustomToolbarWithElements,
renderCustomToolbar,
} from './src/components/custom_toolbar/render_custom_toolbar';

export { getDataGridDensity } from './src/hooks/use_data_grid_density';
export { getRowHeight } from './src/hooks/use_row_height';
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getColumnDisplayName = (

if (columnName === '_source') {
return i18n.translate('unifiedDataTable.grid.documentHeader', {
defaultMessage: 'Document',
defaultMessage: 'Summary',
});
}

Expand Down
18 changes: 11 additions & 7 deletions packages/kbn-unified-data-table/src/hooks/use_data_grid_density.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ interface UseDataGridDensityProps {
onUpdateDataGridDensity?: (density: DataGridDensity) => void;
}

export const DATA_GRID_DENSITY_STORAGE_KEY = 'dataGridDensity';

export function getDensityFromStyle(style: EuiDataGridStyle) {
return style.cellPadding === DATA_GRID_STYLE_COMPACT.cellPadding &&
style.fontSize === DATA_GRID_STYLE_COMPACT.fontSize
Expand All @@ -42,24 +40,30 @@ export function getDensityFromStyle(style: EuiDataGridStyle) {
: DataGridDensity.EXPANDED;
}

const DATA_GRID_DENSITY_STORAGE_KEY = 'dataGridDensity';
const getStorageKey = (consumer: string) => `${consumer}:${DATA_GRID_DENSITY_STORAGE_KEY}`;

export const getDataGridDensity = (storage: Storage, consumer: string): DataGridDensity => {
return storage.get(getStorageKey(consumer)) ?? DataGridDensity.COMPACT;
};

export const useDataGridDensity = ({
storage,
consumer,
dataGridDensityState,
onUpdateDataGridDensity,
}: UseDataGridDensityProps) => {
const storageKey = `${consumer}:${DATA_GRID_DENSITY_STORAGE_KEY}`;
const dataGridDensity = useMemo<DataGridDensity>(() => {
return dataGridDensityState ?? storage.get(storageKey) ?? DataGridDensity.COMPACT;
}, [dataGridDensityState, storage, storageKey]);
return dataGridDensityState ?? getDataGridDensity(storage, consumer);
}, [consumer, dataGridDensityState, storage]);

const onChangeDataGridDensity = useCallback(
(gridStyle: EuiDataGridStyle) => {
const newDensity = getDensityFromStyle(gridStyle);
storage.set(storageKey, newDensity);
storage.set(getStorageKey(consumer), newDensity);
onUpdateDataGridDensity?.(newDensity);
},
[storageKey, storage, onUpdateDataGridDensity]
[storage, consumer, onUpdateDataGridDensity]
);

return {
Expand Down
77 changes: 60 additions & 17 deletions packages/kbn-unified-data-table/src/hooks/use_row_height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,59 @@ interface UseRowHeightProps {
onUpdateRowHeight?: (rowHeight: number) => void;
}

interface ResolveRowHeightParams {
storage: Storage;
consumer: string;
key: string;
configRowHeight: number;
rowHeightState?: number;
}

const resolveRowHeight = ({
storage,
consumer,
key,
configRowHeight,
rowHeightState,
}: ResolveRowHeightParams): number => {
const rowHeightFromLS = getStoredRowHeight(storage, consumer, key);

const configHasNotChanged = (
localStorageRecord: DataGridOptionsRecord | null
): localStorageRecord is DataGridOptionsRecord =>
localStorageRecord !== null && configRowHeight === localStorageRecord.previousConfigRowHeight;

let currentRowLines: number;
if (isValidRowHeight(rowHeightState)) {
currentRowLines = rowHeightState;
} else if (configHasNotChanged(rowHeightFromLS)) {
currentRowLines = rowHeightFromLS.previousRowHeight;
} else {
currentRowLines = configRowHeight;
}

return currentRowLines;
};

export const ROW_HEIGHT_STORAGE_KEY = 'dataGridRowHeight';

export const getRowHeight = ({
storage,
consumer,
rowHeightState,
configRowHeight,
}: Pick<ResolveRowHeightParams, 'storage' | 'consumer' | 'rowHeightState'> & {
configRowHeight?: number;
}) => {
return resolveRowHeight({
storage,
consumer,
key: ROW_HEIGHT_STORAGE_KEY,
configRowHeight: configRowHeight ?? ROWS_HEIGHT_OPTIONS.default,
rowHeightState,
});
};

export const useRowHeight = ({
storage,
consumer,
Expand All @@ -36,23 +89,13 @@ export const useRowHeight = ({
onUpdateRowHeight,
}: UseRowHeightProps) => {
const rowHeightLines = useMemo(() => {
const rowHeightFromLS = getStoredRowHeight(storage, consumer, key);

const configHasNotChanged = (
localStorageRecord: DataGridOptionsRecord | null
): localStorageRecord is DataGridOptionsRecord =>
localStorageRecord !== null && configRowHeight === localStorageRecord.previousConfigRowHeight;

let currentRowLines: number;
if (isValidRowHeight(rowHeightState)) {
currentRowLines = rowHeightState;
} else if (configHasNotChanged(rowHeightFromLS)) {
currentRowLines = rowHeightFromLS.previousRowHeight;
} else {
currentRowLines = configRowHeight;
}

return currentRowLines;
return resolveRowHeight({
storage,
consumer,
key,
configRowHeight,
rowHeightState,
});
}, [configRowHeight, consumer, key, rowHeightState, storage]);

const rowHeight = useMemo<RowHeightSettingsProps['rowHeight']>(() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/kbn-unified-data-table/src/utils/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

import type { DataView } from '@kbn/data-views-plugin/public';

export const SOURCE_COLUMN = '_source';

// We store this outside the function as a constant, so we're not creating a new array every time
// the function is returning this. A changing array might cause the data grid to think it got
// new columns, and thus performing worse than using the same array over multiple renders.
const SOURCE_ONLY = ['_source'];
const SOURCE_ONLY = [SOURCE_COLUMN];

/**
* Function to provide fallback when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const defaultProps: EuiDataGridCellPopoverElementProps = {
cellContentsElement: (<div>{'cellContentsElement'}</div>) as unknown as HTMLDivElement,
};

const renderTestComponent = () => {
const renderTestComponent = (overrideProps = {}) => {
const Renderer = getCustomCellPopoverRenderer();

render(<Renderer {...defaultProps} />);
render(<Renderer {...defaultProps} {...overrideProps} />);
};

describe('getCustomCellPopoverRenderer', () => {
Expand All @@ -45,4 +45,17 @@ describe('getCustomCellPopoverRenderer', () => {
panelClassName: 'unifiedDataTable__cellPopover',
});
});

it('should render a DefaultCellPopover with a wider panel for allowed columns', () => {
renderTestComponent({ columnId: '_source' });

expect(setCellPopoverPropsMocks).toHaveBeenCalledWith({
panelClassName: 'unifiedDataTable__cellPopover',
panelProps: {
css: {
maxInlineSize: 'min(75vw, 600px) !important',
},
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import { EuiDataGridCellPopoverElementProps } from '@elastic/eui';
import React, { memo, useEffect } from 'react';
import { SOURCE_COLUMN } from './columns';

const FIELDS_WITH_WIDE_POPOVER = [SOURCE_COLUMN];

/*
*
Expand All @@ -23,13 +26,20 @@ export const getCustomCellPopoverRenderer = () => {
const RenderCustomCellPopoverMemoized = memo(function RenderCustomCellPopoverMemoized(
props: EuiDataGridCellPopoverElementProps
) {
const { setCellPopoverProps, DefaultCellPopover } = props;
const { columnId, setCellPopoverProps, DefaultCellPopover } = props;

useEffect(() => {
setCellPopoverProps({
const popoverProps: Parameters<typeof setCellPopoverProps>[0] = {
panelClassName: 'unifiedDataTable__cellPopover',
});
}, [setCellPopoverProps]);
};

const shouldRenderWidePopover = FIELDS_WITH_WIDE_POPOVER.includes(columnId);
if (shouldRenderWidePopover) {
popoverProps.panelProps = { css: { maxInlineSize: 'min(75vw, 600px) !important' } };
}

setCellPopoverProps(popoverProps);
}, [columnId, setCellPopoverProps]);

return <DefaultCellPopover {...props} />;
});
Expand Down
Loading

0 comments on commit a17659f

Please sign in to comment.