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

[Textbased languages] Render Lens suggestions in Discover #151581

Merged
merged 61 commits into from
Mar 27, 2023

Conversation

stratoula
Copy link
Contributor

@stratoula stratoula commented Feb 20, 2023

Summary

Part of #147472

This PR adds the unified histogram on the text based mode in Discover and depicts Lens suggestions to the users. The users can navigate from it to Lens for further exploration and adding the viz into a dashboard.

discover

Some notes:

  • Lens now exposes a new api to fetch the suggestions from a text based query. Later it can also be used to return suggestions for the dataview mode (the other part of the aforementioned issue)
  • Lens visualizations have been updated to return the correct previewIcon (the majority of them were using the empty icon and not the icon that represents them). This icon appears on the visualization selection dropdown
  • When Lens suggests a table, then the chart is not displayed (Discover already offers a table view)
  • The legacy metric is excluded from the suggestions as it is not compatible with the text based languages.
  • The text based languages are treated a bit differently on the unified histogram as they do not work with search sessions.
  • This feature is on technical preview, so we can iterate more on that on later esql milestones. This is the first iteration required for the milestone 1.
  • The ESQL search strategy has a default size of 1000 https://github.com/elastic/kibana/blob/main/src/plugins/data/common/search/expressions/essql.ts#L113 which means that this is the max rows that we retrieve. I am keeping the default as is irrelevant from the PR. In ESQL this limitation doesn't exist so I think we are fine.

Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1972

Checklist

@stratoula stratoula changed the title Export lens suggestions [Textbased languages] Render Lens suggestions in Discover Feb 21, 2023
return (
query &&
isOfAggregateQueryType(query) &&
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I am adding this additional check as this will be needed for esql

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at least it will make it easier to add a new one :D

Suggested change
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
(['sql', 'esql'].some( mode === getAggregateQueryMode(query)))

@@ -120,7 +120,7 @@ export function suggestions({
const newShape = getNewShape(groups, subVisualizationId as PieVisualizationState['shape']);
const baseSuggestion: VisualizationSuggestion<PieVisualizationState> = {
title: i18n.translate('xpack.lens.pie.suggestionLabel', {
defaultMessage: 'As {chartName}',
Copy link
Contributor Author

@stratoula stratoula Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Some charts were using the As ... format and other just the visualization name. I decided to keep the latter for consistency (the title is depicted on the suggestions dropdown)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a code review on the Lens side: proposed some changes to align the new API with the existing Lens API.

x-pack/plugins/lens/public/lens_suggestions_api.ts Outdated Show resolved Hide resolved
x-pack/plugins/lens/public/lens_suggestions_api.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me work with you on getting this over the finish line, and as promised my stamp of approval ✅! LGTM, and I'm excited to get this into main -- a great step forward to a DiscoLens future 🪩

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've found a bug on the unified search introduced with this PR while testing it with Safari:

unified_search_bug

The feature is super cool @stratoula ! 🎉

On a side note it is not obvious discovering this awesome DiscoLens 🪩 as there's nothing that hints the user the presence of a visualization in SQL mode. Perhaps a basic histogram can be visualized for the simple SELECT * FROM <dataView> query?

On the code review side I've left mostly minor improvements and nitpicks. The only change I would recommend is to rename the stateHelperApi.suggestionsApi into stateHelperApi.suggestions to be in style sync with the other 2 apis.

return (
query &&
isOfAggregateQueryType(query) &&
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at least it will make it easier to add a new one :D

Suggested change
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
(['sql', 'esql'].some( mode === getAggregateQueryMode(query)))

x-pack/plugins/lens/public/plugin.ts Outdated Show resolved Hide resolved
@stratoula
Copy link
Contributor Author

On a side note it is not obvious discovering this awesome DiscoLens 🪩 as there's nothing that hints the user the presence of a visualization in SQL mode. Perhaps a basic histogram can be visualized for the simple SELECT * FROM query?

@dej611 thanx for the nits. We discussed it with the ESQL WG and we decided against it

@kibana-ci
Copy link
Collaborator

kibana-ci commented Mar 27, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #6 / Discover component selected data view with time field displays chart toggle
  • [job] [logs] Jest Tests #6 / Discover histogram layout component render should not render null if there is a search session
  • [job] [logs] Jest Tests #6 / Discover histogram layout component render should not render null if there is no search session, but isPlainRecord is true
  • [job] [logs] Jest Tests #6 / Discover histogram layout component reset search button renders the button when there is a saved search
  • [job] [logs] Jest Tests #6 / Discover histogram layout component reset search button should call resetSavedSearch when clicked

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 446 447 +1
lens 891 892 +1
unifiedHistogram 57 59 +2
total +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
lens 592 608 +16
unifiedHistogram 23 24 +1
total +17

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 397.4KB 398.5KB +1.1KB
lens 1.3MB 1.3MB +1.1KB
unifiedHistogram 38.3KB 43.7KB +5.4KB
total +7.5KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 49 48 -1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 34.0KB 34.3KB +215.0B
unifiedHistogram 5.7KB 5.9KB +141.0B
total +356.0B
Unknown metric groups

API count

id before after diff
lens 686 702 +16
unifiedHistogram 61 64 +3
total +19

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 446 447 +1
lens 891 892 +1
unifiedHistogram 57 59 +2
total +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
lens 592 608 +16
unifiedHistogram 23 24 +1
total +17

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 397.4KB 398.5KB +1.1KB
lens 1.3MB 1.3MB +1.1KB
unifiedHistogram 38.3KB 43.7KB +5.4KB
total +7.5KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 49 48 -1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 34.0KB 34.3KB +215.0B
unifiedHistogram 5.7KB 5.9KB +141.0B
total +356.0B
Unknown metric groups

API count

id before after diff
lens 686 702 +16
unifiedHistogram 61 64 +3
total +19

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stratoula stratoula merged commit dec52ef into elastic:main Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Discover Discover Application Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants