Skip to content

[Guided onboarding] Fix multiple API requests when fetching guide state#144160

Merged
yuliacech merged 12 commits intoelastic:mainfrom
yuliacech:guided_onboarding/8.6_fix_api_requests_spam
Nov 2, 2022
Merged

[Guided onboarding] Fix multiple API requests when fetching guide state#144160
yuliacech merged 12 commits intoelastic:mainfrom
yuliacech:guided_onboarding/8.6_fix_api_requests_spam

Conversation

@yuliacech
Copy link
Contributor

@yuliacech yuliacech commented Oct 28, 2022

Summary

This PR fixes a bug that guided onboarding is spamming API requests when loading guide state (for example to check if a step is active). The issue was caused by the code not checking if a request was already in flight before sending the next one. The assumption was that one request would complete before any other subscriptions would be made to the observable. However, when a component is being re-rendered several times in fast succession, there were several subscriptions and the requests were not able to complete.
I introduced a check for the request in flight and a handle to abort the request if the subscription is unsubscribed.

@yuliacech yuliacech added release_note:skip Skip the PR/issue when compiling release notes Team:Journey/Onboarding Platform Journey Onboarding team v8.6.0 labels Oct 28, 2022
@yuliacech yuliacech marked this pull request as ready for review October 28, 2022 15:54
@yuliacech yuliacech requested a review from a team as a code owner October 28, 2022 15:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-onboarding (Team:Journey/Onboarding)

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Thanks so much for taking this on! I found one issue with the "complete" state not updating. I left a suggestion that I think could resolve it.

this.isGuideStateLoading = false;
// There should only be 1 active guide
const hasState = response.state.length === 1;
if (hasState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will break the "complete" state; we need to update this.onboardingGuideState$ once the user completes a guide so we know to hide the setup guide button. I think this will be irrelevant if you follow my suggestion below.

})
)
: of(state)
!state && !this.isGuideStateLoading ? this.createGetStateObservable() : of(state)
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to my comment above. I think we need a way to differentiate between state that is undefined because it hasn't been fetched yet vs. state that is undefined bc the active guide has been completed.

Maybe we should rethink this line in updateGuideState and maintain the state:

// If the guide has been deactivated, we return undefined
this.onboardingGuideState$.next(newState.isActive ? newState : undefined);

Change to:

this.onboardingGuideState$.next(newState);

Then, I think we'd need to update guide_panel.tx when checking for the config:

const guideConfig = guideState?.isActive && getGuideConfig(guideState?.guideId);

await pageObjects.infraHome.ensureTourStepIsClosed('guidedSetupStep');
});
// only run these tests on Cloud
if (isCloud) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this!

@yuliacech
Copy link
Contributor Author

Thanks a lot for your review, @alisonelizabeth! Great catch with the completed state not updating, I used your suggestions and added a couple of tests. I might update the guide state observable even further when I'll work on the button logic. We probably do need an indicator of an overall guided onboarding state.

@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Page load bundle

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

id before after diff
guidedOnboarding 23.6KB 24.0KB +365.0B
Unknown metric groups

API count

id before after diff
@kbn/guided-onboarding 22 23 +1

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 57 63 +6
osquery 103 108 +5
securitySolution 439 443 +4
total +17

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 65 71 +6
osquery 104 110 +6
securitySolution 516 520 +4
total +18

History

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

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

Latest LGTM. Great work!

@yuliacech yuliacech merged commit 02a2a6a into elastic:main Nov 2, 2022
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Nov 2, 2022
tylersmalley added a commit that referenced this pull request Nov 2, 2022
@tylersmalley
Copy link
Member

Apologies, I needed to revert this as it hit a type error when merged with main.

CI: https://buildkite.com/elastic/kibana-on-merge/builds/23082#01843930-82e0-4fa2-8c45-4f6c1baf6b3e/193-533

main: 02a2a6a

@yuliacech
Copy link
Contributor Author

Thanks for the heads up @tylersmalley! Yes, there was another PR that got merged shortly before this one and caused a types error. I'll fix this and open a new PR.

yuliacech added a commit to yuliacech/kibana that referenced this pull request Nov 2, 2022
yuliacech added a commit that referenced this pull request Nov 2, 2022
…tching guide state (#144160)"" (#144459)

* Revert "Revert "[Guided onboarding] Fix multiple API requests when fetching guide state (#144160)""

This reverts commit a4445f9.

* [Guided onboarding] Fix type errors
stephmilovic added a commit that referenced this pull request Nov 15, 2022
## Summary

Removes the feature flag for the guided onboarding tour in security

To be merged after #144160. Make sure we run the Cypress tests after
#144160 is merged before merging this

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Yulia Čech <6585477+yuliacech@users.noreply.github.com>
@yuliacech yuliacech deleted the guided_onboarding/8.6_fix_api_requests_spam branch November 22, 2022 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes reverted Team:Journey/Onboarding Platform Journey Onboarding team v8.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants