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

[Logs UI] Remove apollo deps from log link-to routes #74502

Merged
merged 11 commits into from
Aug 14, 2020

Conversation

weltenwort
Copy link
Member

@weltenwort weltenwort commented Aug 6, 2020

Summary

This replaces the use of the old graphql-based useSource hook with the new plain JSON useLogSource hook.

It also fixes two more problems:

closes #74496
closes #74916

Implementation notes

This implements option 1 from #74496, because it is backwards-compatible and minimally invasive.

@weltenwort weltenwort added v8.0.0 Feature:Logs UI Logs UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Aug 6, 2020
@weltenwort weltenwort self-assigned this Aug 6, 2020
@weltenwort
Copy link
Member Author

@elasticmachine merge upstream

@weltenwort weltenwort marked this pull request as ready for review August 11, 2020 17:44
@weltenwort weltenwort requested a review from a team as a code owner August 11, 2020 17:44
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@afgomez afgomez self-requested a review August 13, 2020 06:36
@@ -45,6 +47,10 @@ export const useLogSource = ({
return await callFetchLogSourceConfigurationAPI(sourceId, fetch);
},
onResolve: ({ data }) => {
if (!getIsMounted()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this fixes the race condition you mentioned in the description.

Could you help me understand what was the problem? I see that useMountedState is a wrapper around useEffect. I looked for usages of these promise creators and I couldn't find uses that weren't wrapped in useEffect already.

I worry that this might introduce a "gotcha" if consumers of this API need to call the promises before their component is mounted (i.e. in useLayoutEffect). If I understand this correctly, calling the promise will do nothing.

Copy link
Member Author

Choose a reason for hiding this comment

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

useMountedState returns a predicate that indicates whether the component is mounted. This becomes important when the component unmounts while the promise is pending. Then, when the promise is resolved, the subsequent setState will cause an exception. Therefore all asynchronously called setStates should be guarded by such a check. I'm still trying to catch up with all the occurrences of that mistake in this plugin, so this is a small step.

Copy link
Member Author

@weltenwort weltenwort Aug 14, 2020

Choose a reason for hiding this comment

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

I worry that this might introduce a "gotcha" if consumers of this API need to call the promises before their component is mounted (i.e. in useLayoutEffect). If I understand this correctly, calling the promise will do nothing.

As described above, the promise itself is not the problem. It resolving and thereby causing a setState call before mounting or after unmounting is.

Copy link
Contributor

@afgomez afgomez left a comment

Choose a reason for hiding this comment

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

Tried different links and they seem to work 🎉

@weltenwort
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
infra 1087 +30 1057

async chunks size

id value diff baseline
infra 3.5MB +38.1KB 3.5MB

page load bundle size

id value diff baseline
infra 275.5KB +61.0B 275.5KB

History

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

@weltenwort weltenwort merged commit 0f11282 into elastic:master Aug 14, 2020
@weltenwort weltenwort deleted the logs-ui-remove-apollo-deps branch August 14, 2020 17:50
weltenwort added a commit to weltenwort/kibana that referenced this pull request Aug 14, 2020
This replaces the use of the old graphql-based `useSource` hook with the new plain JSON `useLogSource` hook.

It also fixes two more problems:

- A rendering problem with the source configuration loading screen and a `setState` race condition in the `useLogSource` hook.
- A non-backwards-compatible change of the `/link-to/:sourceId/logs` route in elastic#61162.
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 17, 2020
* master: (24 commits)
  [ML] Functional tests - skip regression and classification tests
  [Ingest Manager] fix removing ingest pipelines from elasticsearch (elastic#75092)
  move tests for placeholder indices to setup (elastic#75096)
  [jest] temporarily extend default test timeout (elastic#75118)
  [cli] remove reference to removed --optimize flag (elastic#75083)
  skip flaky suite (elastic#75044)
  Adding /etc/rc.d/init.d/functions to the init script when present to … (elastic#22985)
  [jenkins] add pipeline for hourly security solution cypress tests (elastic#75087)
  [Reporting/Flaky Test] Skip test for paging list of reports (elastic#75075)
  remove .kbn-optimizer-cache upload (elastic#75086)
  skip flaky suite (elastic#74814)
  Actions add proxy support (elastic#74289)
  [ILM] TS conversion of Edit policy components (elastic#74747)
  [Resolver] simulator tests select elements directly instead of using descendant selectors. (elastic#75058)
  [Enterprise Search] Add Workplace Search side navigation (elastic#74894)
  [Security solution] Sourcerer: Kibana index pattern selector for security views (elastic#74706)
  [Logs UI] Remove apollo deps from log link-to routes (elastic#74502)
  [Maps] add map configurations to docker list (elastic#75035)
  [functional test][saved objects] update tests for additional copy saved objects to space (elastic#74907)
  Make the alerts plugin support generics (elastic#72716)
  ...
weltenwort added a commit to weltenwort/kibana that referenced this pull request Aug 17, 2020
… routes

Partially backports the following commits to 7.x:
 - [Logs UI] Remove apollo deps from log link-to routes (elastic#74502)

This backport only includes the route fix for elastic#74916 to make it
available in 7.9.x.
weltenwort added a commit that referenced this pull request Aug 17, 2020
…75071)

Backports the following commits to 7.x:
 - [Logs UI] Remove apollo deps from log link-to routes (#74502)
weltenwort added a commit that referenced this pull request Aug 17, 2020
… routes (#75140)

Partially backports the following commits to 7.x:
 - [Logs UI] Remove apollo deps from log link-to routes (#74502)

This backport only includes the route fix for #74916 to make it
available in 7.9.x.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Logs UI Logs UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.10.0 v8.0.0
Projects
None yet
4 participants