-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Cancel visualize fetches when navigating away or re-fetching #42035
Merged
lukasolson
merged 33 commits into
elastic:master
from
lukasolson:cancelVisualizeRequests
Aug 28, 2019
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
802f608
add AbortSignal to interpreter
ppisljar daf72d2
adding AbortSignal to visualize_loader
ppisljar 332dae1
adding AbortSignal to embeddables and dashboard
ppisljar 04e1240
passing AbortSignal to courier request handler
ppisljar 0c429c1
Remove abort signal from dashboard and move to handler, and abort fet…
lukasolson 095860e
Remove the rest of the references to abort signal in dashboard
lukasolson 3c7e344
Revert changes to dashboard_app
lukasolson 4af0b64
Remove code related to canceling visualize requests and only keep stu…
lukasolson 89ebc13
Merge branch 'master' into interpreter/canceling
lukasolson d8f5208
Use createError
lukasolson 00a672d
Cancel in-progress fetches when a new one is requested or when leavin…
lukasolson 1d7f782
Merge branch 'master' into cancelVisualizeRequests
lukasolson b37525f
Update with cancel methods and make visualize data loader work
lukasolson dd784a3
Remove unnecessary call to
lukasolson cb2fb2d
Fix tests
lukasolson daa3a48
Merge branch 'master' of github.com:elastic/kibana into cancelVisuali…
lukasolson 897cd96
Merge branch 'master' into cancelVisualizeRequests
lukasolson 3f0b86f
Remove cancel from data loaders
lukasolson 5ddfe24
Merge branch 'cancelVisualizeRequests' of github.com:lukasolson/kiban…
lukasolson b1ec8e4
Fix search source to always either resolve or reject in fetch()
lukasolson 215be5d
Fix naming
lukasolson d8535d4
Merge branch 'master' into cancelVisualizeRequests
lukasolson d63a824
Update search request to reject on abort, and don't render errors in …
lukasolson aeb5045
Update tests
lukasolson 726c4a0
Merge branch 'master' into cancelVisualizeRequests
lukasolson 8255d2f
Merge branch 'master' into cancelVisualizeRequests
lukasolson 6492023
Merge branch 'master' into cancelVisualizeRequests
lukasolson 728a7b4
Add cancellation to input control
lukasolson e068744
Cancel histogram fetches
lukasolson 72a8965
Update esaggs typings
lukasolson 33180fb
Merge branch 'master' into cancelVisualizeRequests
lukasolson d5983e4
Add cancellation for search embeddables
lukasolson 4949fb4
Abort post-flight requests
lukasolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ export class EmbeddedVisualizeHandler { | |
private actions: any = {}; | ||
private events$: Rx.Observable<any>; | ||
private autoFetch: boolean; | ||
private abortController?: AbortController; | ||
private autoRefreshFetchSubscription: Rx.Subscription | undefined; | ||
|
||
constructor( | ||
|
@@ -268,6 +269,7 @@ export class EmbeddedVisualizeHandler { | |
*/ | ||
public destroy(): void { | ||
this.destroyed = true; | ||
this.cancel(); | ||
this.debouncedFetchAndRender.cancel(); | ||
if (this.autoFetch) { | ||
if (this.autoRefreshFetchSubscription) this.autoRefreshFetchSubscription.unsubscribe(); | ||
|
@@ -443,7 +445,14 @@ export class EmbeddedVisualizeHandler { | |
this.fetchAndRender(); | ||
}; | ||
|
||
private cancel = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, i think so, but not necessary for now |
||
if (this.abortController) this.abortController.abort(); | ||
}; | ||
|
||
private fetch = (forceFetch: boolean = false) => { | ||
this.cancel(); | ||
lukasolson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.abortController = new AbortController(); | ||
this.dataLoaderParams.abortSignal = this.abortController.signal; | ||
this.dataLoaderParams.aggs = this.vis.getAggConfig(); | ||
this.dataLoaderParams.forceFetch = forceFetch; | ||
this.dataLoaderParams.inspectorAdapters = this.inspectorAdapters; | ||
|
@@ -452,23 +461,27 @@ export class EmbeddedVisualizeHandler { | |
this.vis.requestError = undefined; | ||
this.vis.showRequestError = false; | ||
|
||
return this.dataLoader | ||
.fetch(this.dataLoaderParams) | ||
.then(data => { | ||
// Pipeline responses never throw errors, so we need to check for | ||
// `type: 'error'`, and then throw so it can be caught below. | ||
// TODO: We should revisit this after we have fully migrated | ||
// to the new expression pipeline infrastructure. | ||
if (data && data.type === 'error') { | ||
throw data.error; | ||
} | ||
|
||
if (data && data.value) { | ||
this.dataSubject.next(data.value); | ||
} | ||
return data; | ||
}) | ||
.catch(this.handleDataLoaderError); | ||
return ( | ||
this.dataLoader | ||
// Don't pass in this.dataLoaderParams directly because it may be modified async in another | ||
// call to fetch before the previous one has completed | ||
.fetch({ ...this.dataLoaderParams }) | ||
.then(data => { | ||
// Pipeline responses never throw errors, so we need to check for | ||
// `type: 'error'`, and then throw so it can be caught below. | ||
// TODO: We should revisit this after we have fully migrated | ||
// to the new expression pipeline infrastructure. | ||
if (data && data.type === 'error') { | ||
throw data.error; | ||
} | ||
|
||
if (data && data.value) { | ||
this.dataSubject.next(data.value); | ||
} | ||
return data; | ||
}) | ||
.catch(this.handleDataLoaderError) | ||
); | ||
}; | ||
|
||
/** | ||
|
@@ -478,6 +491,9 @@ export class EmbeddedVisualizeHandler { | |
* frequently encountered by users. | ||
*/ | ||
private handleDataLoaderError = (error: any): void => { | ||
// If the data loader was aborted then no need to surface this error in the UI | ||
if (error && error.name === 'AbortError') return; | ||
|
||
// TODO: come up with a general way to cancel execution of pipeline expressions. | ||
if (this.dataLoaderParams.searchSource && this.dataLoaderParams.searchSource.cancelQueued) { | ||
this.dataLoaderParams.searchSource.cancelQueued(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rather pass abortSignal in here to have same implementation as in other places ?( abortSignal.addEventListener)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't quite work since this method is called from both
buildVislibDimensions
(which has access to theabortSignal
but not thesearchRequest
) andsearchSource.requestIsStarting
(which has access to thesearchRequest
but not theabortSignal
). I could theoretically pass inabortSignal
as an additional argument, then check bothsearchRequest
andabortSignal
but that seems kinda messy. Any other proposals?