Adding new segments/fields to "target"

Hello,

I am trying to add new fields to the target that is sent out as a request from Grafana. This is a part of a custom data source that I have developed based on the SimpleJSON plugin. I am able to get the new values set by the user from the html page all the way to “datasource.js” page, “buildQueryParameters” function, but the execution fails here at this line ( options.targets = _.filter(options.targets, function (target))* with an error that states:

"angular.js:14700 TypeError: Cannot create property ‘targets’ on string ‘inputvalueXXX’ ",**

as a result options.target never gets created and hence the target json is not getting populated with the new values.

This is what I am trying to achieve: (ideal case json request: want to add customfields to target)
image

But I am not able to proceed because of the error. Is there a predefined list of target elements somewhere that I need to change as well to add new segments? Please let me know what I am missing.

Could you’ll please advise how I can add new values to the target variable in this case?
Any pointers to proceed from here would be greatly appreciated.

Many thanks.

Ok, I have proceeded some more into the code and found out how the SimpleJSON plugin works. I have progressed upto the part that when I click something on the Grafana frontend, the “/search” function is triggered, but it never hits the “/query” function. :frowning:

Any help in this space please?

Would be really helpful to know what calls the “/query” function and how I can track my program flow.

Am I right in saying that backendSrv.datasourceRequest function decides whether the flow should proceed all the way to “/query” or not?
return this.backendSrv.datasourceRequest(options);

Could you’ll please let me know where the function datasourceRequest is located and how I debug my input flow?
What is a valid set of “options” it recognizes?

For now try understanding this template I made for easy use. Especially the query_ctrl.js and the datasource.js


I haven’t gotten round to publishing the blog yet but I do have a write up. I’ll try to release it in a day or two

1 Like

@abhinavred
Thank you so much, I will take a deep dive.

@abhinavred Vey useful repo. Helped solve by problem by just going through your code. Thanks a ton! Much appreciated. Look forward to your blog.