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

[Discover] Allow to store the configured ES|QL visualization v3 (with migrations) #176530

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
38d4298
[Discover] Initial implementation for allowing to store ES|QL customi…
jughosta Jan 5, 2024
d3aaeeb
[Discover] Some refactoring
jughosta Jan 8, 2024
6f6f78b
[Discover] More refactoring
jughosta Jan 9, 2024
cc0ca64
Merge branch 'main' into 167887-esql-saved-search
jughosta Jan 9, 2024
631b174
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Jan 9, 2024
599653c
[Discover] Fix comparison for customVisualizationJSON
jughosta Jan 10, 2024
d982b33
[Discover] Support customization for histogram too. Reset when vis in…
jughosta Jan 11, 2024
97656ac
[Discover] Fix reverting saved search changes
jughosta Jan 11, 2024
ddb6b15
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 12, 2024
6347d35
[Discover] Some fixes to make customVisualization work
jughosta Jan 12, 2024
aa9946d
[Discover] Refactor what is being saved. Persist all Lens attributes …
jughosta Jan 12, 2024
d0b3d85
[Discover] Update suggestion selector
jughosta Jan 12, 2024
96dc0b8
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 12, 2024
1caa803
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 15, 2024
538e422
Merge remote-tracking branch 'origin/167887-esql-saved-search-v2' int…
jughosta Jan 15, 2024
6796374
[Discover] Fix suggestion change
jughosta Jan 15, 2024
f323642
[Discover] Fix suggestion type selector
jughosta Jan 15, 2024
266f99c
[Discover] Improve the resetting of suggestion
jughosta Jan 15, 2024
772a701
[Discover] Reduce the state size
jughosta Jan 15, 2024
1e33a59
[Discover] Extract saved search SO into a separate plugin
jughosta Jan 16, 2024
46b424b
[Discover] Try to reference Lens
jughosta Jan 16, 2024
fbf6910
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 16, 2024
6450c58
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jan 16, 2024
482121d
Merge branch 'main' into 167887-esql-saved-search-v2
jughosta Jan 17, 2024
cb8e18e
[Discover] Update tests
jughosta Jan 17, 2024
e49a423
[Discover] Clean up
jughosta Jan 17, 2024
08f30be
[Discover] Update tests
jughosta Jan 17, 2024
a1643b4
[Discover] Update tests
jughosta Jan 17, 2024
2033a6d
[Discover] Fix typescript errors
jughosta Jan 17, 2024
c9dbaba
[Discover] Remove some logging
jughosta Jan 17, 2024
c6ee408
[Discover] Some fixes
jughosta Jan 17, 2024
55e3641
[Discover] Don't reset the vis on save
jughosta Jan 17, 2024
98b3c9d
[Discover] Fix histogram case
jughosta Jan 17, 2024
70455f0
[Discover] Fix other case
jughosta Jan 17, 2024
cf130cf
[Discover] Refactor to a service
jughosta Jan 18, 2024
34d01f4
[Discover] Add fixes
jughosta Jan 18, 2024
494fde5
[Discover] Refactor to props
jughosta Jan 22, 2024
c4eb455
[Discover] Clean up
jughosta Jan 22, 2024
b882203
[Discover] Fix tests
jughosta Jan 22, 2024
14c224d
[Discover] Fix tests
jughosta Jan 22, 2024
f835ad3
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 22, 2024
a5b59aa
[Discover] Clean up
jughosta Jan 23, 2024
56ca482
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Jan 23, 2024
9996c5d
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Jan 23, 2024
1dc7474
[Discover] Simplify state management
jughosta Jan 23, 2024
5de6c05
[Discover] Update tests
jughosta Jan 24, 2024
73d5819
[Discover] Don't sync with URL
jughosta Jan 24, 2024
1871a4e
[Discover] Improve resetting of lens attributes
jughosta Jan 24, 2024
f28d4bd
[Discover] Add logging
jughosta Jan 24, 2024
ac9d3fe
[Discover] Remove suggestion from histogram main state
jughosta Jan 24, 2024
9ece3ce
[Discover] Return suggestion to histogram main state as it triggers r…
jughosta Jan 25, 2024
fc2ec95
[Discover] Disable logging
jughosta Jan 25, 2024
38c69af
[Discover] Fix breakdown field
jughosta Jan 26, 2024
003f7be
Merge branch 'main' into split-saved-search-plugin
jughosta Jan 30, 2024
ef7a1ea
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Jan 30, 2024
4181550
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 31, 2024
0328095
[Discover] Delay calculation of table until search is complete
jughosta Jan 31, 2024
6d23632
Migrate Lens Vis State to InternalStateContainer
kertal Jan 30, 2024
1b2fb11
[Discover] Skip syncing to internalStateContainer
jughosta Jan 31, 2024
db9a48d
[Discover] Change props format
jughosta Jan 31, 2024
c0eda01
[Discover] Back to the problem
jughosta Jan 31, 2024
ee25770
[Discover] Improve reverting logic
jughosta Jan 31, 2024
525e7c3
[Discover] Comment logs out
jughosta Feb 1, 2024
bad165d
[Discover] Comment logs out
jughosta Feb 1, 2024
7e53323
[Discover] Fix checks
jughosta Feb 1, 2024
c6b124c
[Discover] Fix sample size schema
jughosta Feb 1, 2024
ae17bcf
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 1, 2024
3a211b2
[Discover] Check tests
jughosta Feb 2, 2024
5b382b9
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Feb 2, 2024
031343e
[Discover] Merge
jughosta Feb 2, 2024
895a08e
[Discover] Fix checks
jughosta Feb 2, 2024
c8f837c
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 2, 2024
30f9df0
[Discover] Fix for ft
jughosta Feb 2, 2024
60e217d
[Discover] Clean up
jughosta Feb 2, 2024
1e5c502
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 5, 2024
7e9dd06
[Discover] Fix based on tests
jughosta Feb 5, 2024
825aa71
[Discover] Update mocks
jughosta Feb 5, 2024
04a3430
[Discover] Restore tests for lens attributes
jughosta Feb 5, 2024
09960ce
[Discover] Fix tests
jughosta Feb 5, 2024
189a182
[Discover] Simplify tests
jughosta Feb 5, 2024
98923df
[Discover] Restore tests for vis suggestions
jughosta Feb 5, 2024
d7be568
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 5, 2024
1fce17f
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 6, 2024
9940078
[Discover] Add new functional tests
jughosta Feb 6, 2024
a5c1281
[Discover] Update tests
jughosta Feb 6, 2024
ab9593b
[Discover] Switch to local utils
jughosta Feb 6, 2024
9bd096c
[Discover] Add more tests
jughosta Feb 7, 2024
7ff9e21
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 7, 2024
6c11f14
[Discover] Remove redundant chart title
jughosta Feb 7, 2024
f2fc2ce
[Discover] Use the shared util for lens attributes
jughosta Feb 7, 2024
b555cd5
[Discover] Update on revert
jughosta Feb 7, 2024
7f8cb6b
[Discover] Add a test
jughosta Feb 7, 2024
cf5666c
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 7, 2024
c2c15b2
[Discover] Clean up i18n
jughosta Feb 7, 2024
9e49be3
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 7, 2024
f25029a
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Feb 7, 2024
9898d6c
[Discover] Avoid circular deps
jughosta Feb 8, 2024
f1d3994
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 8, 2024
96c3f13
[Discover] Revert type changes
jughosta Feb 8, 2024
7f85d86
[Discover] Update types
jughosta Feb 8, 2024
caf273a
Merge branch 'main' into split-saved-search-plugin
jughosta Feb 8, 2024
4bd7a3d
[Discover] Rearrange consts
jughosta Feb 8, 2024
f7ec154
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 8, 2024
fbc0181
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Feb 8, 2024
a90b028
Merge remote-tracking branch 'origin/split-saved-search-plugin' into …
jughosta Feb 8, 2024
0e922c2
[Discover] Update code style
jughosta Feb 8, 2024
f8f00ce
[Discover] Add migrations for visContextJSON. Create saved search pac…
jughosta Jan 15, 2024
5010ce2
[Discover] Fix existing migration tests
jughosta Feb 8, 2024
e3e728b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 8, 2024
4dea461
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Feb 8, 2024
7b624a9
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Feb 8, 2024
055383a
[Discover] Fix types
jughosta Feb 8, 2024
5eabc7c
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3-with…
jughosta Feb 8, 2024
6e28a48
[Discover] Make lens migrations optional
jughosta Feb 9, 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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ src/plugins/saved_objects @elastic/kibana-core
packages/kbn-saved-objects-settings @elastic/appex-sharedux
src/plugins/saved_objects_tagging_oss @elastic/appex-sharedux
x-pack/plugins/saved_objects_tagging @elastic/appex-sharedux
packages/kbn-saved-search @elastic/kibana-data-discovery
src/plugins/saved_search @elastic/kibana-data-discovery
src/plugins/saved_search_so @elastic/kibana-data-discovery
examples/screenshot_mode_example @elastic/appex-sharedux
src/plugins/screenshot_mode @elastic/appex-sharedux
x-pack/examples/screenshotting_example @elastic/appex-sharedux
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ oss plugins.
|Contains the saved search saved object definition and helpers.


|{kib-repo}blob/{branch}/src/plugins/saved_search_so/README.md[savedSearchSo]
|Contains the saved search saved object definition.


|{kib-repo}blob/{branch}/src/plugins/screenshot_mode/README.md[screenshotMode]
|The service exposed by this plugin informs consumers whether they should optimize for non-interactivity. In this way plugins can avoid loading unnecessary code, data or other services.

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@
"@kbn/saved-objects-settings": "link:packages/kbn-saved-objects-settings",
"@kbn/saved-objects-tagging-oss-plugin": "link:src/plugins/saved_objects_tagging_oss",
"@kbn/saved-objects-tagging-plugin": "link:x-pack/plugins/saved_objects_tagging",
"@kbn/saved-search": "link:packages/kbn-saved-search",
"@kbn/saved-search-plugin": "link:src/plugins/saved_search",
"@kbn/saved-search-so-plugin": "link:src/plugins/saved_search_so",
"@kbn/screenshot-mode-example-plugin": "link:examples/screenshot_mode_example",
"@kbn/screenshot-mode-plugin": "link:src/plugins/screenshot_mode",
"@kbn/screenshotting-example-plugin": "link:x-pack/examples/screenshotting_example",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-saved-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/saved-search

Package for extracted saved search plugin logic
13 changes: 13 additions & 0 deletions packages/kbn-saved-search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 {
MIN_SAVED_SEARCH_SAMPLE_SIZE,
MAX_SAVED_SEARCH_SAMPLE_SIZE,
VIEW_MODE,
} from './src/constants';
13 changes: 13 additions & 0 deletions packages/kbn-saved-search/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-saved-search'],
};
5 changes: 5 additions & 0 deletions packages/kbn-saved-search/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/saved-search",
"owner": "@elastic/kibana-data-discovery"
}
7 changes: 7 additions & 0 deletions packages/kbn-saved-search/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/saved-search",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false
}
15 changes: 15 additions & 0 deletions packages/kbn-saved-search/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 const MIN_SAVED_SEARCH_SAMPLE_SIZE = 1;
export const MAX_SAVED_SEARCH_SAMPLE_SIZE = 10000;

export enum VIEW_MODE {
DOCUMENT_LEVEL = 'documents',
AGGREGATED_LEVEL = 'aggregated',
}
14 changes: 14 additions & 0 deletions packages/kbn-saved-search/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"include": ["*.ts", "src/**/*", "__mocks__/**/*.ts"],
"compilerOptions": {
"outDir": "target/types"
},
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/data-plugin",
"@kbn/utility-types",
]
}
46 changes: 46 additions & 0 deletions packages/kbn-saved-search/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { RefreshInterval, TimeRange } from '@kbn/data-plugin/common';
import type { SerializableRecord } from '@kbn/utility-types';
import { VIEW_MODE } from './src/constants';

export interface DiscoverGridSettings extends SerializableRecord {
columns?: Record<string, DiscoverGridSettingsColumn>;
}

export interface DiscoverGridSettingsColumn extends SerializableRecord {
width?: number;
}

/** @internal **/
export interface SavedSearchAttributes {
title: string;
sort: Array<[string, string]>;
columns: string[];
description: string;
grid: DiscoverGridSettings;
hideChart: boolean;
isTextBasedQuery: boolean;
usesAdHocDataView?: boolean;
kibanaSavedObjectMeta: {
searchSourceJSON: string;
};
viewMode?: VIEW_MODE;
hideAggregatedPreview?: boolean;
rowHeight?: number;

timeRestore?: boolean;
timeRange?: Pick<TimeRange, 'from' | 'to'>;
refreshInterval?: RefreshInterval;

rowsPerPage?: number;
sampleSize?: number;
breakdownField?: string;
visContextJSON?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('getLensAttributesFromSuggestion', () => {
timeFieldName: '@timestamp',
isPersisted: () => false,
toSpec: () => ({}),
toMinimalSpec: () => ({}),
} as unknown as DataView;
const query: AggregateQuery = { esql: 'from foo | limit 10' };

Expand Down
24 changes: 17 additions & 7 deletions packages/kbn-visualization-utils/src/get_lens_attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ export const getLensAttributesFromSuggestion = ({
query: Query | AggregateQuery;
suggestion: Suggestion | undefined;
dataView?: DataView;
}) => {
}): {
references: Array<{ name: string; id: string; type: string }>;
visualizationType: string;
state: {
visualization: {};
datasourceStates: Record<string, unknown>;
query: Query | AggregateQuery;
filters: Filter[];
};
title: string;
} => {
const suggestionDatasourceState = Object.assign({}, suggestion?.datasourceState);
const suggestionVisualizationState = Object.assign({}, suggestion?.visualizationState);
const datasourceStates =
Expand All @@ -35,11 +45,11 @@ export const getLensAttributesFromSuggestion = ({
};
const visualization = suggestionVisualizationState;
const attributes = {
title: suggestion
? suggestion.title
: i18n.translate('visualizationUtils.config.suggestion.title', {
defaultMessage: 'New suggestion',
}),
title:
suggestion?.title ??
i18n.translate('visualizationUtils.config.suggestion.title', {
defaultMessage: 'New suggestion',
}),
references: [
{
id: dataView?.id ?? '',
Expand All @@ -55,7 +65,7 @@ export const getLensAttributesFromSuggestion = ({
...(dataView &&
dataView.id &&
!dataView.isPersisted() && {
adHocDataViews: { [dataView.id]: dataView.toSpec(false) },
adHocDataViews: { [dataView.id]: dataView.toMinimalSpec() },
}),
},
visualizationType: suggestion ? suggestion.visualizationId : 'lnsXY',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"risk-engine-configuration": "b105d4a3c6adce40708d729d12e5ef3c8fbd9508",
"rules-settings": "892a2918ebaeba809a612b8d97cec0b07c800b5f",
"sample-data-telemetry": "37441b12f5b0159c2d6d5138a494c9f440e950b5",
"search": "2c1ab8a17e6972be2fa8d3880ba2305dfd9a5a6e",
"search": "e49d124ed4c28131c52fadf85e6470871e22b20c",
"search-session": "b2fcd840e12a45039ada50b1355faeafa39876d1",
"search-telemetry": "b568601618744720b5662946d3103e3fb75fe8ee",
"security-rule": "07abb4d7e707d91675ec0495c73816394c7b521f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
* Side Public License, v 1.
*/

import React, { useCallback, useMemo } from 'react';
import React, { useCallback } from 'react';
import { UnifiedHistogramContainer } from '@kbn/unified-histogram-plugin/public';
import { css } from '@emotion/react';
import useObservable from 'react-use/lib/useObservable';
import { Datatable } from '@kbn/expressions-plugin/common';
import { useDiscoverHistogram } from './use_discover_histogram';
import { type DiscoverMainContentProps, DiscoverMainContent } from './discover_main_content';
import { useAppStateSelector } from '../../services/discover_app_state_container';
import { FetchStatus } from '../../../types';

export interface DiscoverHistogramLayoutProps extends DiscoverMainContentProps {
container: HTMLElement | null;
Expand All @@ -35,14 +33,14 @@ export const DiscoverHistogramLayout = ({
const { dataState } = stateContainer;
const searchSessionId = useObservable(stateContainer.searchSessionManager.searchSessionId$);
const hideChart = useAppStateSelector((state) => state.hideChart);

const unifiedHistogramProps = useDiscoverHistogram({
stateContainer,
inspectorAdapters: dataState.inspectorAdapters,
hideChart,
isPlainRecord,
});

const datatable = useObservable(dataState.data$.documents$);
const renderCustomChartToggleActions = useCallback(
() =>
React.isValidElement(panelsToggle)
Expand All @@ -51,20 +49,6 @@ export const DiscoverHistogramLayout = ({
[panelsToggle]
);

const table: Datatable | undefined = useMemo(() => {
if (
isPlainRecord &&
datatable &&
[FetchStatus.PARTIAL, FetchStatus.COMPLETE].includes(datatable.fetchStatus)
) {
return {
type: 'datatable' as 'datatable',
rows: datatable.result!.map((r) => r.raw),
columns: datatable.textBasedQueryColumns || [],
};
}
}, [datatable, isPlainRecord]);

// Initialized when the first search has been requested or
// when in text-based mode since search sessions are not supported
if (!searchSessionId && !isPlainRecord) {
Expand All @@ -76,7 +60,6 @@ export const DiscoverHistogramLayout = ({
{...unifiedHistogramProps}
searchSessionId={searchSessionId}
requestAdapter={dataState.inspectorAdapters.requests}
table={table}
container={container}
css={histogramLayoutCss}
renderCustomChartToggleActions={renderCustomChartToggleActions}
Expand Down
Loading