Cancel in-flight queries when panel scrolls out of view#1417
Open
setoh2000 wants to merge 1 commit intografana:mainfrom
Open
Cancel in-flight queries when panel scrolls out of view#1417setoh2000 wants to merge 1 commit intografana:mainfrom
setoh2000 wants to merge 1 commit intografana:mainfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
#1148 added lazy loading support:
SceneQueryRunnerno longer starts queries for panels that are outside the viewport when a time range change or variable change occurs.However, there is still a gap: if a query is already running when the panel scrolls out of view, the request is left alive until it completes. This PR addresses that remaining case by cancelling in-flight queries as soon as a panel leaves the viewport.
Motivation
Grafana's Panel Repeat feature makes it easy to generate 100+ panels from a single template. When a user scrolls quickly through such a dashboard, each panel fires a query the moment it enters the viewport — even briefly. As the user scrolls past, all those queries remain in-flight — consuming browser connections, backpressure on the datasource, and delaying results for the panels actually on screen.
A concrete example: a dashboard with 100 repeated panels, each running a query that takes 100 ms+. Scrolling to the bottom means waiting for ~90 in-flight queries from off-screen panels to complete before the visible ones get their turn.
What this PR adds
A private
_isQueryInFlightboolean is introduced toSceneQueryRunnerto track whether a datasource query is currently running.When
isInViewChanged(false)is called while a query is in flight, the subscription is immediately unsubscribed and the panel is flagged to re-run when it returns to view — exactly the same behavior as when a variable changes while a panel is out of view.Two async race condition guards are also added inside
runWithTimeRange(after theawait getDataSource()call) to handle the case where the viewport changes during the async setup phase.