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] Only cache non-alias dashboards #175635

Merged

Conversation

Heenawter
Copy link
Contributor

@Heenawter Heenawter commented Jan 25, 2024

Summary

This PR fixes the alias redirect problem that was noted in the attached SDH.

For context, as part of the Links panel work, I added dashboard caching to make navigation more efficient - however, when implementing this, I did not consider the redirect behaviour.

Specifically, we were always adding dashboards to the cache, even if the load outcome meant a redirect was necessary - so, because the meta info for the dashboard fetch result was cached, this meant that the 'aliasMatch' outcome was also cached. Because of this, after a redirect happened, the second attempt to load the dashboard would return the result from the cache rather than fetching the dashboard from the CM client - but, as described previously, the cached dashboard would still appear as though it required a redirect because the cached outcome was 'aliasMatch'.

Therefore, because of hitting this early return on both fetch attempts (before the redirect, after the redirect)...

const validationResult = loadDashboardReturn && validateLoadedSavedObject?.(loadDashboardReturn);
if (validationResult === 'invalid') {
// throw error to stop the rest of Dashboard loading and make the factory return an ErrorEmbeddable.
throw new Error('Dashboard failed saved object result validation');
} else if (validationResult === 'redirected') {
return;
}

... the dashboard information would not get updated. (Oof!)

Despite the lengthy description of the problem, the solution is quite simple - just don't add dashboards to the cache if they require a redirect. And then everything works! 🎉

Videos

Before

Screen.Recording.2024-01-25.at.2.06.49.PM.mov

After

Screen.Recording.2024-01-25.at.2.08.24.PM.mov

Testing

To test, I followed the directions from this PR description to get a dashboard that requires a redirect - then, I created a markdown panel with the old (from the Default space) dashboard ID in the new space to see the same redirect behaviour that the customer in the SDH was seeing.

Checklist

For maintainers

@Heenawter Heenawter added bug Fixes for quality problems that affect the customer experience Feature:Dashboard Dashboard related features release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:small Small Level of Effort impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. labels Jan 25, 2024
@Heenawter Heenawter self-assigned this Jan 25, 2024
@Heenawter
Copy link
Contributor Author

/ci

@Heenawter
Copy link
Contributor Author

/ci

@Heenawter Heenawter marked this pull request as ready for review January 25, 2024 21:29
@Heenawter Heenawter requested a review from a team as a code owner January 25, 2024 21:29
@elasticmachine
Copy link
Contributor

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

@ThomThomson ThomThomson self-requested a review January 25, 2024 21:50
@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 382.6KB 382.6KB +37.0B

History

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

cc @Heenawter

@Heenawter Heenawter added backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) v8.12.1 v8.13.0 labels Jan 26, 2024
Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Thank you for diving in, diagnosing, and fixing this @Heenawter!

The last time this functionality broke, I wrote this in the PR description:

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.

Unfortunately, that idea slipped through the cracks and I forgot to write tests to cover this, which is why it ended up breaking again.

While this PR adds unit test coverage, functional test coverage is still important here IMO, but it's also could still be quite difficult. @elastic/kibana-presentation let's discuss how to cover this with functional tests.

After discussion, we can build the functional test coverage in a follow-up. LGTM!

savedObjectsTagging,
};

describe('Load dashboard state', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see new jest tests for this case!

@Heenawter Heenawter merged commit 27b34d5 into elastic:main Jan 26, 2024
23 checks passed
@Heenawter Heenawter added backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) and removed v8.12.1 v8.13.0 backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) labels Jan 26, 2024
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 26, 2024
## Summary

This PR fixes the alias redirect problem that was noted in the attached
SDH.

For context, as part of the [Links panel
work](elastic#166896), I added [dashboard
caching](elastic#162285) to make
navigation more efficient - however, when implementing this, I did not
consider the redirect behaviour.

Specifically, we were **always** adding dashboards to the cache, even if
the load outcome meant a redirect was necessary - so, because the meta
info for the dashboard fetch result was cached, this meant that the
`'aliasMatch'` outcome was **also** cached. Because of this, after a
redirect happened, the second attempt to load the dashboard would return
the result from the **cache** rather than fetching the dashboard from
the CM client - but, as described previously, the cached dashboard would
still appear as though it required a redirect because the cached outcome
was `'aliasMatch'`.

Therefore, because of hitting this early return on **both** fetch
attempts (before the redirect, after the redirect)...

https://github.com/elastic/kibana/blob/4565b1bfba91cd24f73f8ce37fa7be73283a4453/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts#L165-L171

... the dashboard information would not get updated. _(Oof!)_

Despite the lengthy description of the problem, the solution is quite
simple - just don't add dashboards to the cache if they require a
redirect. And then everything works! 🎉

### Videos
**Before**

https://github.com/elastic/kibana/assets/8698078/983b81a6-acf3-4e71-804a-6ed75c36896f

**After**

https://github.com/elastic/kibana/assets/8698078/028369ff-f73f-43e6-9abb-b35f0d2f33e1

### Testing
To test, I followed the directions from [this PR
description](elastic#163658) to get a
dashboard that requires a redirect - then, I created a markdown panel
with the **old** (from the Default space) dashboard ID in the new space
to see the same redirect behaviour that the customer in the SDH was
seeing.

### Checklist
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 27b34d5)
@kibanamachine
Copy link
Contributor

kibanamachine commented Jan 26, 2024

💚 All backports created successfully

Status Branch Result
8.12

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

Questions ?

Please refer to the Backport tool documentation

@elastic elastic deleted a comment from kibanamachine Jan 26, 2024
@Heenawter Heenawter deleted the fix-alias-redirect-caching_2024-01-25 branch January 26, 2024 16:46
kibanamachine added a commit that referenced this pull request Jan 26, 2024
# Backport

This will backport the following commits from `main` to `8.12`:
- [[Dashboard] Only cache non-alias dashboards
(#175635)](#175635)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-01-26T16:09:28Z","message":"[Dashboard]
Only cache non-alias dashboards (#175635)\n\n## Summary\r\n\r\nThis PR
fixes the alias redirect problem that was noted in the
attached\r\nSDH.\r\n\r\nFor context, as part of the [Links
panel\r\nwork](#166896), I added
[dashboard\r\ncaching](#162285) to
make\r\nnavigation more efficient - however, when implementing this, I
did not\r\nconsider the redirect behaviour.\r\n\r\nSpecifically, we were
**always** adding dashboards to the cache, even if\r\nthe load outcome
meant a redirect was necessary - so, because the meta\r\ninfo for the
dashboard fetch result was cached, this meant that the\r\n`'aliasMatch'`
outcome was **also** cached. Because of this, after a\r\nredirect
happened, the second attempt to load the dashboard would return\r\nthe
result from the **cache** rather than fetching the dashboard from\r\nthe
CM client - but, as described previously, the cached dashboard
would\r\nstill appear as though it required a redirect because the
cached outcome\r\nwas `'aliasMatch'`.\r\n\r\nTherefore, because of
hitting this early return on **both** fetch\r\nattempts (before the
redirect, after the
redirect)...\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/4565b1bfba91cd24f73f8ce37fa7be73283a4453/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts#L165-L171\r\n\r\n...
the dashboard information would not get updated. _(Oof!)_
\r\n\r\nDespite the lengthy description of the problem, the solution is
quite\r\nsimple - just don't add dashboards to the cache if they require
a\r\nredirect. And then everything works! 🎉\r\n\r\n###
Videos\r\n**Before**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/983b81a6-acf3-4e71-804a-6ed75c36896f\r\n\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/028369ff-f73f-43e6-9abb-b35f0d2f33e1\r\n\r\n\r\n###
Testing\r\nTo test, I followed the directions from [this
PR\r\ndescription](#163658) to get
a\r\ndashboard that requires a redirect - then, I created a markdown
panel\r\nwith the **old** (from the Default space) dashboard ID in the
new space\r\nto see the same redirect behaviour that the customer in the
SDH was\r\nseeing.\r\n\r\n### Checklist\r\n- [x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"27b34d591111a878001eaac7b0f3ef0173bc8f02","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Dashboard","release_note:fix","Team:Presentation","loe:small","impact:high","backport:prev-minor","v8.12.1","v8.13.0"],"title":"[Dashboard]
Only cache non-alias
dashboards","number":175635,"url":"https://github.com/elastic/kibana/pull/175635","mergeCommit":{"message":"[Dashboard]
Only cache non-alias dashboards (#175635)\n\n## Summary\r\n\r\nThis PR
fixes the alias redirect problem that was noted in the
attached\r\nSDH.\r\n\r\nFor context, as part of the [Links
panel\r\nwork](#166896), I added
[dashboard\r\ncaching](#162285) to
make\r\nnavigation more efficient - however, when implementing this, I
did not\r\nconsider the redirect behaviour.\r\n\r\nSpecifically, we were
**always** adding dashboards to the cache, even if\r\nthe load outcome
meant a redirect was necessary - so, because the meta\r\ninfo for the
dashboard fetch result was cached, this meant that the\r\n`'aliasMatch'`
outcome was **also** cached. Because of this, after a\r\nredirect
happened, the second attempt to load the dashboard would return\r\nthe
result from the **cache** rather than fetching the dashboard from\r\nthe
CM client - but, as described previously, the cached dashboard
would\r\nstill appear as though it required a redirect because the
cached outcome\r\nwas `'aliasMatch'`.\r\n\r\nTherefore, because of
hitting this early return on **both** fetch\r\nattempts (before the
redirect, after the
redirect)...\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/4565b1bfba91cd24f73f8ce37fa7be73283a4453/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts#L165-L171\r\n\r\n...
the dashboard information would not get updated. _(Oof!)_
\r\n\r\nDespite the lengthy description of the problem, the solution is
quite\r\nsimple - just don't add dashboards to the cache if they require
a\r\nredirect. And then everything works! 🎉\r\n\r\n###
Videos\r\n**Before**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/983b81a6-acf3-4e71-804a-6ed75c36896f\r\n\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/028369ff-f73f-43e6-9abb-b35f0d2f33e1\r\n\r\n\r\n###
Testing\r\nTo test, I followed the directions from [this
PR\r\ndescription](#163658) to get
a\r\ndashboard that requires a redirect - then, I created a markdown
panel\r\nwith the **old** (from the Default space) dashboard ID in the
new space\r\nto see the same redirect behaviour that the customer in the
SDH was\r\nseeing.\r\n\r\n### Checklist\r\n- [x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"27b34d591111a878001eaac7b0f3ef0173bc8f02"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/175635","number":175635,"mergeCommit":{"message":"[Dashboard]
Only cache non-alias dashboards (#175635)\n\n## Summary\r\n\r\nThis PR
fixes the alias redirect problem that was noted in the
attached\r\nSDH.\r\n\r\nFor context, as part of the [Links
panel\r\nwork](#166896), I added
[dashboard\r\ncaching](#162285) to
make\r\nnavigation more efficient - however, when implementing this, I
did not\r\nconsider the redirect behaviour.\r\n\r\nSpecifically, we were
**always** adding dashboards to the cache, even if\r\nthe load outcome
meant a redirect was necessary - so, because the meta\r\ninfo for the
dashboard fetch result was cached, this meant that the\r\n`'aliasMatch'`
outcome was **also** cached. Because of this, after a\r\nredirect
happened, the second attempt to load the dashboard would return\r\nthe
result from the **cache** rather than fetching the dashboard from\r\nthe
CM client - but, as described previously, the cached dashboard
would\r\nstill appear as though it required a redirect because the
cached outcome\r\nwas `'aliasMatch'`.\r\n\r\nTherefore, because of
hitting this early return on **both** fetch\r\nattempts (before the
redirect, after the
redirect)...\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/4565b1bfba91cd24f73f8ce37fa7be73283a4453/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts#L165-L171\r\n\r\n...
the dashboard information would not get updated. _(Oof!)_
\r\n\r\nDespite the lengthy description of the problem, the solution is
quite\r\nsimple - just don't add dashboards to the cache if they require
a\r\nredirect. And then everything works! 🎉\r\n\r\n###
Videos\r\n**Before**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/983b81a6-acf3-4e71-804a-6ed75c36896f\r\n\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/elastic/kibana/assets/8698078/028369ff-f73f-43e6-9abb-b35f0d2f33e1\r\n\r\n\r\n###
Testing\r\nTo test, I followed the directions from [this
PR\r\ndescription](#163658) to get
a\r\ndashboard that requires a redirect - then, I created a markdown
panel\r\nwith the **old** (from the Default space) dashboard ID in the
new space\r\nto see the same redirect behaviour that the customer in the
SDH was\r\nseeing.\r\n\r\n### Checklist\r\n- [x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"27b34d591111a878001eaac7b0f3ef0173bc8f02"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
## Summary

This PR fixes the alias redirect problem that was noted in the attached
SDH.

For context, as part of the [Links panel
work](elastic#166896), I added [dashboard
caching](elastic#162285) to make
navigation more efficient - however, when implementing this, I did not
consider the redirect behaviour.

Specifically, we were **always** adding dashboards to the cache, even if
the load outcome meant a redirect was necessary - so, because the meta
info for the dashboard fetch result was cached, this meant that the
`'aliasMatch'` outcome was **also** cached. Because of this, after a
redirect happened, the second attempt to load the dashboard would return
the result from the **cache** rather than fetching the dashboard from
the CM client - but, as described previously, the cached dashboard would
still appear as though it required a redirect because the cached outcome
was `'aliasMatch'`.

Therefore, because of hitting this early return on **both** fetch
attempts (before the redirect, after the redirect)...


https://github.com/elastic/kibana/blob/4565b1bfba91cd24f73f8ce37fa7be73283a4453/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts#L165-L171

... the dashboard information would not get updated. _(Oof!)_ 

Despite the lengthy description of the problem, the solution is quite
simple - just don't add dashboards to the cache if they require a
redirect. And then everything works! 🎉

### Videos
**Before**


https://github.com/elastic/kibana/assets/8698078/983b81a6-acf3-4e71-804a-6ed75c36896f


**After**


https://github.com/elastic/kibana/assets/8698078/028369ff-f73f-43e6-9abb-b35f0d2f33e1


### Testing
To test, I followed the directions from [this PR
description](elastic#163658) to get a
dashboard that requires a redirect - then, I created a markdown panel
with the **old** (from the Default space) dashboard ID in the new space
to see the same redirect behaviour that the customer in the SDH was
seeing.

### Checklist
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) bug Fixes for quality problems that affect the customer experience 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:small Small Level of Effort release_note:fix Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.12.1 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants