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

Limit fetching index patterns #56603

Merged
merged 5 commits into from
Feb 5, 2020

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Feb 3, 2020

Summary

Should address #56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@Dosant Dosant changed the title [wip] Optimize pre-fetching index patterns Optimize loading all index patterns Feb 3, 2020
@Dosant Dosant changed the title Optimize loading all index patterns Limit fetching index patterns Feb 3, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@Dosant Dosant added the Feature:Index Management Index and index templates UI label Feb 3, 2020
@Dosant Dosant marked this pull request as ready for review February 3, 2020 13:59
@Dosant Dosant requested a review from a team as a code owner February 3, 2020 13:59
@tylersmalley
Copy link
Contributor

ack, reviewing this evening.

@tylersmalley
Copy link
Contributor

Thanks for jumping on this so quickly! At first I was excited by the limited scope required for this fix, but the more I dug into it the more I believe the change required to be a bit more involved. Looking at the get method alone in the IndexPatterns class, it's referenced in a dozen or so places. This method returns directly from the cache the object, which defined by the type, has multiple non-optional fields.

src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts 
  129, 3:   get = async (id: string): Promise<IndexPattern> => { 
  123, 25:    return await this.get(defaultIndexPatternId); 
src/plugins/data/public/actions/apply_filter_action.ts 
  71, 39: return getIndexPatterns().get(filter.meta.index!); 
src/legacy/ui/public/saved_objects/helpers/hydrate_index_pattern.ts 
  52, 40:  await indexPatterns.get(index); 
src/legacy/core_plugins/visualizations/public/np_ready/public/expressions/visualization_function.ts 
  93, 64: await getIndexPatterns().get(args.index) : null; 
src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts 
  71, 32: return await indexPatterns.get(indexPatternSavedObject.id); 
src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/use_es_doc_search.ts 
  67, 60: await indexPatternService.get(indexPatternId); 
src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/context.ts 
  73, 46:  await indexPatterns.get(indexPatternId); 
src/legacy/core_plugins/input_control_vis/public/control/range_control_factory.ts 
  136, 60: dataPluginStart.indexPatterns.get(controlParams.indexPattern); 
src/legacy/core_plugins/input_control_vis/public/control/list_control_factory.ts 
  209, 60: dataPluginStart.indexPatterns.get(controlParams.indexPattern); 
src/legacy/core_plugins/input_control_vis/public/components/editor/controls_tab.tsx 
  70, 47: startDeps.data.indexPatterns.get(indexPatternId); 
src/legacy/core_plugins/data/public/search/expressions/esaggs.ts 
  263, 46:  await indexPatterns.get(args.index); 

There might be something I am missing here, as I am unable to find a broken path and there do not appear to be any functional tests effected.

@Dosant
Copy link
Contributor Author

Dosant commented Feb 5, 2020

@tylersmalley,

As I understood it, there are 2 different types of cache.

  1. is simple savedObjectCache which I was fixing. It is used in couple places for pulling an info about all index patterns. And as I understood, only id and title are used. This cache is prefetched. This one is used in methods like getTitles, getIds and getFields (which is only used in one place for both id and title).

  2. Then there is an indexPattern cache, which caches complete IndexPattern objects. This cache is populated lazily. This one is used in methods like get

@Dosant Dosant requested a review from alexwizp February 5, 2020 10:48
@Dosant
Copy link
Contributor Author

Dosant commented Feb 5, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

Copy link
Contributor

@alexwizp alexwizp left a comment

Choose a reason for hiding this comment

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

Looking like these changes should help, two minor nit's

@tylersmalley
Copy link
Contributor

@Dosant, multiple index pattern cache types for the same class, that's wild - knew I was missing something, thanks for the explanation.

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

This looks good to me. Tested Chrome OSX and nothing seems broken from what I can tell.

@Dosant is correct; There are two types of caches and the one that was touched here has very limited use (mainly for the index pattern select dropdown in discover AFAIK).

expect(savedObjectsClient.find).toHaveBeenCalledTimes(1);
});

test('can refresh the saved objects caches', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding these 🙏

@Dosant Dosant merged commit dcaee36 into elastic:master Feb 5, 2020
@Dosant Dosant deleted the dev/optimize-fetching-index-patterns branch February 5, 2020 19:21
@Dosant Dosant added the v7.6.1 label Feb 5, 2020
Dosant added a commit to Dosant/kibana that referenced this pull request Feb 5, 2020
Should address elastic#56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title
Dosant added a commit to Dosant/kibana that referenced this pull request Feb 5, 2020
Should address elastic#56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title
tylersmalley pushed a commit that referenced this pull request Feb 5, 2020
Should address #56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
tylersmalley pushed a commit that referenced this pull request Feb 5, 2020
Should address #56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
tylersmalley pushed a commit that referenced this pull request Feb 6, 2020
@LeeDr LeeDr added v7.6.0 and removed v7.6.1 labels Feb 6, 2020
majagrubic pushed a commit to majagrubic/kibana that referenced this pull request Feb 10, 2020
Should address elastic#56352.

I did a look up and it seems like only id and title a really used in case that savedObjectsCache is used. So I simply limited that request to fetch only title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants