JSON datasource search request/response

Hello
I intend to develop a Grafana datasource that will provide content for the Table panel and I started a POC based upon the Simple JSON datasource. This POC is functional currently but I do not understand completely how I should build a query with the /search method.

The datasource /search method receives a ‘target’ parameter but this parameter is always empty whatever the content of the Metrics tab of the Table panel. I hoped that I would be able to search target and sub targets like it is possible with the Graphite datasource :slight_smile:

Is there any solution to this problem ?

Thanks in advance

Hello
Is there any one that may have a little look to this problem. I am really stuck on this since a while … many thanks in advance

Best regards, Fred

I’ve had this open in a tab for the last week but was at a conference.

From the docs:

/search used by the find metric options on the query tab in panels.

The /search route is used by the query editor to get metric suggestions and for template variable queries. Not for queries.

The /query route is the one that should return the main query results and it is this target parameter that will have a value:

Thanks @daniellee for this answer.

You are showing an example with the Graph panel whereas my problem is when using the Table panel. Is it something related to the Table panel that does not allow to build a segmented query like the Graph panel does ?

With some pictures and explanations:

I add a table query and then select the hosts proposed in the list that is returned by my /search. The /query is then executed correctly and it returns the expected data. Then I would like to select a next segment to select hosts.unix to have a more precise query.

There is only one query field, the “target” field. Doesn’t make any difference if it is the graph or table panel (unless I am not understanding something here).

If you want to add more segments/fields, then it is time to fork the repo and start creating your own plugin. The SimpleJSON data source is meant to be very simple.

To make it work without starting to build your own plugin, you would need to write hosts.unix in the field. So your /search route could return both hosts and hosts.unix or the user could just type hosts.unix in the dropdown field - it allows custom values that are not contained in the list of options.

I still created my own datasource plugin which is connected to my application backend.

What I do not understand is that there is only one post on the /search route of my plugin. What should I return back from /search to make the panel propose a new segment ? Like the Graph panel does when one is browsing the Graphite metrics ?

Perhaps the /search route is not the correct one to use … it seems that the Graph panel is posting on /metrics/find/?query=* … should I try with this method ?

To build a query editor like the Graphite query editor is a lot of code. It is is not “simple” like the Simple JSON data source unfortunately. To build a query chain like that will take some programming (it probably doesn’t need to be as advanced as the Graphite query editor). There are lots of examples. Check out the list of data source plugins on grafana.com and try and find one that is similar to yours.

The app dynamics data source might be similar to yours:

It is easier if it is not dynamic and you can just have multiple dropdowns instead (e.g. an OS dropdown with unix and windows options) .

Thanks for your answers to my question and for the hints … I will try to improve my datasource.

Best regards