-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add QueryConversionHandler #1071
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// QueryConversionHandler is an EXPERIMENTAL service that allows converting queries between versions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on this should it live in an experimental package? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be but I am just following the same approach than the other new handlers. |
||
|
||
type QueryConversionHandler interface { | ||
// ConvertQuery is called to covert queries between different versions | ||
ConvertQuery(context.Context, *QueryConversionRequest) (*QueryConversionResponse, error) | ||
} | ||
|
||
type ConvertQueryFunc func(context.Context, *QueryConversionRequest) (*QueryConversionResponse, error) | ||
|
||
// ConvertQuery calls fn(ctx, req). | ||
func (fn ConvertQueryFunc) ConvertQuery(ctx context.Context, req *QueryConversionRequest) (*QueryConversionResponse, error) { | ||
return fn(ctx, req) | ||
} | ||
|
||
// QueryConversionRequest supports converting a query from on version to another | ||
type QueryConversionRequest struct { | ||
// NOTE: this may not include app or datasource instance settings depending on the request | ||
marefr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PluginContext PluginContext `json:"pluginContext,omitempty"` | ||
// Queries to convert. This contains the full metadata envelope. | ||
Queries []DataQuery `json:"objects,omitempty"` | ||
} | ||
|
||
type QueryConversionResponse struct { | ||
// Converted queries. | ||
Queries []DataQuery `json:"objects,omitempty"` | ||
} |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the example, https://github.com/grafana/grafana-plugin-examples/pull/340/files#diff-e608edd147405086920bcb097aae449ffb1ca927fea2ab583e93e9bde6b6ee93, this looks a bit costly resource wise to always call it if implemented. You would have to parse the JSON to figure out if it should be converted/migrated. Then after handling the query data in plugin you would have to parse the JSON again. Not optimal, but maybe not a big deal?
But from plugin development perspective I'm not sure how this helps me compared to having some conversion/migration happening within QueryData that you could do already today without these changes.
It feels like this could be useful if the SDK would handle everything related to figure out if conversion is needed using API version, plugin version or some version/incremented value. Maybe I've been out of the loop lately and missed where we're headed with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the goal here was to avoid people having to manually call the migrate function but that comes with the cost of the extra marshalling-unmarshalling. I am going to refactor it so people will need to call it manually.