-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Background search] Change polling behavior #244760
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
Open
AlexGPlay
wants to merge
3
commits into
elastic:main
Choose a base branch
from
AlexGPlay:230909-change-polling-behaviour
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−37
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,19 +9,22 @@ | |
|
|
||
| import type { PublicContract, SerializableRecord } from '@kbn/utility-types'; | ||
| import { | ||
| EMPTY, | ||
| distinctUntilChanged, | ||
| filter, | ||
| from, | ||
| interval, | ||
| map, | ||
| mapTo, | ||
| mergeMap, | ||
| repeat, | ||
| startWith, | ||
| switchMap, | ||
| take, | ||
| takeUntil, | ||
| tap, | ||
| } from 'rxjs'; | ||
| import type { Observable } from 'rxjs'; | ||
| import { BehaviorSubject, combineLatest, EMPTY, from, merge, of, Subscription, timer } from 'rxjs'; | ||
| import { BehaviorSubject, combineLatest, merge, of, Subscription, timer } from 'rxjs'; | ||
| import type { | ||
| PluginInitializerContext, | ||
| StartServicesAccessor, | ||
|
|
@@ -50,7 +53,7 @@ import type { ISearchSessionEBTManager } from './ebt_manager'; | |
| * Polling interval for keeping completed searches alive | ||
| * until the user saves the session | ||
| */ | ||
| const KEEP_ALIVE_COMPLETED_SEARCHES_INTERVAL = 30000; | ||
| const KEEP_ALIVE_COMPLETED_SEARCHES_INTERVAL = 30_000; | ||
|
|
||
| /** | ||
| * To prevent the session ids map from growing indefinitely we can use an LRU cache - we will limit it to 30 sessions for | ||
|
|
@@ -306,8 +309,20 @@ export class SessionService { | |
| if (!this.hasAccess()) return EMPTY; // don't need to keep searches alive if the user can't save session | ||
| if (!this.isSessionStorageReady()) return EMPTY; // don't need to keep searches alive if app doesn't allow saving session | ||
|
|
||
| const finishedStates = [ | ||
| SearchSessionState.Completed, | ||
| SearchSessionState.BackgroundCompleted, | ||
| SearchSessionState.Restored, | ||
| SearchSessionState.Canceled, | ||
| ]; | ||
|
|
||
| const stopOnFinishedState$ = this.state$.pipe( | ||
| filter((state) => finishedStates.includes(state)), | ||
| take(1) | ||
| ); | ||
|
|
||
| const schedulePollSearches = () => { | ||
| return timer(KEEP_ALIVE_COMPLETED_SEARCHES_INTERVAL).pipe( | ||
| return interval(KEEP_ALIVE_COMPLETED_SEARCHES_INTERVAL).pipe( | ||
| mergeMap(() => { | ||
| const searchesToKeepAlive = this.state.get().trackedSearches.filter( | ||
| (s) => | ||
|
|
@@ -333,8 +348,8 @@ export class SessionService { | |
| ) | ||
| ); | ||
| }), | ||
| repeat(), | ||
| takeUntil(this.disableSaveAfterSearchesExpire$.pipe(filter((disable) => disable))) | ||
| takeUntil(this.disableSaveAfterSearchesExpire$.pipe(filter((disable) => disable))), | ||
| takeUntil(stopOnFinishedState$) | ||
|
Comment on lines
+351
to
+352
Contributor
Author
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. this is the main change, now on top of the existing behavior we stop when the search session is in a completed status |
||
| ); | ||
| }; | ||
|
|
||
|
|
||
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.
i've changed it from timer + repeat to just use interval