Skip to content

SceneQueryController: Do not mark query as complete on PartialResult state#1383

Open
tskarhed wants to merge 1 commit intomainfrom
fix/partial-result-query-controller
Open

SceneQueryController: Do not mark query as complete on PartialResult state#1383
tskarhed wants to merge 1 commit intomainfrom
fix/partial-result-query-controller

Conversation

@tskarhed
Copy link
Contributor

@tskarhed tskarhed commented Mar 5, 2026

Summary

  • registerQueryWithController now skips queryCompleted() when the emitted state is LoadingState.PartialResult, so SceneRenderProfiler only fires "All queries completed" after the final Done arrives
  • Streaming behaviour is unchanged — live tail queries still complete immediately on the first emission
  • Adds two new tests: one asserting that PartialResult does not complete the query, one asserting that Streaming still does

Context

LoadingState.PartialResult is a new state introduced in grafana/grafana#118796. It is used by Loki's querySplitting and shardQuerySplitting to mark intermediate chunks of a split query — unlike Streaming (used for live tail queries that run indefinitely), PartialResult always terminates with a final Done.

Before this fix, registerQueryWithController treated PartialResult identically to Streaming: it fired queryCompleted() on the first non-Loading emission. This meant SRP: All queries completed would fire as soon as the first split chunk arrived, giving an inaccurate measurement of the true query duration.

After this fix (verified via Playwright with sceneProfiling enabled on a 7-day Loki dashboard), SRP: All queries completed fires only after all split chunks have returned their final Done, with timings of 4700–5400 ms reflecting the actual full-range query completion.

Merge order

This PR depends on grafana/grafana#118796 being merged and @grafana/schema published with the PartialResult enum value before this can be released. The LoadingState.PartialResult check will silently no-op at runtime until then (the enum value resolves to undefined in older schema versions).

Test plan

  • yarn test:scenes -- --testPathPattern="SceneQueryController" passes
  • Manual verification: load a Loki dashboard with a 7-day range and localStorage.setItem('grafana.debug.sceneProfiling', 'true') — confirm SRP: All queries completed fires only after all panels have logged their final query timing

🤖 Generated with Claude Code

…state

Previously, registerQueryWithController called queryCompleted() on the
first non-Loading emission, including LoadingState.Streaming and the new
LoadingState.PartialResult. This caused SceneRenderProfiler to fire
"All queries completed" as soon as the first intermediate chunk arrived
from split queries (e.g. Loki's querySplitting), rather than waiting for
the final Done.

PartialResult (added in grafana/grafana#118796) is a new state used by
Loki's querySplitting and shardQuerySplitting to signal that more data
is still incoming and a final Done will follow. Unlike Streaming (which
is used for live-forever tail queries), PartialResult always terminates.

This change skips queryCompleted() when the state is PartialResult,
so the profiler only records completion after the final Done arrives.
Streaming is left unchanged — it still completes immediately, preserving
existing behaviour for live tail queries.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant