Skip to content
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

[One Discover] Add summary column for logs contextual experience #192567

Merged
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4e757a6
feat(discover): rename Document column to Summary
Sep 5, 2024
027cfdf
feat(discover): support discover services in profiles definition
Sep 6, 2024
21ca23e
refactor(discover): minor components adjustments
Sep 6, 2024
4358037
refactor(discover): resource column
Sep 6, 2024
9401f2a
feat(discover): responsive summary column
Sep 9, 2024
7c12e0b
feat(discover): custom popover
Sep 9, 2024
83c5b16
feat(discover): custom popover mvp
Sep 10, 2024
313fc72
refactor(discover): update summary conditions
Sep 11, 2024
bad95d1
refactor(discover): rename virtual column service
Sep 11, 2024
a8fb2d0
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 11, 2024
d1c1db5
Merge branch 'tonyghiani-feature/one-discover-summary-column-copy' in…
Sep 11, 2024
1acb0bc
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 11, 2024
0bbbcd8
refactor(discover): minor cleanups
Sep 11, 2024
c397fae
refactor(discover): update popover content
Sep 11, 2024
50e3000
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 12, 2024
bc6c06a
refactor(discover): apply lazy loading on summary column
Sep 12, 2024
63a5578
refactor(discover): remove cell popover
Sep 12, 2024
315a4db
refactor(discover): remove unused file
Sep 12, 2024
2c02f59
refactor(logs-explorer): switch to new summary column
Sep 12, 2024
307bbbc
refactor(logs-explorer): disable resource and content as default columns
Sep 12, 2024
5576690
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 13, 2024
b4f7759
Merge branch 'tonyghiani-feature/one-discover-summary-column' into fe…
Sep 13, 2024
bf1c501
refactor(discover): move summary column files
Sep 13, 2024
77671be
refactor(discover): align font size depending on grid params
Sep 13, 2024
63b468e
refactor(discover): fix broken tests
Sep 13, 2024
a055078
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 13, 2024
1b23a48
refactor(discover): fix i18n
Sep 13, 2024
afc9e47
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 16, 2024
6f45e83
test(discover): add basic testing for summary column
Sep 16, 2024
e479c2c
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 17, 2024
37b84af
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 17, 2024
403123a
refactor(discover): update getFieldValue and remove duplicate getFiel…
Sep 17, 2024
69c78bc
refactor(discover): minor code changes
Sep 17, 2024
3b459d6
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 17, 2024
a0bf65b
refactor(discover): update checks
Sep 17, 2024
0e35022
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 17, 2024
bcf90dd
test(logs-explorer): skip tests for disabled features
Sep 17, 2024
7052b4e
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 17, 2024
4a1d21c
refactor(discover): fix conflict
Sep 17, 2024
ae6e75f
refactor(discover): skip tests for disabled features
Sep 17, 2024
d7c489b
refactor(discover): update test
Sep 17, 2024
a08552e
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 18, 2024
8bef034
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 18, 2024
97e90e5
Merge branch 'tonyghiani-feature/one-discover-summary-column' into fe…
Sep 18, 2024
ae8f145
refactor(discover): update test
Sep 18, 2024
93666a9
refactor(discover): use EuiCopy
Sep 20, 2024
b0fe55a
fix(discover): conditionally render resource block when missing for b…
Sep 20, 2024
e147b75
fix(discover): remove pre-optimization
Sep 20, 2024
e87d6a8
fix(discover): make popover wide for limited columns
Sep 20, 2024
4e0c3d4
fix(discover): pre-compute shouldShowFieldHandler once when creating …
Sep 20, 2024
7936e12
fix(discover): types and test
Sep 20, 2024
d5f2b91
fix(discover): remove profile manager singleton
Sep 20, 2024
aa06ab8
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 20, 2024
933b080
perf(discover): optimize document formatting to remove properties
Sep 20, 2024
b4f8a07
fix(discover): remove import
Sep 23, 2024
a0e5539
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 24, 2024
430cedc
refactor(discover): update styles
Sep 24, 2024
fff5e35
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 24, 2024
58ee8be
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 24, 2024
8938421
refactor(discover): update styles
Sep 24, 2024
69f3135
Merge branch 'feature/one-discover-summary-column' of github.com:tony…
Sep 24, 2024
42a4501
feat(discover): apply shared actions to summary column
Sep 24, 2024
1ba9d3a
refactor(discover): update test
Sep 24, 2024
ed9bc98
test(discover): add FT for summary column displaying
Sep 24, 2024
c01f2cc
test(discover): update FT test
Sep 24, 2024
ac22f2d
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 25, 2024
690ecfa
fix(discover): conflicts
Sep 25, 2024
a2cd794
refactor(discover): update styles and cleanup
Sep 25, 2024
a3ac8fe
refactor(discover): add popover close button
Sep 25, 2024
505dbc1
refactor(discover): remove unnecessary wrapper
Sep 25, 2024
9ff0c54
Fix default grid density and row height passed to getCellRenderers
davismcphee Sep 26, 2024
456d268
refactor(discover): change requests
Sep 26, 2024
4afb2a0
Merge pull request #2 from davismcphee/fix-default-density-and-row-he…
tonyghiani Sep 26, 2024
5bbe0a7
refactor(discover): fix imports
Sep 26, 2024
9199821
refactor(discover): remove unused property
Sep 26, 2024
1fe2ebf
refactor(discover): revert log level badge styles
Sep 27, 2024
cd0d7df
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 27, 2024
70d4bb6
Merge branch 'main' into feature/one-discover-summary-column
tonyghiani Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>(
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
record: TRecord,
field: TField & keyof TRecord['flattened']
): TRecord['flattened'][TField] => {
const value = record.flattened[field];
return Array.isArray(value) ? value[0] : value;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 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 Down
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import {
ROW_HEIGHT_OPTION,
SHOW_MULTIFIELDS,
} from '@kbn/discover-utils';
import { DataLoadingState, UnifiedDataTableProps } from '@kbn/unified-data-table';
import {
DataGridDensity,
DataLoadingState,
ROWS_HEIGHT_OPTIONS,
UnifiedDataTableProps,
} from '@kbn/unified-data-table';
import { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
import { useQuerySubscriber } from '@kbn/unified-field-list';
import useObservable from 'react-use/lib/useObservable';
Expand Down Expand Up @@ -173,8 +178,13 @@ export function ContextAppContent({
const getCellRenderersAccessor = useProfileAccessor('getCellRenderers');
const cellRenderers = useMemo(() => {
const getCellRenderers = getCellRenderersAccessor(() => ({}));
return getCellRenderers();
}, [getCellRenderersAccessor]);
return getCellRenderers({
actions: { addFilter },
dataView,
density: DataGridDensity.COMPACT,
rowHeight: ROWS_HEIGHT_OPTIONS.single,
tonyghiani marked this conversation as resolved.
Show resolved Hide resolved
});
}, [addFilter, dataView, getCellRenderersAccessor]);

const dataSource = useMemo(() => createDataSource({ dataView, query: undefined }), [dataView]);
const { filters } = useQuerySubscriber({ data: services.data });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ describe('Discover documents layout', () => {
const discoverGridComponent = component.find(DiscoverGrid);
expect(discoverGridComponent.exists()).toBeTruthy();
expect(Object.keys(discoverGridComponent.prop('externalCustomRenderers')!)).toEqual([
'content',
'resource',
'_source',
'rootProfile',
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { useContextualGridCustomisations } from '../../hooks/grid_customisations
import { useIsEsqlMode } from '../../hooks/use_is_esql_mode';
import { useAdditionalFieldGroups } from '../../hooks/sidebar/use_additional_field_groups';
import {
CellRenderersExtensionParams,
DISCOVER_CELL_ACTIONS_TRIGGER,
useAdditionalCellActions,
useProfileAccessor,
Expand Down Expand Up @@ -306,16 +307,26 @@ function DiscoverDocumentsComponent({
[dataView, onAddColumn, onAddFilter, onRemoveColumn, query, savedSearch.id, setExpandedDoc]
);

const cellRendererParams: CellRenderersExtensionParams = useMemo(
() => ({
actions: { addFilter: onAddFilter },
dataView,
density,
rowHeight,
}),
[onAddFilter, dataView, density, rowHeight]
);

const { rowAdditionalLeadingControls } = useDiscoverCustomization('data_table') || {};
const { customCellRenderer, customGridColumnsConfiguration } =
useContextualGridCustomisations() || {};
useContextualGridCustomisations(cellRendererParams) || {};
const additionalFieldGroups = useAdditionalFieldGroups();

const getCellRenderersAccessor = useProfileAccessor('getCellRenderers');
const cellRenderers = useMemo(() => {
const getCellRenderers = getCellRenderersAccessor(() => customCellRenderer ?? {});
return getCellRenderers();
}, [customCellRenderer, getCellRenderersAccessor]);
return getCellRenderers(cellRendererParams);
}, [cellRendererParams, customCellRenderer, getCellRenderersAccessor]);

const documents = useObservable(stateContainer.dataState.data$.documents$);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@
*/

import { useMemo } from 'react';
import { useDiscoverServices } from '../../../../hooks/use_discover_services';
import { useDiscoverCustomization } from '../../../../customizations';
import { getLogsVirtualColumnsConfiguration } from './logs';
import { DataGridColumnsDeps, getDataGridColumnsConfiguration } from './logs';

export * from './logs';

export const useContextualGridCustomisations = () => {
const { data } = useDiscoverServices();
type ContextualGridCustomizationParams = DataGridColumnsDeps;

export const useContextualGridCustomisations = (params: ContextualGridCustomizationParams) => {
// 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 getDataGridColumnsConfiguration(params);
}, [isLogsContext, params]);

return virtualColumnsConfiguration;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
* License v3.0 only", 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';
import { SOURCE_COLUMN } from '@kbn/unified-data-table';
import {
SummaryColumnGetterDeps,
getSummaryColumn,
} from '../../../../components/data_types/logs/summary_column';

export const getLogsVirtualColumnsConfiguration = (data: DataPublicPluginStart) => {
export type DataGridColumnsDeps = CustomCellRendererDeps;

export const getDataGridColumnsConfiguration = (params: DataGridColumnsDeps) => {
return {
customCellRenderer: createCustomCellRenderer({ data }),
customCellRenderer: createCustomCellRenderer(params),
customGridColumnsConfiguration: createCustomGridColumnsConfiguration(),
};
};

export const createCustomCellRenderer = ({ data }: { data: DataPublicPluginStart }) => {
type CustomCellRendererDeps = SummaryColumnGetterDeps;

export const createCustomCellRenderer = (params: CustomCellRendererDeps) => {
return {
[CONTENT_FIELD]: renderCell(CONTENT_FIELD, { data }),
[RESOURCE_FIELD]: renderCell(RESOURCE_FIELD, { data }),
[SOURCE_COLUMN]: getSummaryColumn(params),
};
};

export const createCustomGridColumnsConfiguration = () => ({
[CONTENT_FIELD]: renderColumn(CONTENT_FIELD),
[RESOURCE_FIELD]: renderColumn(RESOURCE_FIELD),
});
export const createCustomGridColumnsConfiguration = () => ({});

This file was deleted.

Loading