-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Draft: add apiVersion to datasource ref #87961
Conversation
Think this is going in the direction I was expecting, but might have been outside the loop recently.
Based on plugin context is expected to have the request api version, https://github.com/grafana/grafana-plugin-sdk-go/blob/36b8fe32821b1740d9fb32a6472287058aee5304/proto/backend.proto#L86, that dictates that all the data queries should use the same api version and hence the datasource ref api version would need to be extracted and put into |
This could be a bit confusing, but the
Because of that, I think plugins should have access to both the |
Yes, its very confusing 😄
Not sure that make sense. Shouldn't the frontend be able to decide which api version to use? In the context of a datasource API server I would expect the version being used when hitting the API will populate the |
Correct, in the future, the api version will be part of the URL (e.g.
As I understand it, it's not the same. For example, the API server may be able to accept multiple version (e.g. |
addQuery(queries, query, { | ||
type: dsSettings?.type, | ||
uid: dsSettings?.uid, | ||
apiVersion: dsSettings?.meta.apiVersion, |
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.
hymm -- I though we were not going to add this to the swagger yet?
I don't think we want that form locked in yet
@@ -16,7 +16,7 @@ import { | |||
* @public | |||
*/ | |||
export function getDataSourceRef(ds: DataSourceInstanceSettings): DataSourceRef { | |||
return { uid: ds.uid, type: ds.type }; | |||
return { uid: ds.uid, type: ds.type, apiVersion: ds.meta?.apiVersion }; |
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.
Hymm -- do we we want to set this automaticly yet? I see two big issues:
- this assumes frontend and backend are in sync
- This does not let the frontend say what apiVersion is is actually supporting
I think this is generally fine with the big exception that I do not think we are ready to have it automatically filled up from the settings. If a frontend sets it that is fine, but lets not depend on See also: grafana/grafana-plugin-sdk-go#991 |
Okay, let's block this until #88041 is solved
The question is where should the frontend get this from if not from the datasource settings? |
IIUC, it is the frontend client that should know what api it is using -- so it would be in the client. |
yes but I mean the client, in this case Grafana UI should get the version from somewhere. Would that be the current value in the |
@andresmgot I think I understand where you're going/how you're thinking. Let me see if this is correctly understood. So when a user selects a datasource to make a query for either explore, alerting or dashboards the datasource ref is supposed to automatically populate the panel datasource prop, right? Is one potential problem for using the datasource ref that the datasource don't have any dynamic way to influence the api version picked besides currently putting it into plugin.json? That's why you suggest putting it in data query instead because the query editor can control such prop? |
Correct.
First of all, I am thinking from the assumption that the final user won't need to care about the My confusion (and correct me if I am wrong here @ryantxu), comes from the fact that an API server directly owns data source configs but also queries. In other words, a specific From that point, what I am questioning is if a query should be tied to an apiVersion because it's using a data source with a certain apiVersion or because it's using a plugin with a certain apiVersion. For the former, imagine a query that is using a datasource "A". At the moment of creating the datasource, the API server is using the version "v0alpha1" (this version is read from the plugin.json). Therefore, when saving the query, it will contain: For the later, the query would store the So in the end, I guess the question is, does an Hope all that long comment makes sense 😞 |
Yes -- though not really a schema -- it points to the server that can answer that query payload. The server can (and eventually should!) have a schema that can help validate the query target.
I think this comment points to the biggest confusion -- every apiVersion that we publish should keep working until we explicitly want to break or stop supporting only APIs. When you publish "v2", something must still be running at "v1" that continues to support the payloads that were valid at that time -- behind the scenes that will likely convert, but it could just be an old version of the service that continues to run. This may help explain why I was so confused by using semantic version for the apiVersion! |
Got it, I think the conversation diverted a bit from the original question. Let's go back a bit. I want to save a query for an API server that is running
Is your concern about the format (e.g. My point is that the client, in this case the Grafana UI, needs to set the apiVersion of the query somewhere and read it before saving from somewhere too. Either it gets it from the data source metadata (and save it in the data source ref) or from the plugin metadata (and stores it in the query model). Or maybe you are thinking on a third option I am not seeing. |
Now I see the key difference:
The client should know what apiVersion it is targeting -- it should not ask something else what its version is and then blindly use it. This is why I am fine if we just remove apiVersion from the (legacy) /api endpoints When introducing new apiVersions, the target will likely want/need to support multiple versions at the same time. |
For queries specifically -- the apiserver will soon publish the query schemas and support validation. I'm happy if the client uses this to know the apiversion |
It seems we are lacking the infrastructure for this yet. If the approach on this PR is not the way forward then I'll close. Please let us know when we can re-evaluate this. |
What is this feature?
Adds the plugin (and data source) apiVersion to a query
DatasourceRef
and inDatasourceSettings
so panels and alerts (among other requests), include a reference to the targetapiVersion
.Query:
Alert:
It's still not clear to me if we should add this field elsewhere for example, in the
DataQuery
object. If theapiVersion
is not in the query, the plugin won't receive this information in the request (req.PluginContext.DatasourceSettings
is populated with the value in storage, not with theDatasourceRef
from the query) so it won't work out of the box for example for running query migrations.TODO:
Why do we need this feature?
We can add now a validation step that checks that for a given query, the datasource referenced matches in apiVersion with that it's stored.
Who is this feature for?
Which issue(s) does this PR fix?:
Fixes #
Special notes for your reviewer:
Please check that: