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

Keep volatile information out of stored search source #91517

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Feb 16, 2021

Fixes #91459

Separates the search source in discover into two separate sources - the persistent search source tied to the saved object containing stuff which should be saved (filters, query) and the volatile search source which is a child of the persistent one containing all other things (size, highlight, sorting, fields, ...)

CSV export gets passed the volatile search source so it's operating on the very same state (minus some specific cleanup)

There is one weird thing but I guess we can open a separate issue for this - when creating a reporting job from discover, index pattern runtime fields work correctly, because the runtime_mapping part of the dsl object becomes part of the job params. On dashboards, this part of the dsl object is not used (

const state = _.pick(searchRequestBody, ['sort', 'docvalue_fields', 'query']);
), that's why index pattern runtime fields won't show up in the resulting csv.

The saved search embeddable is still polluting the original search source, but it doesn't matter here because it's never saved.

@flash1293 flash1293 added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0 labels Feb 16, 2021
@flash1293 flash1293 marked this pull request as ready for review February 17, 2021 08:24
@flash1293 flash1293 requested a review from a team February 17, 2021 08:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@@ -169,10 +169,10 @@ function discoverController($route, $scope, Promise) {
let inspectorRequest;
let isChangingIndexPattern = false;
const savedSearch = $route.current.locals.savedObjects.savedSearch;
$scope.searchSource = savedSearch.searchSource;
$scope.persistentSearchSource = savedSearch.searchSource;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me this is not used anywhere outside the current scope? Could we already not store that on $scope and make it a local variable instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed

@@ -16,7 +16,8 @@ import { DiscoverServices } from '../../build_services';
* Helper function to update the given searchSource before fetching/sharing/persisting
*/
export function updateSearchSource(
searchSource: ISearchSource,
persistentSearchSource: ISearchSource,
volatileSearchSource: ISearchSource | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

🎨 Would also allow us not to need to pass undefined explicitly to this method above.

Suggested change
volatileSearchSource: ISearchSource | undefined,
volatileSearchSource?: ISearchSource,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not possible because the third argument is mandatory. I refactored it to just take a single object with all parameters instead.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
discover 426.4KB 426.8KB +443.0B

History

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


// searchSource which applies time range
const timeRangeSearchSource = savedSearch.searchSource.create();
const volatileSearchSource = savedSearch.searchSource.create();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these changes be applied to embeddable as well?

const timeRangeSearchSource = searchSource.create();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the description:

The saved search embeddable is still polluting the original search source, but it doesn't matter here because it's never saved.

We can structure it the same way there, but it's not related to the issue of polluted saved objects because the embeddable search source is never saved. To keep the scope small I would like to do these things in 7.13

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, missed this line in the description

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Changes seem reasonable. I had a quick pass at:

  1. loading a previously saved search
  2. saving a saved search and loading it back

Both with fields API and _source. It works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] Fix search source behavior
5 participants