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] Migrate async import of embeddable factory to embeddable class #70920

Conversation

kertal
Copy link
Member

@kertal kertal commented Jul 7, 2020

Summary

Prevent a potential race condition when registering the Embeddable by migrating the import of the factory class from async to sync, while importing the Embeddable itself to async import so it's done on demand.
Fixes #70470

Testing

You can reproduce the race condition by adding a delay in the registerEmbeddable function of the Discover plugin


    function delay() {
      return new Promise((resolve) => {
        setTimeout(resolve, 5000);
      });
    }
    await delay();
    const { SearchEmbeddableFactory } = await import('./application/embeddable');

This will lead to the following screen on a dashboard containing a saved search

Bildschirmfoto 2020-07-09 um 07 44 54

Since the new implementation isn't importing async, this can't happen

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@kertal kertal added Feature:Discover Discover Application release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 v7.9.0 v7.8.2 labels Jul 7, 2020
@kertal kertal self-assigned this Jul 7, 2020
@kertal
Copy link
Member Author

kertal commented Jul 7, 2020

@elasticmachine merge upstream

@kertal kertal marked this pull request as ready for review July 9, 2020 05:49
@kertal kertal requested a review from a team July 9, 2020 05:49
@elasticmachine
Copy link
Contributor

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

@kertal
Copy link
Member Author

kertal commented Jul 13, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💛 Build succeeded, but was flaky


Test Failures

Kibana Pipeline / kibana-xpack-agent / Kibana Embedded in iframe with X-Pack Security.x-pack/test/functional_embedded/tests/iframe_embedded·ts.Kibana embedded in iframe should open Kibana for logged-in user

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has failed 5 times on tracked branches: https://github.com/elastic/kibana/issues/70928

[00:00:00]       │
[00:00:00]         └-: Kibana embedded
[00:00:00]           └-> "before all" hook
[00:00:00]           └-: in iframe
[00:00:00]             └-> "before all" hook
[00:00:00]             └-> should open Kibana for logged-in user
[00:00:00]               └-> "before each" hook: global before each
[00:00:00]               │ debg TestSubjects.exists(headerGlobalNav)
[00:00:00]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="headerGlobalNav"]') with timeout=2500
[00:00:02]               │ debg --- retry.tryForTime error: [data-test-subj="headerGlobalNav"] is not displayed
[00:00:03]               │ debg navigating to login url: https://localhost:6131/login
[00:00:03]               │ debg navigate to: https://localhost:6131/login
[00:00:03]               │ debg browser[INFO] https://localhost:6131/login?_t=1594632920238 341 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-P5polb1UreUSOe5V/Pv7tc+yeZuJXiOi/3fqhGsU7BE='), or a nonce ('nonce-...') is required to enable inline execution.
[00:00:03]               │
[00:00:03]               │ debg browser[INFO] https://localhost:6131/bundles/app/core/bootstrap.js 42:19 "^ A single error about an inline script not firing due to content security policy is expected!"
[00:00:03]               │ debg ... sleep(700) start
[00:00:04]               │ debg ... sleep(700) end
[00:00:04]               │ debg returned from get, calling refresh
[00:00:04]               │ debg browser[INFO] https://localhost:6131/login?_t=1594632920238 341 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-P5polb1UreUSOe5V/Pv7tc+yeZuJXiOi/3fqhGsU7BE='), or a nonce ('nonce-...') is required to enable inline execution.
[00:00:04]               │
[00:00:04]               │ debg browser[INFO] https://localhost:6131/bundles/app/core/bootstrap.js 42:19 "^ A single error about an inline script not firing due to content security policy is expected!"
[00:00:04]               │ debg currentUrl = https://localhost:6131/login
[00:00:04]               │          appUrl = https://localhost:6131/login
[00:00:04]               │ debg TestSubjects.find(kibanaChrome)
[00:00:04]               │ debg Find.findByCssSelector('[data-test-subj="kibanaChrome"]') with timeout=60000
[00:00:07]               │ debg browser[INFO] https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js 452:106112 "INFO: 2020-07-13T09:35:23Z
[00:00:07]               │        Adding connection to https://localhost:6131/elasticsearch
[00:00:07]               │
[00:00:07]               │      "
[00:00:07]               │ debg ... sleep(501) start
[00:00:08]               │ debg ... sleep(501) end
[00:00:08]               │ debg in navigateTo url = https://localhost:6131/login
[00:00:08]               │ debg TestSubjects.exists(statusPageContainer)
[00:00:08]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="statusPageContainer"]') with timeout=2500
[00:00:10]               │ debg --- retry.tryForTime error: [data-test-subj="statusPageContainer"] is not displayed
[00:00:11]               │ debg Waiting for Login Form to appear.
[00:00:11]               │ debg Waiting up to 100000ms for login form...
[00:00:11]               │ debg TestSubjects.exists(loginForm)
[00:00:11]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="loginForm"]') with timeout=2500
[00:00:11]               │ debg TestSubjects.setValue(loginUsername, elastic)
[00:00:11]               │ debg TestSubjects.click(loginUsername)
[00:00:11]               │ debg Find.clickByCssSelector('[data-test-subj="loginUsername"]') with timeout=10000
[00:00:11]               │ debg Find.findByCssSelector('[data-test-subj="loginUsername"]') with timeout=10000
[00:00:11]               │ debg TestSubjects.setValue(loginPassword, changeme)
[00:00:11]               │ debg TestSubjects.click(loginPassword)
[00:00:11]               │ debg Find.clickByCssSelector('[data-test-subj="loginPassword"]') with timeout=10000
[00:00:11]               │ debg Find.findByCssSelector('[data-test-subj="loginPassword"]') with timeout=10000
[00:00:11]               │ debg TestSubjects.click(loginSubmit)
[00:00:11]               │ debg Find.clickByCssSelector('[data-test-subj="loginSubmit"]') with timeout=10000
[00:00:11]               │ debg Find.findByCssSelector('[data-test-subj="loginSubmit"]') with timeout=10000
[00:00:11]               │ debg Waiting for login result, expected: undefined.
[00:00:11]               │ debg Waiting up to 20000ms for logout button visible...
[00:00:11]               │ debg TestSubjects.exists(userMenuButton)
[00:00:11]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="userMenuButton"]') with timeout=2500
[00:00:14]               │ debg browser[INFO] https://localhost:6131/app/home 341 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-P5polb1UreUSOe5V/Pv7tc+yeZuJXiOi/3fqhGsU7BE='), or a nonce ('nonce-...') is required to enable inline execution.
[00:00:14]               │
[00:00:14]               │ debg browser[INFO] https://localhost:6131/bundles/app/core/bootstrap.js 42:19 "^ A single error about an inline script not firing due to content security policy is expected!"
[00:00:14]               │ debg browser[INFO] https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js 452:106112 "INFO: 2020-07-13T09:35:30Z
[00:00:14]               │        Adding connection to https://localhost:6131/elasticsearch
[00:00:14]               │
[00:00:14]               │      "
[00:00:14]               │ debg --- retry.tryForTime error: [data-test-subj="userMenuButton"] is not displayed
[00:00:15]               │ proc [kibana]  error  [09:35:32.348] [error][client][connection] Error: 140616173352768:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
[00:00:15]               │ proc [kibana] 
[00:00:15]               │ debg TestSubjects.exists(userMenuButton)
[00:00:15]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="userMenuButton"]') with timeout=2500
[00:00:15]               │ERROR browser[SEVERE] http://localhost:6131/api/_newsfeed-FTS-external-service-simulators/kibana/v8.0.0-SNAPSHOT.json - Failed to load resource: net::ERR_EMPTY_RESPONSE
[00:00:15]               │ERROR browser[SEVERE] https://localhost:6131/34547/bundles/plugin/newsfeed/newsfeed.plugin.js 0:19107 TypeError: Failed to fetch
[00:00:15]               │          at Fetch._callee3$ (https://localhost:6131/34547/bundles/core/core.entry.js:34:105174)
[00:00:15]               │          at l (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:155138)
[00:00:15]               │          at Generator._invoke (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:154891)
[00:00:15]               │          at Generator.forEach.e.<computed> [as throw] (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:155495)
[00:00:15]               │          at fetch_asyncGeneratorStep (https://localhost:6131/34547/bundles/core/core.entry.js:34:99267)
[00:00:15]               │          at _throw (https://localhost:6131/34547/bundles/core/core.entry.js:34:99675)
[00:00:15]               │ debg TestSubjects.exists(userMenu)
[00:00:15]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="userMenu"]') with timeout=2500
[00:00:18]               │ debg --- retry.tryForTime error: [data-test-subj="userMenu"] is not displayed
[00:00:18]               │ debg TestSubjects.click(userMenuButton)
[00:00:18]               │ debg Find.clickByCssSelector('[data-test-subj="userMenuButton"]') with timeout=10000
[00:00:18]               │ debg Find.findByCssSelector('[data-test-subj="userMenuButton"]') with timeout=10000
[00:00:18]               │ debg Waiting up to 20000ms for user menu opened...
[00:00:18]               │ debg TestSubjects.exists(userMenu)
[00:00:18]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="userMenu"]') with timeout=2500
[00:00:18]               │ debg TestSubjects.exists(userMenu > logoutLink)
[00:00:18]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="userMenu"] [data-test-subj="logoutLink"]') with timeout=2500
[00:00:19]               │ debg TestSubjects.find(iframe_embedded)
[00:00:19]               │ debg Find.findByCssSelector('[data-test-subj="iframe_embedded"]') with timeout=10000
[00:00:19]               │ debg browser[INFO] https://localhost:6131/app/home 341 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-P5polb1UreUSOe5V/Pv7tc+yeZuJXiOi/3fqhGsU7BE='), or a nonce ('nonce-...') is required to enable inline execution.
[00:00:19]               │
[00:00:19]               │ debg browser[INFO] https://localhost:6131/bundles/app/core/bootstrap.js 42:19 "^ A single error about an inline script not firing due to content security policy is expected!"
[00:00:19]               │ debg TestSubjects.exists(headerGlobalNav)
[00:00:19]               │ debg Find.existsByDisplayedByCssSelector('[data-test-subj="headerGlobalNav"]') with timeout=2500
[00:00:22]               │ debg browser[INFO] https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js 452:106112 "INFO: 2020-07-13T09:35:38Z
[00:00:22]               │        Adding connection to https://localhost:6131/elasticsearch
[00:00:22]               │
[00:00:22]               │      "
[00:00:22]               │ debg --- retry.tryForTime error: [data-test-subj="headerGlobalNav"] is not displayed
[00:00:22]               │ proc [kibana]  error  [09:35:39.443] [error][client][connection] Error: 140616173352768:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
[00:00:22]               │ proc [kibana] 
[00:00:22]               │ERROR browser[SEVERE] http://localhost:6131/api/_newsfeed-FTS-external-service-simulators/kibana/v8.0.0-SNAPSHOT.json - Failed to load resource: net::ERR_EMPTY_RESPONSE
[00:00:22]               │ERROR browser[SEVERE] https://localhost:6131/34547/bundles/plugin/newsfeed/newsfeed.plugin.js 0:19107 TypeError: Failed to fetch
[00:00:22]               │          at Fetch._callee3$ (https://localhost:6131/34547/bundles/core/core.entry.js:34:105174)
[00:00:22]               │          at l (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:155138)
[00:00:22]               │          at Generator._invoke (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:154891)
[00:00:22]               │          at Generator.forEach.e.<computed> [as throw] (https://localhost:6131/34547/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:368:155495)
[00:00:22]               │          at fetch_asyncGeneratorStep (https://localhost:6131/34547/bundles/core/core.entry.js:34:99267)
[00:00:22]               │          at _throw (https://localhost:6131/34547/bundles/core/core.entry.js:34:99675)
[00:00:22]               │ info Taking screenshot "/dev/shm/workspace/kibana/x-pack/test/functional_embedded/screenshots/failure/Kibana embedded in iframe should open Kibana for logged-in user.png"
[00:00:22]               │ info Current URL is: https://localhost:6131/iframe_embedded
[00:00:22]               │ info Saving page source to: /dev/shm/workspace/kibana/x-pack/test/functional_embedded/failure_debug/html/Kibana embedded in iframe should open Kibana for logged-in user.html
[00:00:22]               └- ✖ fail: Kibana embedded in iframe should open Kibana for logged-in user
[00:00:22]               │      Error: expected true to equal false
[00:00:22]               │       at Assertion.assert (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:100:11)
[00:00:22]               │       at Assertion.be.Assertion.equal (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:227:8)
[00:00:22]               │       at Assertion.be (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:69:22)
[00:00:22]               │       at Context.it (test/functional_embedded/tests/iframe_embedded.ts:39:33)
[00:00:22]               │ 
[00:00:22]               │ 

Stack Trace

Error: expected true to equal false
    at Assertion.assert (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:100:11)
    at Assertion.be.Assertion.equal (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:227:8)
    at Assertion.be (/dev/shm/workspace/kibana/packages/kbn-expect/expect.js:69:22)
    at Context.it (test/functional_embedded/tests/iframe_embedded.ts:39:33)

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
discover 112 -1 113

History

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

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in FF and works as expected even with delay in front of the new dynamic import. LGTM

@kertal kertal merged commit 84edc36 into elastic:master Jul 13, 2020
kertal added a commit to kertal/kibana that referenced this pull request Jul 13, 2020
kertal added a commit to kertal/kibana that referenced this pull request Jul 13, 2020
…dable (elastic#70920)

# Conflicts:
#	src/plugins/discover/public/application/embeddable/index.ts
#	src/plugins/discover/public/application/embeddable/search_embeddable.ts
#	src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts
#	src/plugins/discover/public/application/embeddable/types.ts
#	src/plugins/discover/public/plugin.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 13, 2020
* master: (28 commits)
  skip flaky suite (elastic#71361)
  [Ingest Manager] Add UI to enroll standalone agent (elastic#71288)
  Node options from cfg file for production (elastic#62468)
  [APM] Improvements to the ML Settings page (elastic#71309)
  add old .chromium to gitignore to prevent it from being accidentally committed
  [Ingest Manager] Simplify add/edit package config (integration) form (elastic#71187)
  Ensure Other bucket works on scripted fields. (elastic#71329)
  [APM] Anomaly detection setup link with alert if job doesn't exist (elastic#71229)
  [APM] Anomaly detection integration with transaction duration chart (elastic#71230)
  inclusive language (elastic#71438)
  [Ingest Manager] During fleet setup create an enrollment for every config (elastic#71308)
  Improvements to our developer guide (elastic#67764)
  [SIEM][Detections] Fixes index patterns order (elastic#71270)
  [Metrics + Logs UI] Add test for logs and metrics telemetry (elastic#70858)
  [Maps] Inclusive language (elastic#71427)
  [Logs UI] Unskip log highlight api integration test (elastic#71058)
  [Security_Solution][Resolver] Style adjustments per UX (elastic#71179)
  [Functional test] Increase the timeout to click new vis function (elastic#71226)
  [Discover] Migrate async import of embeddable factory to actual embeddable (elastic#70920)
  fix overflow (elastic#70723)
  ...
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:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.8.2 v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discover Code loading race condition with embeddables
4 participants