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

[Dashboard] Fix Alias Redirect Race Condition #161043

Merged

Conversation

ThomThomson
Copy link
Contributor

@ThomThomson ThomThomson commented Jun 30, 2023

Summary

This PR fixes a race condition that could happen in the case of an alias match redirect. Before this PR it was possible for a URL update (redirecting to the alias) to happen in the middle of building the errored state of the Dashboard. This would sometimes result in the error from the last dashboard (the old saved object id) being surfaced instead of the redirect properly firing.

To fix this, this PR allows the Dashboard factory to return undefined in the case of a redirect and updates the renderer to support that.

Before

Before.mp4

After

After

A note on tests

It seems like this alias match functionality breaks often enough that we should cover it with functional tests. Testing this will be difficult because we'll need to spoof a situation where a redirect would be required - which requires multiple spaces, and saved objects from 7.17. This test coverage should be added as a followup because it is important that this PR merged into 8.9.

How to test manually?

  1. Extract this file (containing ES Data with 7.17 ID conflicts).
    esData backup (7.17 ID conflicts).zip
  2. Start ES pointing to the extracted folder. yarn es snapshot -E path.data="/path/to/data"
  3. Load into the Super Cool New Space
  4. Paste in URL with an old ID to that Dashboard {Your address}/s/super-cool-new-space/app/dashboards#/view/326754f0-0ac2-11ee-9f77-63b7bd4c6a36
  5. The Dashboard should redirect properly to the new Dashboard with the ID ce23f0a9-47e2-5cf5-82b2-9446e880a0ae
  6. Paste the link from step 4 into your URL bar as many times as you want... it should keep redirecting properly!

@ThomThomson ThomThomson marked this pull request as ready for review July 4, 2023 13:40
@ThomThomson ThomThomson requested a review from a team as a code owner July 4, 2023 13:40
@ThomThomson
Copy link
Contributor Author

@elasticmachine merge upstream

@ThomThomson ThomThomson added Feature:Dashboard Dashboard related features release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:medium Medium Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. labels Jul 4, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@nreese nreese self-requested a review July 6, 2023 13:49
spaces.redirectLegacyUrl?.({ path, aliasPurpose });
return false; // redirected. Stop loading dashboard.
}
// navigate to alias on the next tick to allow Dashboard to finish rendering its error state.
Copy link
Contributor

@nreese nreese Jul 6, 2023

Choose a reason for hiding this comment

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

Instead of event stack hacking, how about changing the return type of validateOutcome to be a enum instead of a boolean, so you can better define outcomes. For example, really there are three outcomes - found, notFound, and redirect. That way, initializeDashboard can just return early in redirect case instead of going into an error state - which it should not enter, because redirect is not really an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea - let me give that a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion @nreese! I was able to get that working well, just had to propagate the fact that the embeddable create could return undefined up the chain. This also let me do at least a jest test verifies that in the event of a redirect result, dashboard create should return undefined.

@ThomThomson ThomThomson changed the title [Dashboard] Delay Alias redirect [Dashboard] Fix Alias Redirect Race Condition Jul 6, 2023
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.

LGTM
code review

@kibana-ci
Copy link
Collaborator

💚 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
dashboard 355.6KB 355.7KB +119.0B

Page load bundle

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

id before after diff
dashboard 42.4KB 42.4KB +4.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 489 493 +4
total +6

History

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

@ThomThomson ThomThomson merged commit 1d78311 into elastic:main Jul 6, 2023
19 checks passed
@ThomThomson ThomThomson added the backport:prev-minor Backport to the previous minor version (i.e. one version back from main) label Jul 6, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 6, 2023
Fixes a race condition that could happen in the case of an alias match redirect.

(cherry picked from commit 1d78311)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.9

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 6, 2023
Fixes a race condition that could happen in the case of an alias match redirect.

(cherry picked from commit 1d78311)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.9

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jul 6, 2023
# Backport

This will backport the following commits from `main` to `8.9`:
- [[Dashboard] Fix Alias Redirect Race Condition
(#161043)](#161043)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Devon
Thomson","email":"devon.thomson@elastic.co"},"sourceCommit":{"committedDate":"2023-07-06T20:19:54Z","message":"[Dashboard]
Fix Alias Redirect Race Condition (#161043)\n\nFixes a race condition
that could happen in the case of an alias match
redirect.","sha":"1d783110b343050be7f6c42d774fa1d6a2ead303","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","release_note:fix","Team:Presentation","loe:days","impact:high","v8.9.0","v8.10.0"],"number":161043,"url":"#161043
Fix Alias Redirect Race Condition (#161043)\n\nFixes a race condition
that could happen in the case of an alias match
redirect.","sha":"1d783110b343050be7f6c42d774fa1d6a2ead303"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"#161043
Fix Alias Redirect Race Condition (#161043)\n\nFixes a race condition
that could happen in the case of an alias match
redirect.","sha":"1d783110b343050be7f6c42d774fa1d6a2ead303"}}]}]
BACKPORT-->

Co-authored-by: Devon Thomson <devon.thomson@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to the previous minor version (i.e. one version back from main) Feature:Dashboard Dashboard related features impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:medium Medium Level of Effort release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.9.0 v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants