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

[data.ui] Lazy load UI components in data plugin. #78889

Merged
merged 12 commits into from
Oct 6, 2020

Conversation

lukeelmers
Copy link
Member

@lukeelmers lukeelmers commented Sep 29, 2020

In an effort to reduce the initial bundle size of the data plugin, this updates items exported from data/public/ui to be lazy-loaded.

There's more we could investigate in the data plugin longer term, but this is the quickest/easiest target for bundle size reduction that doesn't involve breaking any service contracts or making lifecycle methods async.

Here are the before and after stats from webpack-bundle-analyzer:

Before: data/public/ui ~307k

Data Plugin
Screen Shot 2020-09-30 at 5 04 35 PM
Closeup of data/public/ui
Screen Shot 2020-09-30 at 5 05 30 PM

After: data/public/ui ~37k

Data Plugin
Screen Shot 2020-10-01 at 2 59 12 PM
Closeup of data/public/ui
Screen Shot 2020-10-01 at 2 59 39 PM

import { phraseFilter } from '../../../../stubs';

afterEach(cleanup);
Copy link
Member Author

Choose a reason for hiding this comment

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

These cleanups should no longer be needed as explained in #78742

Comment on lines -26 to -33
// @internal
export { ShardFailureOpenModalButton, ShardFailureRequest } from './shard_failure_modal';

// @internal
export { SavedQueryManagementComponent } from './saved_query_management';

// @internal
export { SaveQueryForm, SavedQueryMeta } from './saved_query_form';
Copy link
Member Author

Choose a reason for hiding this comment

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

data/public/index.ts imports from this file, so I have removed any items which are imported internally by other lazy-loaded components. This way the only items available in ui/index are types, or lazy-loaded components.

Comment on lines +112 to +113
await waitFor(() => getByText(kqlQuery.query));
await waitFor(() => getByText('KQL'));
Copy link
Member Author

Choose a reason for hiding this comment

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

waitFor already fails if the items you are querying for don't exist, so we no longer need the assertions that were here previously.

const SEARCH_BAR_ROOT = '.globalQueryBar';
const FILTER_BAR = '.filterBar';
const FILTER_BAR = '.globalFilterBar';
Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I have no clue how this test worked previously with the .filterBar class... I couldn't find it anywhere in the DOM. So I replaced it with .globalFilterBar which definitely exists 🙂

Comment on lines +29 to +35
// The data plugin's `SearchBar` is lazy loaded, so we need to ensure it is
// available before we mount our component with Enzyme.
const getWrapper = async (Component: ReturnType<typeof Proxy>) => {
const { getByTestId } = render(Component);
await waitFor(() => getByTestId('queryInput')); // check for presence of query input
return mount(Component);
};
Copy link
Member Author

Choose a reason for hiding this comment

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

React.Suspense doesn't play nice with Enzyme, but I wanted to avoid re-writing each test with @testing-library/react since I'm not familiar with this area of code. So I made this wrapper which ensures the SearchBar that's loaded with React.lazy is available before Enzyme mount is called.

You may want to consider a rewrite with @testing-library/react that doesn't rely on <SearchBar /> internals, as it should speed these tests up a bit. (Or perhaps a functional test if you really want to test the end-to-end experience).

@lukeelmers lukeelmers self-assigned this Oct 1, 2020
@lukeelmers lukeelmers added release_note:skip Skip the PR/issue when compiling release notes technical debt Improvement of the software architecture and operational architecture v7.10.0 v8.0.0 labels Oct 1, 2020
@lukeelmers lukeelmers marked this pull request as ready for review October 2, 2020 03:38
@lukeelmers lukeelmers requested a review from a team as a code owner October 2, 2020 03:38
@lukeelmers lukeelmers requested a review from a team October 2, 2020 03:38
@lukeelmers lukeelmers requested review from a team as code owners October 2, 2020 03:38
@elasticmachine
Copy link
Contributor

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

@lukeelmers
Copy link
Member Author

After several attempts, I've been unable to reproduce these failures locally, however they are failing consistently so I'll keep investigating.

[00:07:24]                 └- ✖ fail: maps app  blended vector layer should request documents when zoomed to smaller regions showing less data
[00:07:24]                 │      Error: expected '34' to equal '33'
[00:07:24]                 │       at Assertion.assert (/dev/shm/workspace/parallel/24/kibana/packages/kbn-expect/expect.js:100:11)
[00:07:24]                 │       at Assertion.equal (/dev/shm/workspace/parallel/24/kibana/packages/kbn-expect/expect.js:227:8)
[00:07:24]                 │       at Context.it (test/functional/apps/maps/blended_vector_layer.js:30:23)

Copy link
Contributor

@mattkime mattkime left a comment

Choose a reason for hiding this comment

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

Changes look good and work well locally. Nice work!

Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Code only review - but Kibana App changes LGTM

@lukeelmers
Copy link
Member Author

I haven't had any luck getting to the bottom of this failed maps functional test, so I've pinged @elastic/kibana-gis for input:

[00:07:24]                 └- ✖ fail: maps app  blended vector layer should request documents when zoomed to smaller regions showing less data
[00:07:24]                 │      Error: expected '34' to equal '33'

Since this test doesn't appear to have been failing on other branches lately, I'm trying to figure out what I changed that might have affected this test. The two components which are now lazy loaded that I could find usage of in the maps app are SearchBar and IndexPatternSelect.

One hypothesis I had was that perhaps the SearchBar was loading more slowly in CI, causing the map to temporarily render at a larger size and thus include a wider area in the query, resulting in the one additional hit that comes back (34 instead of 33).

I did a few things to try to reproduce the failure locally:

  • Tried throttling network speed.
  • Tried manually delaying rendering of the SearchBar and IndexPatternSelect.
  • Tried removing the SearchBar completely to see if it changed the results.
  • Looked at the PageObjects.maps methods to see if there were any obvious places that race conditions might occur.

In all cases I was still unable to reproduce the failure 🙁

The screenshot from the test artifacts doesn't show any obvious rendering problems either:

maps app  blended vector layer should request documents when zoomed to smaller regions showing less data

At this point I've adjusted the height of the SearchBar fallback component to see if it helps (so that the UI doesn't "jump" as that component loads).

But if this next run still fails, I might need some more expertise from @elastic/kibana-gis.

Comment on lines +30 to +31
// Allow a range of hits to account for variances in browser window size.
expect(parseInt(hits)).to.be.within(30, 40);
Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed with @nreese, and he agreed that in this case it would be fine to make this assertion a range of values to account for small variances in screen size.

@lukeelmers lukeelmers requested a review from a team as a code owner October 6, 2020 02:51
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id before after diff
data 569 570 +1

async chunks size

id before after diff
data 0.0B 273.8KB ⚠️ +273.8KB

distributable file count

id before after diff
default 48278 48308 +30
oss 29048 29078 +30

page load bundle size

id before after diff
data 1.3MB 1.1MB -248.8KB

History

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

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

maps changes LGTM
code review

@lukeelmers lukeelmers merged commit 8ec5ce6 into elastic:master Oct 6, 2020
@lukeelmers lukeelmers deleted the test/data-bundle branch October 6, 2020 13:24
lukeelmers added a commit to lukeelmers/kibana that referenced this pull request Oct 6, 2020
gmmorris added a commit that referenced this pull request Oct 8, 2020
…into feature/task_manager_429

* 'feature/task_manager_429' of github.com:elastic/kibana: (158 commits)
  Add license check to direct package upload handler. (#79653)
  [Ingest Manager] Rename API /api/ingest_manager => /api/fleet (#79193)
  [Security Solution][Resolver] Simplify CopyableField styling and add comments (#79594)
  Fine-tunes ML related text on Metrics UI (#79425)
  [ML] DF Analytics creation wizard: ensure job creation possible when model memory lower than estimate (#79229)
  Add new "Add Data" tutorials (#77237)
  Update APM telemetry docs (#79583)
  Revert "Add support for runtime field types to mappings editor. (#77420)" (#79611)
  Kibana request headers (#79218)
  ensure missing indexPattern error is bubbled up to error callout (#79378)
  Missing space fix (#79585)
  remove duplicate tab states (#79501)
  [data.ui] Lazy load UI components in data plugin. (#78889)
  Add generic type params to search dependency. (#79608)
  [Ingest Manager] Internal action for policy reassign (#78493)
  [ILM] Add index_codec to forcemerge action in hot and warm phases (#78175)
  [Ingest Manager] Update open API spec and add condition to agent upgrade endpoint (#79579)
  [ML] Hide Data Grid column options when histogram charts are enabled. (#79459)
  [Telemetry] Synchronous `setup` and `start` methods (#79457)
  [Observability] Persist time range across apps (#79258)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review technical debt Improvement of the software architecture and operational architecture v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants