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

Variables: Notify scene after each variable completion or value change #525

Merged
merged 16 commits into from
Jan 22, 2024

Conversation

torkelo
Copy link
Member

@torkelo torkelo commented Jan 5, 2024

Removes the batching of the notifications so they happen right away after a variable update is completed or value is changed. This requires a breaking chance to SceneVariableDependencyConfigLike but I think it's worth it.

Proper fix for #524

PR changes:

  • Makes scene updates more efficient as parts of the scene now get notified right away when a variable is changed instead of having to wait for all variables. There is an increased cost as this requires more calls to sceneGraph.hasVariableDependencyInLoadingState to check if any other variable dependency is still loading but it's worth it I think.
  • VariableDependencyConfig now handles the "waitingForVariables" state logic

So the main flow after this is this

SceneVariableSet will always notify the scene after each variable completes an update process and / or when the variable changes value. This is done in the same callback (and in case a loading variable changes value after loading is complete this is done in a single call)

VariableDependencyLike interface

 variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void;

Scene objects care about two updates, when a variable that they depend on directly has changed or when a variable has completed an update process (no matter if it changed or not). This is because sceneGraph.hasVariableDependencyInLoadingState(X) returns true if a variable or its dependency is in a loading state. SceneQueryRunner will wait to issue the query until that function returns false. But to check again the SceneQueryRunner will need to know whenever a variable completes it's "loading/value validation" phase.

This is not different from how it works now, only difference is that we now check this after each variable completes.

VariableDependencyConfig (the default implementation) will take care of checking whether the changed variable is a dependency (so in it's callback the hasChanged boolean is now named dependencyChanged). In #526 I also expand the role of VariableDependencyConfig to handle the "isWaitingForVariables" state so that it is not duplicated and spread in multiple places.

  • This causes VizPanel to re-render for each of its variable dependencies as they change, we could have an option in VariableDependencyConfig to batch notifications together after the last dependency in a loading state is completed. But I think we can leave this optimization for the future.

Release notes

VariableDependencyConfigLike interface has changed so that scene objects now get notified after each variable update is completed (or changed value). Before, the SceneVariableSet waited for all variables to complete before notifying scene objects.

The function variableUpdatesCompleted has changed name and signature:

variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void;

VariableDependencyConfig has also some breaking changes. The function named onVariableUpdatesCompleted has changed name and signature to:

 onVariableUpdateCompleted?: () => void;

VariableDependencyConfig now handles the state logic for "waitingForVariables". If you call VariableDependencyConfig.hasDependencyInLoadingState and it returns true it will remember this waiting state and call onVariableUpdateCompleted as soon as the next variable update is completed, no matter if that variable is a dependency or if it changed or not.

Base automatically changed from dependency-check-fix to main January 8, 2024 08:38
@torkelo
Copy link
Member Author

torkelo commented Jan 8, 2024

@dprokop added some more description to the flow of the change

Comment on lines 223 to 224
private onVariableUpdatesCompleted(variable: SceneVariable, dependencyChanged: boolean) {
if (this.state._isWaitingForVariables || dependencyChanged) {
Copy link
Member

Choose a reason for hiding this comment

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

This feels wrong or hard to reason about. Won't this trigger queries for individual variable changes?

Copy link
Member

Choose a reason for hiding this comment

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

All right, I get it now, we also check whethere or not there are any variables pending in the runWithTimeRange call. Think we need to document the Variables/SQR flow in some readme as it's already quite complex and certain assumptions are not documented anywhere but in the PRs. WDYT?

@torkelo torkelo added the major Increment the major version when merged label Jan 8, 2024
@torkelo
Copy link
Member Author

torkelo commented Jan 8, 2024

@dprokop added some docs and release notes

@dprokop
Copy link
Member

dprokop commented Jan 10, 2024

Would wait for @domasx2 review before landing this, ok?

@torkelo
Copy link
Member Author

torkelo commented Jan 15, 2024

@domasx2 had a chance to look at this? this should fix your issue

@domasx2
Copy link
Contributor

domasx2 commented Jan 16, 2024

Hey! Unfortunately I refactored out this use case in app o11y, so no longer have something to test against

@torkelo torkelo added the release Create a release when this pr is merged label Jan 22, 2024
@torkelo torkelo merged commit b827025 into main Jan 22, 2024
3 checks passed
@torkelo torkelo deleted the variable-scene-notify-rethink branch January 22, 2024 08:18
@grafanabot
Copy link
Contributor

🚀 PR was released in v2.0.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major Increment the major version when merged release Create a release when this pr is merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants