Sensetif / sensetif-app-plugin

The Grafana Application Plugin for the Sensetif platform.
Apache License 2.0
0 stars 0 forks source link

Implement Grafana Variables #48

Closed niclash closed 11 months ago

niclash commented 2 years ago

It seems that backend datasources need to actively support "Variables" for me to be able to create "Panel Templates" that can be reused in many systems.

See;

Currently no idea how this is supposed to work. Where are the "options" coming from? The sample seems to relate to the "normal" datasources, where the querying is happening on the front end and the query sent to a proxy on the backend. In our case, we have a "backend" datasource, and it seems to work very differently, and the write-up about those doesn't mention "Variables"; https://grafana.com/docs/grafana/latest/developers/plugins/backend/

niclash commented 2 years ago

@grzegorekb Do you have any clue how this should be done? You want to do it?

grzegorekb commented 2 years ago

Have no idea yet. I will check on that.

grzegorekb commented 2 years ago

Actually now, as I'm thinking about it, I don't understand the use case. Can you explain why you need that? Why is evaluation of the variables on the frontend side, not enough? You can still create templated panels with that I think, right?

niclash commented 2 years ago

I guess I don't understand how it is supposed to work.

  1. I need to change that the Query Editor's drop down boxes also allow for arbitrary text editing, otherwise the Variables can't be used.
  2. How can the Query Editor get hold of which variables are available to assist the user?
  3. Will Core Grafana be involved in modifying the Query content before it is sent to the backend, replacing variables with the values?
grzegorekb commented 2 years ago

Are we talking about Grafana's dashboard variables?

Is this the thing we want to achieve? I've defined some variable called default_project (it has some values from whatever source). Then we want to use that variable as project in the query just like in the screenshot, right? image

grzegorekb commented 2 years ago

If that's the case, I think it only requires some changes to the frontend part of the datasource (query editor, and datasource.ts file). Currently, our datasource.ts is the simplest it can be <- it does nothing. Usually, this is the place where variable evaluation happens. After that, the proper request is passed to the actual server, eg. elasticsearch/sql, whatever. In our case, we need to evaluate variables before they will be passed to the backend part of our datasource plugin.

niclash commented 2 years ago

Yes, that is what I am talking about...

niclash commented 2 years ago

We don't have a datasource.ts

grzegorekb commented 2 years ago

https://github.com/Sensetif/sensetif-datasource-plugin/blob/main/src/datasource.ts It implements DataSourceWithBackend that comes from Grafana packages. Our impl is empty.

grzegorekb commented 2 years ago

Maybe it will work out of the box when we allow to input any text into our selectors for project/subsystem/datapoint. I will check on that.

niclash commented 2 years ago

Sorry, I was looking in wrong repository

niclash commented 2 years ago

Would be great if you could take care of it!

Usecase; Not only should it be possible to replace the entire field (say Project) with a variable, but it still needs text replacement, for instance; "fvc1.rad.${regulator}.algorithm"

grzegorekb commented 2 years ago

If I only manage to switch between ssh keys for different github accounts, I will push the first version today..

grzegorekb commented 2 years ago

https://github.com/Sensetif/sensetif-datasource-plugin/pull/2/files

grzegorekb commented 2 years ago

@niclash can we close this one?