Dynamic Text Panel: How to get current Data Source

Hello,

I am a beginner and starting to use grafana.
I tried to get the solution for myself but I need some help.

Grafana Version: 10.1.2
Dynamic Text Panel plugin Version: 4.2.0

I added a Dynamic Text Panel to my Dashboard.
I selected a mysql data source for the initial query.
I added a button to the panel.
When pushing the button an update against the mysql datasource is performed.
I implemented this with a POST request against ../api/ds/query either with:
dataset: "<myDataSourceName>", datasource: { type: "mysql", uid: "<myUserId>" },
or with:
datasourceId: <myDataSourceId>,

Both works fine.

I also found out how to get the datasource ID by Name via API:
GET request against /api/datasources/id/<myDataSourceName>

This also works fine.

But I was not able to get the currently used datasource (name or ID) via Java Script
(Editor: After Content Ready).
I searched in Parameter context, but could not find anything.

I there a way to get the currently used data source via Java Script?
Should I add a (hidden) dashboard variable of type Data Source as workaround?
My current workaround is:

  1. Select the current database select database(); in the mysql query.
  2. Get the data source ID via API GET request.

Any help is appreciated!

1 Like

@rniebsch We don’t expose Data Source and data frames directly in the context.

Have you looked at the Data Manipulation panel? It works with Data Source directly and will allow to read and update data.

Hidden dashboard variable will work for Dynamic Text.

Hi Mikhail,

thanks for your quick response!
Yes, I first tried your awesome Data Manipulation panel.
Unfortunately I was not as free as I wanted in customizing style/validation for my form elements
(nice to have not need to have: I see that you work hard on this).

More severe is the problem that I could not fade-out the changes caused by a dashboard refresh:

I first tried option Initial Request-> Data Source but I was not successful.

Then I read your advice regarding Initial Request -> Custom Code
I tried this option too, but this worked only partial.
(i.e. I did not really understand when initial is set resp. flushed
and why Initial Request is called twice in case of a dashboard refresh)
And with option Initial Request -> Custom Code I assue that I have
again the problem that I need the datasource ID/Name?

What is the reason why you don’t expose the Name of the current Data Source?

Thanks for your good work.
I really appreciate your plugins.

@rniebsch Interesting, It’s not clear why Data Source was not working. It’s maybe something we need to fix or update in the Documentation.

Regarding Dynamic Text, it was developed to expose data only containing data for easy to use, not the data frames as is. In the latest versions we introduced JS and it makes sense to provide access to data frames as is for advanced use cases.

Please open an issue in the GitHub repository and will look into adding it.

1 Like