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

Query conversion handler #1078

Merged
merged 9 commits into from
Sep 17, 2024
Merged

Query conversion handler #1078

merged 9 commits into from
Sep 17, 2024

Conversation

andresmgot
Copy link
Contributor

@andresmgot andresmgot commented Sep 9, 2024

What this PR does / why we need it:

Adds a wrapper around the ConversionHandler for the specific case of queries. That way if a plugin implements a ConvertQuery, the SDK will automatically translate ConversionHandler requests back and forth and migrate queries.

This is a rework of #1071 but in this case, the ConvertQuery function is not explicitly called in the QueryData flow, so the plugin needs to manually call the ConvertQuery function on their QueryData where they see fit.

WIP usage in Grafana as an api server: https://github.com/grafana/grafana/pull/92909/files

See an example usage at grafana/grafana-plugin-examples#340

Which issue(s) this PR fixes:

First part of grafana/grafana#92749

Special notes for your reviewer:


type QueryConversionResponse struct {
// Converted query. It should extend v0alpha1.Query
Query any `json:"query"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I had to use a explicit any here rather than make this a generic struct (type QueryConversionResponse[T any] struct) because either the generic conversion bubbles up until the Manage function and therefore becomes a breaking change, or the type is specifically set to any in any of the intermediate structs but then the plugin needs to explicitly use also any on its implementation, making the use of generics unnecessary.

Let me know if I am missing something here.

backend/query_conversion.go Outdated Show resolved Hide resolved
backend/query_conversion.go Outdated Show resolved Hide resolved
@andresmgot
Copy link
Contributor Author

@ryantxu I believe I have addressed your comments, please take a look again!

@andresmgot andresmgot requested a review from ryantxu September 13, 2024 10:30
@andresmgot andresmgot marked this pull request as ready for review September 13, 2024 14:15
@andresmgot andresmgot requested a review from a team as a code owner September 13, 2024 14:15
@andresmgot andresmgot requested review from wbrowne, oshirohugo and xnyo and removed request for a team and oshirohugo September 13, 2024 14:15
@andresmgot andresmgot assigned marefr and unassigned marefr Sep 13, 2024
@andresmgot andresmgot requested a review from marefr September 13, 2024 14:16
@andresmgot
Copy link
Contributor Author

okay, this should now be ready for a final review 👍

Copy link
Member

@wbrowne wbrowne left a comment

Choose a reason for hiding this comment

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

LGTM! Awesome work on this.


"github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2"
)

type conversionSDKAdapter struct {
handler ConversionHandler
handler ConversionHandler
queryConversionHandler QueryConversionHandler
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would be good to document/note that this is optional (just for the sake of knowing not to skip nil checks if anyone is going to change any code here)

@andresmgot andresmgot merged commit 97a7441 into main Sep 17, 2024
3 checks passed
@andresmgot andresmgot deleted the queryConversionHandler branch September 17, 2024 09:05
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.

4 participants