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

Improve apiVersion in plugin models #87639

Closed
wants to merge 11 commits into from
Closed

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented May 10, 2024

This is a proposed update to #87510

This updates the settings model so it is more clearly a indication of where the apiserver is running with which versions:
image

It also makes the value optional on individual apis so we don't advertise the value until it is actually saved.

@@ -105,5 +105,6 @@
"url": "https://prometheus.io/"
}
]
}
},
"apiVersion": "v0alpha3"
Copy link
Member Author

Choose a reason for hiding this comment

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

^^^ should be removed before commit!

But note, that this will make the server run on the configured apiVersion 🎉

http://localhost:3000/apis/prometheus.datasource.grafana.app/v0alpha3/namespaces/default/connections/gdev-prometheus

APIVersion string `json:"apiVersion"`

// The apiVersion (and schema) when the datasource was saved
// This value links the JsonData and SecureJsonFields with an explicit version
Copy link
Member Author

Choose a reason for hiding this comment

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

we can remove the comment if it helps 🤷🏻

But I keep getting confused which one indicates where it is running vs where it was saved!

@@ -28,7 +28,7 @@ type PluginSetting struct {
SignatureType plugins.SignatureType `json:"signatureType"`
SignatureOrg string `json:"signatureOrg"`
AngularDetected bool `json:"angularDetected"`
APIVersion string `json:"apiVersion"`
Copy link
Member Author

Choose a reason for hiding this comment

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

alternatively we could use the group+version flavor, but I find it super confusing that k8s mixes the use of these eg:

apiVersion = "v0alpha1"
or
apiVersion = "prometheus.datasource.grafana.app/v0alpha"

sadly k8s uses both all over the place 🤒

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this yet? I guess that the idea here is that the frontend would get this api server config and start querying the datasource in the new URL, right? (/apis/<api_group>/<api_version>/namespaces/stack/connections/<ds_UID>/query vs /api/ds/query).

Since we already have the /apis endpoint, which returns similar information coming from the k8s tooling, do we need to modify this for the "legacy" endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively we could remove/hide it entirely entirely for now. "apiVersion" without the group is a bit awkward in this api call.

By adding APIServerInfo we add enough info to point to everything required for:
`/apis/<api_group>/<api_version>/namespaces//connections/<ds_UID>/query

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we could remove/hide it entirely entirely for now. "apiVersion" without the group is a bit awkward in this api call.

I think it's still useful to have just the apiVersion, for example to store it in datasource settings and dashboards.

By adding APIServerInfo we add enough info to point to everything required for:
`/apis/<api_group>/<api_version>/namespaces//connections/<ds_UID>/query

Yes, but I don't know if this is the best place to have it (also because it's a bit hardcoded). I think a better workflow would be for the frontend to have a map between pluginID -> DS server (e.g. prometheus: prometheus-url:6443) and then obtain the apiVersions and groups with a request to the DS server (prometheus-url:6443/apis). Isn't that closer to a native workflow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure the best strategy to get from where we are to where we need to be -- long term, the plugins settings will not be there. It will be a resource managed in an apiserver saying what is available.

My concern with setting a single apiversion -- is mainly that people will start to think that is true and depend on it. The frontend needs to know what apiVersion it is able to talk to if it wants to use the preferredVersion that is fine, we just want to make sure the pattern is clear that a datasource/app can have many versions and the client must know who they are talking to

@@ -224,7 +227,9 @@ func (b *DataSourceAPIBuilder) getPluginContext(ctx context.Context, uid string)
if err != nil {
return backend.PluginContext{}, err
}
return b.contextProvider.PluginContextForDataSource(ctx, instance)
pctx, err := b.contextProvider.PluginContextForDataSource(ctx, instance)
pctx.APIVersion = b.connectionResourceInfo.APIVersion()
Copy link
Member Author

Choose a reason for hiding this comment

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

^^^ this is the interesting part

This tells the backend what apiversion was requested.

NOTE: pctx.DataSourceInstanceSettings.APIVersion may be different! it should be the version when the datasource settings were saved

Base automatically changed from pluginApiVersion to main May 14, 2024 11:58
@andresmgot
Copy link
Contributor

hi @ryantxu, do you want to move forward with this? I want to work on the frontend part of this apiVersion setting so we need to agree on what we want to set. cc/ @marefr

@ryantxu
Copy link
Member Author

ryantxu commented May 15, 2024

I want to work on the frontend part

what is the frontend part? IIUC, nothign in the the existing /api should change -- only if we are talking to /apis/...

@ryantxu
Copy link
Member Author

ryantxu commented May 20, 2024

Closing and replacing with #88041

@ryantxu ryantxu closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants