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

[Lens] Integrate searchSessionId into Lens app #86297

Merged
merged 11 commits into from
Dec 29, 2020

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Dec 17, 2020

Summary

Fix: #85517

the aim of the PR is to integrate the searchSessionId parameter in the Lens EditorFrame component.
During the integration it was noticed that there were duplicate state updates on filter updates: that led to a refactor of the state update process to remove the duplications.

  • ✨ Add searchSessionId on Editor open/landing
  • 🔥 Clear the session id on app leave
  • 🔥 remove duplicate state update
  • ✅ Add unit tests for new integration
    • this required a small refactor of the services mocks
    • some tangential tests have been updated with a searchSessionId mock to work

Manual tests have been performed to test various app leave flows. They should all be covered now, but any feedback on this side is welcome.

Checklist

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Lens v7.12.0 labels Dec 17, 2020
@dej611 dej611 requested a review from a team December 17, 2020 14:31
@elasticmachine
Copy link
Contributor

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

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.

Didn't test in depth yet, but two things:

  • Is it resetting the search session id on refresh?
  • Seems like it's not using the search session id for the suggestion panels

@dej611
Copy link
Contributor Author

dej611 commented Dec 17, 2020

  • Is it resetting the search session id on refresh?

Yes.

  • Seems like it's not using the search session id for the suggestion panels

You are quite right 😓

@dej611
Copy link
Contributor Author

dej611 commented Dec 17, 2020

Added the session id for suggestions too: not sure what to test in there.

@flash1293
Copy link
Contributor

@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.

Looks pretty good already, I just noticed one problem - if auto-refresh is used, the session id is not reset.

You can subscribe to the observable provided by the timefilter service in the data plugin to get notified and change the session id based on it (timefilter.getAutoRefreshFetch$()).

If you do this, you can probably remove the subscriptions in the workspace and suggestion panels as they would get refetch automatically because of the incoming session id change - simplifying the code there as a little bonus :)

const autoRefreshFetch$ = useMemo(() => timefilter.getAutoRefreshFetch$(), [timefilter]);
and
const autoRefreshFetch$ = plugins.data.query.timefilter.timefilter.getAutoRefreshFetch$();

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I ran into exactly the same problem as you are, which is that the API of onAppLeave is unintuitive. We will need to find another solution to clearing searchSessionId.

@@ -205,6 +212,8 @@ export function App({

useEffect(() => {
onAppLeave((actions) => {
// Clear the session when leaving Lens
data.search.session.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely should not be adding side effects to the onAppLeave handler because of how it's called. The onAppLeave function is executed immediately, and is not executed when the user tries to leave. Basically it sets up a state that says "if the user were to leave in the future, prevent them".

What this means is that I don't think we have a reliable way to make a side effect happen as the user is leaving, and I don't think we should be adding any side effects to the onAppLeave handlers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, I guess we can put it in an unmount handler (e.g. useUnmount() )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did some investigation on this area:

  • during the saving process, no problem with that, as the clear can be explicitly set
  • otherwise if the user clicks on another plugin/app there's no other way to intercept it within Lens and clear the session. The session check happens before the component get unmounted leading to an error page. Note that this error page happens only on the dev environment, while in production the session gets cleared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed with @flash1293 and found a simpler solution to that

dateRange: {
fromDate: dateRange.from,
toDate: dateRange.to,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

So we're using the timeFilter manager instead now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code was already using the timeFilter, but this code here was covering the scenario where the data didn't change but we want the state to trigger a new render ("Refresh" click).
Previously when the dateRange values changed the state was update twice with the same content, triggering a double rendering. Now this scenario is covered by the timeFilter subscription.
In case of no dateRange change ("Refresh" button), the session id is regenerated triggering a re-render now.

We still need the dateRange state, but we can reduce the number of time we update it.

@@ -89,6 +89,7 @@ export function App({
isSaveModalVisible: false,
indicateNoData: false,
isSaveable: false,
searchSessionId: data.search.session.start(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove dateRange from the LensAppState now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the dateRange out of state in the last commit. An object reference needs to be still hold for the frame component, but there's a single source of truth now for it.

/>
);
}, [plugins.data.query.timefilter.timefilter, ExpressionRendererComponent]);
}, [frame.searchSessionId, ExpressionRendererComponent]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes the component to get renewed each time the session id changes, which causes the loading bug again that got fixed with #86092

Please either put the search session id in a ref as well to avoid that or remove the AutoRefreshExpressionRenderer completely and just pass session id and search context down to the place where the component is actually used. With both of these approaches we can make sure the expression loader is not destroyed and re-created for each change.

I'm also seeing duplicated requests for the suggestions, but those might be caused by the same problem

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 and works as expected. The issue with double fetch is caused by another problem, I will create a separate PR to fix

@flash1293
Copy link
Contributor

@elasticmachine merge upstream

@dej611
Copy link
Contributor Author

dej611 commented Dec 28, 2020

@elasticmachine merge upstream

@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
lens 1.0MB 1.0MB +348.0B

Distributable file count

id before after diff
default 47267 48027 +760

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 54.2KB 54.3KB +64.0B

History

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

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Changes LGTM!

@dej611 dej611 merged commit bd908c6 into elastic:master Dec 29, 2020
@dej611 dej611 deleted the feature/85517 branch December 29, 2020 13:18
gmmorris added a commit to gmmorris/kibana that referenced this pull request Dec 30, 2020
* master: (108 commits)
  [DOCS] Refreshes Data Visualizer screenshot (elastic#87017)
  [Security Solution] Change 'anti-virus' text to 'antivirus' (elastic#87001)
  [securitySolution/cypress] temporarily limit to PRs
  [AppServices/Examples] Add the example for Reporting integration (elastic#82091)
  [Build Chromium] Improve git checkout (elastic#83225)
  Deprecate `services.callCluster` in alerts and actions executors (elastic#86474)
  [Security Solution] Use system node version for Cypress and increase exec command timeout (elastic#86985)
  [Lens] Add more chart editor tests based on the debug state (elastic#86750)
  [Lens] Integrate searchSessionId into Lens app (elastic#86297)
  skip "pagination updates results and page number" elastic#86975
  skip "Custom detection rules" elastic#83772
  [logging/json] use merge from kbn/std (elastic#86330)
  skip network and timeline inspection. elastic#85677, elastic#85678
  skip "adds correctly a filter to the global search bar" elastic#86552
  [ftr/flags] improve help text (elastic#86971)
  skip "Fields Browser rendering. elastic#60209
  skip "Closes and opens alerts" elastic#83773
  [Security Solution] Skip failing Cypress tests (elastic#86967)
  Removes archives (elastic#86537)
  [ML] Fix charts grid on the Anomaly Explorer page (elastic#86904)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Dec 30, 2020
* master: (72 commits)
  [DOCS] Refreshes Data Visualizer screenshot (elastic#87017)
  [Security Solution] Change 'anti-virus' text to 'antivirus' (elastic#87001)
  [securitySolution/cypress] temporarily limit to PRs
  [AppServices/Examples] Add the example for Reporting integration (elastic#82091)
  [Build Chromium] Improve git checkout (elastic#83225)
  Deprecate `services.callCluster` in alerts and actions executors (elastic#86474)
  [Security Solution] Use system node version for Cypress and increase exec command timeout (elastic#86985)
  [Lens] Add more chart editor tests based on the debug state (elastic#86750)
  [Lens] Integrate searchSessionId into Lens app (elastic#86297)
  skip "pagination updates results and page number" elastic#86975
  skip "Custom detection rules" elastic#83772
  [logging/json] use merge from kbn/std (elastic#86330)
  skip network and timeline inspection. elastic#85677, elastic#85678
  skip "adds correctly a filter to the global search bar" elastic#86552
  [ftr/flags] improve help text (elastic#86971)
  skip "Fields Browser rendering. elastic#60209
  skip "Closes and opens alerts" elastic#83773
  [Security Solution] Skip failing Cypress tests (elastic#86967)
  Removes archives (elastic#86537)
  [ML] Fix charts grid on the Anomaly Explorer page (elastic#86904)
  ...
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 31, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

2 similar comments
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens 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.

[Lens] Integrate search session id
5 participants