Skip to content

Commit d9b00c5

Browse files
qn895kibanamachine
andauthored
[ML] Fix data visualizer grid failing if one of the fields failed and not updating when refreshed (#115644) (#118267)
* [ML] Initial embed * [ML] Initial embed props * [ML] Add top nav link to data viz * Add visible fields * Add add data service to register links * Renames, refactor, use constants * Renames, refactor, use constants * Update tests and mocks * Embeddable * Update hook to update upon time udpate * Add filter support to query * Refactor filter utilities * Add filter support for embeddable * Fix saved search data undefined * Prototype aggregated view/document view switcher * Prototype flyout * Prototype save document view option in storage * Fix filter and query conflict with saved search * Minor styling edits * [ML] Initial embed * [ML] Initial embed props * Add embeddable 1 * Add visible fields * Embeddable 2 * Add filter support to query * Refactor filter utilities * Add filter support for embeddable * Fix saved search data undefined * Prototype aggregated view/document view switcher * Prototype flyout * Prototype save document view option in storage * Fix filter and query conflict with saved search * Minor styling edits * Fix missing code after conflicts * Remove dv locator and flyout * Make types happy * Fix types * Rename toggle option * Resolve conflicts * [ML] Reduce size of chart * [ML] Unbold name, switch icons of show distributions * [ML] Make size consistent * [ML] Make page size 25 * [ML] Switch to arrow right and down * [ML] Make legend font smaller * [ML] Add user setting * [ML] Add show preview by default setting * [ML] Match icon * Add panels around the subcontent * Add preference for aggregated vs doc * Fix types * Fix types, add constants for adv settings * Change to data view type * Temp fix for Kibana/EUI table overflow issue * Modify line height so text is not cut off, modify widths for varying screen sizes * Different width padders for different screens * Fix CI * Merge latest, move button to the right * Fix width for bar charts previews * Fix toggle buttons, fix maps * Delete unused file * Fix boolean styling * Change to enum, discover mode * Hide field stats * Hide field stats * Persist show mini preview/distribution settings * Remove window size, use size observer instead * Default to document view * Remove bold, switch icon * Set fixed width for top values, reduce font size in table * Fix custom url tests * Update width styling for panels * Fix missing flag for Discover sidebar, jest tests * Fix max width * Workaround for sorting * Fix import * Fix styling * Make height uniform, center alignment, fix map and keyword map not same size Move styling * Revert "Make height uniform, center alignment, fix map and keyword map not same size" This reverts commit 8fc42e2 * Revert "Make height uniform, center alignment, fix map and keyword map not same size" This reverts commit 8fc42e2 * Uniform height, left aligned, flex grid * Switch top values to have labels * Center content * Replace fixed widths with percentage * Fix table missing field types * Add dashboard embeddable and filter support * Fix file data viz styling and tests, lean up imports, remove hard coded pixels * Add search panel/kql filter bar * Temporarily fix scrolling * New kql filters for data visualizer * Set map height so it will fit the sampler shard size text * Use eui progress labels * Fix spacer * Add beta badge * Temporarily fix scrolling * Fix grow for Top Values for * [ML] Update functional tests to reflect new arrow icons * [ML] Add filter buttons and KQL bars * [ML] Update filter bar onChange behavior * [ML] Update top values filter onChange behavior * [ML] Update search filters when opening saved search * [ML] Clean up * [ML] Remove fit content for height * [ML] Fix boolean legend * [ML] Fix header section when browser width is small to large and when index pattern title is too large * [ML] Hide expander icon when dimension is xs or s & css fixes * [ML] Delete embeddables because they are not use * [ML] Rename view mode, refactor to separate hook, add error prompt if can't show, rename wrapper, clean up & fix tests * [ML] Make doc count 0 for empty fields, update t/f test * [ML] Add unit testing for search utils * Fix missing unsubscribe for embeddable output * Remove redundant onAddFilter for this PR, fix width * Rename Field Stats to Field stats to match convention * [ML] Fix expand all/collapse all behavior to override individual setting * [ML] Fix functional tests should be 0/0% * [ML] Fix docs content spacing, rename classnames, add filters to Discover, lens, and maps * [ML] Fix doc count for fields that exists but have no stats * [ML] Fix icon styling to match Discover but have text/keyword/histogram * [ML] Fix doc count for fields that exists but have no stats * [ML] Rename classnames to BEM style * Resolve latest changes * Add in place ss * Refactor helper functions * Refactor helper functions * Add error log * Migrate overall stats to data's search * Better handle errors * Fix url so restore session brings back correct view * Add progress bar * [ML] Add tests for data viz in Discover * [ML] Change to combinelatest * Update tests & dashboard behavior to reflect new advanced settings * Update telemetry * Remove workaround after eui bump fix * Remove dataloader * Snapshot * Migrate search to client side * Consolidate types * Change back to forkjoin instead of combinelatest for overallstats * Fix missing bool clause * Add login * Fix saved search attributes broken with latest changes * Update tests * Fix import * Match the no results found * Reset field stats so it reloads when query is refreshed * Reset field stats so it reloads when query is refreshed * Add doc stats * Merge to use hook completely * Merge to use hook completely * Fix doc chart doesn't show up when page is first mounted * Fix Discover auto refresh previously didn't update * Fix query util to return search source's results right away. Fix texts. * Refactor documentStats * Fix doc stats not showing upon page mount * Fix types * Delete old files * Update tests & i18n * Fix examples, tests * Remove old files & routes * Add telemetry, clean up, rename components for clarity * Fix size of callout message * Fix texts field * Consolidate field type * Consolidate field type, add count to top values * Clean up * Update tests * Remove progress on embedadble * Update snapshot * Clean up, consolidate searchOptions * Fix new es client types * Fix types * Fix loading state in Discover * Remove unused services, Change switchMap to map, mergeMap -> switchMap, update types * Fix missing filters * Fix message of table to show searching instead of no items found * Fix dashboard saved search source persisting time range * [ML] Fix table message state * [ML] Fix to not fetch field stats if cardinality is 0 * [ML] Fix locator missing view mode * [ML] Quit right away if field doesn't exist in docs * [ML] Change to use batch and only retry with individual field if failed * [ML] Batch requests for speed and retry failures for resiliency * No need to fetch field stats if overall stats haven't completed * Wait on overallStats to complete * Fix types after merge * Fix payload size too big 413, num of requests * Update field icon to using kbn/react-field package Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 3c6db50 commit d9b00c5

File tree

95 files changed

+2368
-3736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2368
-3736
lines changed

src/plugins/discover/public/application/apps/main/components/layout/discover_layout.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ import {
4343
SavedSearchURLConflictCallout,
4444
useSavedSearchAliasMatchRedirect,
4545
} from '../../../../../saved_searches';
46-
import { DiscoverDataVisualizerGrid } from '../../../../components/data_visualizer_grid';
4746
import { VIEW_MODE } from '../view_mode_toggle';
47+
import {
48+
DOCUMENTS_VIEW_CLICK,
49+
FIELD_STATISTICS_VIEW_CLICK,
50+
} from '../../../../components/field_stats_table/constants';
51+
import { FieldStatisticsTable } from '../../../../components/field_stats_table';
4852

4953
/**
5054
* Local storage key for sidebar persistence state
@@ -54,7 +58,7 @@ export const SIDEBAR_CLOSED_KEY = 'discover:sidebarClosed';
5458
const SidebarMemoized = React.memo(DiscoverSidebarResponsive);
5559
const TopNavMemoized = React.memo(DiscoverTopNav);
5660
const DiscoverChartMemoized = React.memo(DiscoverChart);
57-
const DataVisualizerGridMemoized = React.memo(DiscoverDataVisualizerGrid);
61+
const FieldStatisticsTableMemoized = React.memo(FieldStatisticsTable);
5862

5963
export function DiscoverLayout({
6064
indexPattern,
@@ -95,8 +99,16 @@ export function DiscoverLayout({
9599
const setDiscoverViewMode = useCallback(
96100
(mode: VIEW_MODE) => {
97101
stateContainer.setAppState({ viewMode: mode });
102+
103+
if (trackUiMetric) {
104+
if (mode === VIEW_MODE.AGGREGATED_LEVEL) {
105+
trackUiMetric(METRIC_TYPE.CLICK, FIELD_STATISTICS_VIEW_CLICK);
106+
} else {
107+
trackUiMetric(METRIC_TYPE.CLICK, DOCUMENTS_VIEW_CLICK);
108+
}
109+
}
98110
},
99-
[stateContainer]
111+
[trackUiMetric, stateContainer]
100112
);
101113

102114
const fetchCounter = useRef<number>(0);
@@ -315,7 +327,7 @@ export function DiscoverLayout({
315327
stateContainer={stateContainer}
316328
/>
317329
) : (
318-
<DataVisualizerGridMemoized
330+
<FieldStatisticsTableMemoized
319331
savedSearch={savedSearch}
320332
services={services}
321333
indexPattern={indexPattern}
@@ -324,6 +336,8 @@ export function DiscoverLayout({
324336
columns={columns}
325337
stateContainer={stateContainer}
326338
onAddFilter={onAddFilter}
339+
trackUiMetric={trackUiMetric}
340+
savedSearchRefetch$={savedSearchRefetch$}
327341
/>
328342
)}
329343
</EuiFlexGroup>

src/plugins/discover/public/application/apps/main/components/sidebar/discover_field.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ const FieldInfoIcon: React.FC = memo(() => (
5858
</EuiToolTip>
5959
));
6060

61-
const DiscoverFieldTypeIcon: React.FC<{ field: IndexPatternField }> = memo(({ field }) => (
62-
<FieldIcon type={field.type} label={getFieldTypeName(field.type)} scripted={field.scripted} />
63-
));
61+
const DiscoverFieldTypeIcon: React.FC<{ field: IndexPatternField }> = memo(({ field }) => {
62+
// If it's a string type, we want to distinguish between keyword and text
63+
const tempType = field.type === 'string' && field.esTypes ? field.esTypes[0] : field.type;
64+
return <FieldIcon type={tempType} label={getFieldTypeName(tempType)} scripted={field.scripted} />;
65+
});
6466

6567
const FieldName: React.FC<{ field: IndexPatternField }> = memo(({ field }) => {
6668
const title =

src/plugins/discover/public/application/apps/main/components/sidebar/discover_sidebar.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { each, cloneDeep } from 'lodash';
9+
import { cloneDeep, each } from 'lodash';
1010
import { ReactWrapper } from 'enzyme';
1111
import { findTestSubject } from '@elastic/eui/lib/test';
1212
// @ts-expect-error

src/plugins/discover/public/application/apps/main/components/sidebar/lib/get_field_type_name.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export function getFieldTypeName(type: string) {
5151
return i18n.translate('discover.fieldNameIcons.stringFieldAriaLabel', {
5252
defaultMessage: 'String field',
5353
});
54+
case 'text':
55+
return i18n.translate('discover.fieldNameIcons.textFieldAriaLabel', {
56+
defaultMessage: 'Text field',
57+
});
58+
case 'keyword':
59+
return i18n.translate('discover.fieldNameIcons.keywordFieldAriaLabel', {
60+
defaultMessage: 'Keyword field',
61+
});
62+
5463
case 'nested':
5564
return i18n.translate('discover.fieldNameIcons.nestedFieldAriaLabel', {
5665
defaultMessage: 'Nested field',

src/plugins/discover/public/application/apps/main/services/discover_state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,5 +411,7 @@ function createUrlGeneratorState({
411411
}
412412
: undefined,
413413
useHash: false,
414+
viewMode: appState.viewMode,
415+
hideAggregatedPreview: appState.hideAggregatedPreview,
414416
};
415417
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
/** Telemetry related to field statistics table **/
10+
export const FIELD_STATISTICS_LOADED = 'field_statistics_loaded';
11+
export const FIELD_STATISTICS_VIEW_CLICK = 'field_statistics_view_click';
12+
export const DOCUMENTS_VIEW_CLICK = 'documents_view_click';
Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
*/
88

99
import React, { useEffect, useMemo, useRef, useState } from 'react';
10-
import { Filter } from '@kbn/es-query';
10+
import type { Filter } from '@kbn/es-query';
11+
import { METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics';
1112
import { IndexPatternField, IndexPattern, DataView, Query } from '../../../../../data/common';
12-
import { DiscoverServices } from '../../../build_services';
13+
import type { DiscoverServices } from '../../../build_services';
1314
import {
1415
EmbeddableInput,
1516
EmbeddableOutput,
1617
ErrorEmbeddable,
1718
IEmbeddable,
1819
isErrorEmbeddable,
1920
} from '../../../../../embeddable/public';
21+
import { FIELD_STATISTICS_LOADED } from './constants';
2022
import { SavedSearch } from '../../../saved_searches';
2123
import { GetStateReturn } from '../../apps/main/services/discover_state';
24+
import { DataRefetch$ } from '../../apps/main/services/use_saved_search';
2225

2326
export interface DataVisualizerGridEmbeddableInput extends EmbeddableInput {
2427
indexPattern: IndexPattern;
@@ -36,7 +39,7 @@ export interface DataVisualizerGridEmbeddableOutput extends EmbeddableOutput {
3639
showDistributions?: boolean;
3740
}
3841

39-
export interface DiscoverDataVisualizerGridProps {
42+
export interface FieldStatisticsTableProps {
4043
/**
4144
* Determines which columns are displayed
4245
*/
@@ -69,14 +72,24 @@ export interface DiscoverDataVisualizerGridProps {
6972
* Filters query to update the table content
7073
*/
7174
filters?: Filter[];
75+
/**
76+
* State container with persisted settings
77+
*/
7278
stateContainer?: GetStateReturn;
7379
/**
7480
* Callback to add a filter to filter bar
7581
*/
7682
onAddFilter?: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
83+
/**
84+
* Metric tracking function
85+
* @param metricType
86+
* @param eventName
87+
*/
88+
trackUiMetric?: (metricType: UiCounterMetricType, eventName: string | string[]) => void;
89+
savedSearchRefetch$?: DataRefetch$;
7790
}
7891

79-
export const DiscoverDataVisualizerGrid = (props: DiscoverDataVisualizerGridProps) => {
92+
export const FieldStatisticsTable = (props: FieldStatisticsTableProps) => {
8093
const {
8194
services,
8295
indexPattern,
@@ -86,9 +99,10 @@ export const DiscoverDataVisualizerGrid = (props: DiscoverDataVisualizerGridProp
8699
filters,
87100
stateContainer,
88101
onAddFilter,
102+
trackUiMetric,
103+
savedSearchRefetch$,
89104
} = props;
90105
const { uiSettings } = services;
91-
92106
const [embeddable, setEmbeddable] = useState<
93107
| ErrorEmbeddable
94108
| IEmbeddable<DataVisualizerGridEmbeddableInput, DataVisualizerGridEmbeddableOutput>
@@ -109,10 +123,16 @@ export const DiscoverDataVisualizerGrid = (props: DiscoverDataVisualizerGridProp
109123
}
110124
});
111125

126+
const refetch = savedSearchRefetch$?.subscribe(() => {
127+
if (embeddable && !isErrorEmbeddable(embeddable)) {
128+
embeddable.updateInput({ lastReloadRequestTime: Date.now() });
129+
}
130+
});
112131
return () => {
113132
sub?.unsubscribe();
133+
refetch?.unsubscribe();
114134
};
115-
}, [embeddable, stateContainer]);
135+
}, [embeddable, stateContainer, savedSearchRefetch$]);
116136

117137
useEffect(() => {
118138
if (embeddable && !isErrorEmbeddable(embeddable)) {
@@ -135,17 +155,11 @@ export const DiscoverDataVisualizerGrid = (props: DiscoverDataVisualizerGridProp
135155
embeddable.updateInput({
136156
showPreviewByDefault,
137157
});
158+
138159
embeddable.reload();
139160
}
140161
}, [showPreviewByDefault, uiSettings, embeddable]);
141162

142-
useEffect(() => {
143-
return () => {
144-
// Clean up embeddable upon unmounting
145-
embeddable?.destroy();
146-
};
147-
}, [embeddable]);
148-
149163
useEffect(() => {
150164
let unmounted = false;
151165
const loadEmbeddable = async () => {
@@ -181,8 +195,15 @@ export const DiscoverDataVisualizerGrid = (props: DiscoverDataVisualizerGridProp
181195
useEffect(() => {
182196
if (embeddableRoot.current && embeddable) {
183197
embeddable.render(embeddableRoot.current);
198+
199+
trackUiMetric?.(METRIC_TYPE.LOADED, FIELD_STATISTICS_LOADED);
184200
}
185-
}, [embeddable, embeddableRoot, uiSettings]);
201+
202+
return () => {
203+
// Clean up embeddable upon unmounting
204+
embeddable?.destroy();
205+
};
206+
}, [embeddable, embeddableRoot, uiSettings, trackUiMetric]);
186207

187208
return (
188209
<div
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88

99
import React from 'react';
1010
import { I18nProvider } from '@kbn/i18n/react';
11-
import {
12-
DiscoverDataVisualizerGrid,
13-
DiscoverDataVisualizerGridProps,
14-
} from './data_visualizer_grid';
11+
import { FieldStatisticsTable, FieldStatisticsTableProps } from './field_stats_table';
1512

16-
export function FieldStatsTableEmbeddable(renderProps: DiscoverDataVisualizerGridProps) {
13+
export function FieldStatsTableSavedSearchEmbeddable(renderProps: FieldStatisticsTableProps) {
1714
return (
1815
<I18nProvider>
19-
<DiscoverDataVisualizerGrid
16+
<FieldStatisticsTable
2017
savedSearch={renderProps.savedSearch}
2118
services={renderProps.services}
2219
indexPattern={renderProps.indexPattern}

src/plugins/discover/public/application/components/data_visualizer_grid/index.ts renamed to src/plugins/discover/public/application/components/field_stats_table/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
* Side Public License, v 1.
77
*/
88

9-
export { DiscoverDataVisualizerGrid } from './data_visualizer_grid';
9+
export { FieldStatisticsTable } from './field_stats_table';
10+
export { FieldStatsTableSavedSearchEmbeddable } from './field_stats_table_saved_search_embeddable';

src/plugins/discover/public/application/embeddable/saved_search_embeddable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { getDefaultSort } from '../apps/main/components/doc_table';
4747
import { SortOrder } from '../apps/main/components/doc_table/components/table_header/helpers';
4848
import { updateSearchSource } from './helpers/update_search_source';
4949
import { VIEW_MODE } from '../apps/main/components/view_mode_toggle';
50-
import { FieldStatsTableEmbeddable } from '../components/data_visualizer_grid/field_stats_table_embeddable';
50+
import { FieldStatsTableSavedSearchEmbeddable } from '../components/field_stats_table';
5151

5252
export type SearchProps = Partial<DiscoverGridProps> &
5353
Partial<DocTableProps> & {
@@ -391,7 +391,7 @@ export class SavedSearchEmbeddable
391391
Array.isArray(searchProps.columns)
392392
) {
393393
ReactDOM.render(
394-
<FieldStatsTableEmbeddable
394+
<FieldStatsTableSavedSearchEmbeddable
395395
services={searchProps.services}
396396
indexPattern={searchProps.indexPattern}
397397
columns={searchProps.columns}

0 commit comments

Comments
 (0)