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

SceneQueryRunner: decouple time range comparisons #587

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sd2k
Copy link
Contributor

@sd2k sd2k commented Feb 9, 2024

Prior to this commit, SceneQueryRunner had special handling for
SceneTimeRangeCompare objects, explicitly searching for them in the
scene graph, adding additional queries, and transforming resulting
queries. This made it difficult to re-use the general behaviour of
'running additional queries' in other objects.

This commit introduces a new interface, SceneRequestAdder, which
can be implemented to inform the query runner that it should run
additional requests (returned by getExtraRequests) and transform the
results in some fashion.

Instead of searching the graph for SceneTimeRangeCompare objects,
the query runner searches for implementors of SceneRequestAdder
and uses those instead. The specifics of how it searches for these
is a little bit fuzzy and should probably be improved: it walks up the
graph until it finds at least one adder at the current level or in
any children of the current level; adds any others at that level
or in the children; then returns.

SceneTimeRangeCompare has been refactored to make use of this new
interface. I've also got a separate object which also implements
it which is working well including when both are enabled.

Relates to this Slack thread.

import { SceneObjectBase } from "../core/SceneObjectBase";
import { SceneObjectState } from "../core/types";

// A transformation function called by the query runner with responses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

naming: we already have 'transformations', maybe this should have a different name...

//
// The output is a single frame with the primary series and all transformed
// secondary series combined.
export const extraRequestProcessingOperator = (transforms: Map<string, TransformFunc>) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same applies here re. naming of transforms

}

// Indicates that this type wants to add extra requests to a query runner.
export interface SceneRequestAdder<T extends SceneObjectState> extends SceneObjectBase<T> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dislike the name SceneRequestAdder too, open to bikeshedding 🙂

@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from d35c5f3 to 7f75cef Compare February 9, 2024 22:00
@sd2k sd2k marked this pull request as ready for review February 11, 2024 17:19
@sd2k sd2k requested a review from torkelo February 14, 2024 10:59
@torkelo
Copy link
Member

torkelo commented Feb 14, 2024

@sd2k I think this looks interesting, sorry for late review. so much going on now with dashboard => scenes migration, and a customer project. We will try to review this in depth shortly, I think with some minor refactoring and name changes it looks overall promising / close, but I just did a very quick code scan

@sd2k
Copy link
Contributor Author

sd2k commented Feb 14, 2024

@sd2k I think this looks interesting, sorry for late review. so much going on now with dashboard => scenes migration, and a customer project. We will try to review this in depth shortly, I think with some minor refactoring and name changes it looks overall promising / close, but I just did a very quick code scan

No worries, it's not urgent, just wanted to make sure it didn't fall too far off the radar 👍

I'll try and add an example of how this can be used somewhere so it's a bit less abstract.

@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from 7f75cef to e12a606 Compare February 16, 2024 10:39
@sd2k
Copy link
Contributor Author

sd2k commented Feb 16, 2024

FYI I've added an example of using this to the scenes-baseliner branch branch along with a demo, should be easy to run but you'll need to use a version of Grafana with grafana/grafana#82299 merged in to load the plugin correctly since it depends on a WASM module.

I don't think that'd necessarily make it into the core repo since it's quite heavyweight but it's a decent example!

Also a live demo of a custom application observability build with this enabled.

@sd2k
Copy link
Contributor Author

sd2k commented Mar 12, 2024

One thing I bumped into while using this in other projects was that I can't see a way to turn off the extra SceneRequestAdders per-query runner. For example, in the live demo above the ScenesBaseliner runs for the various histogram panels as well as for the time series panels, but it can't really do much in those cases.

I imagine the solution would be to have a separate embedded scene with the baseline controls or something, but it might be nice to be able to say 'this SceneRequestAdder should only run for these queries' somehow 🤔

Edit: I just rebased on main and can see that #650 added the ability to opt out of time range comparisons; it's a tiny bit special-casey for now but I imagine we could do something similar for other RequestAdders (e.g. baselines: false).

@sd2k
Copy link
Contributor Author

sd2k commented Mar 21, 2024

Hey @torkelo, do you think you (or someone else) will have time to take a look at this in the next week or so? Happy to walk through it if you like.

@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from e12a606 to 4cc87f3 Compare March 21, 2024 20:13
@torkelo
Copy link
Member

torkelo commented Mar 22, 2024

@sd2k sorry, it's a bit of a bad time now with G11 / GrafanaCon crunch.

@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch 4 times, most recently from 8b74dd9 to 8154573 Compare April 24, 2024 13:52
@sd2k
Copy link
Contributor Author

sd2k commented Apr 24, 2024

I've tried to come up with some better names for the things I wasn't happy with ('adder' because it kinda sucks, and 'transform' because it's overused). The new names are maybe slightly better?

The best way to test this out, if anyone's interested, is to check out the Baselines demo in the demo app in the downstream scenes-baseliner branch which makes use of this PR to provide a second control similar to the time range comparison.

@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from 8154573 to 79d35df Compare May 2, 2024 08:38
sd2k and others added 2 commits May 16, 2024 11:41
Prior to this commit, `SceneQueryRunner` had special handling for
`SceneTimeRangeCompare` objects, explicitly searching for them in the
scene graph, adding additional queries, and transforming resulting
queries. This made it difficult to re-use the general behaviour of
'running additional queries' in other objects.

This commit introduces a new interface, `SceneRequestAdder`, which
can be implemented to inform the query runner that it should run
additional requests (returned by `getExtraRequests`) and transform the
results in some fashion.

Instead of searching the graph for `SceneTimeRangeCompare` objects,
the query runner searches for implementors of `SceneRequestAdder`
and uses those instead. The specifics of how it searches for these
is a little bit fuzzy and should probably be improved: it walks up the
graph until it finds at least one adder at the current level or in
any children of the current level; adds any others at that level
or in the children; then returns.

`SceneTimeRangeCompare` has been refactored to make use of this new
interface. I've also got a separate object which also implements
it which is working well including when both are enabled.
@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from 79d35df to 4f58dee Compare May 16, 2024 10:41
Not sure these names are much better but they're possibly less ambiguous.
@sd2k sd2k force-pushed the decouple-comparisons-from-queryrunner branch from 4f58dee to 9aa6700 Compare May 16, 2024 10:44
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.

None yet

2 participants