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

[Bug] Templating - json parse fails when using another template variable in query #5615

Closed
vaibhavinbayarea opened this issue Jul 20, 2016 · 7 comments
Labels
Milestone

Comments

@vaibhavinbayarea
Copy link
Contributor

Please include this information:

  • What Grafana version are you using?
    Version 3.1.0 (commit: v3.1.0)
  • What datasource are you using?
    Elasticsearch
  • What OS are you running grafana on?
    Ubuntu 14.04
  • What did you do?
    When building a template with query that uses another template variable, often times json parse fails because of escaping of special characters.

My query looks like:
{"find": "terms", "field": "storageInstances.lunInstances.name", "query":"storageInstances.name:$Storage_instances"}

Where for example, the $Storage_instances = "cent7-pbs-client-app__ST__storage-1"

According to chrome console, the query being json parsed is:

a = "{"find": "terms", "field": "storageInstances.lunInstances.name", "query":"storageInstances.name:cent7\-pbs\-client\-app__ST__storage\-1"}"

The stack trace shows:

boot.8ba215a1.js:formatted:41332 SyntaxError: Unexpected number in JSON at position 102
    at Object.parse (native)
    at Object.X [as fromJson] (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:34:21196)
    at h.metricFindQuery (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:13:25614)
    at updateOptionsFromMetricFindQuery (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:10:29774)
    at b (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:41:20151)
    at h (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:36:18232)
    at http://127.0.0.1:3200/public/app/boot.8ba215a1.js:36:18404
    at n.$eval (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:36:25921)
    at n.$digest (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:36:24429)
    at n.$apply (http://127.0.0.1:3200/public/app/boot.8ba215a1.js:36:26204)

If I use json formatter on the above query, it complains of an invalid character when "-" is escaped.

  • What was the expected result?
    I believe the template should handle escaping of template variables according to json standards.

screen shot 2016-07-19 at 6 02 09 pm

@vaibhavinbayarea
Copy link
Contributor Author

For completeness,

When I remove the $Storage_instance variable and hard-code a name, the lookup works with the following

a = "{"find": "terms", "field": "storageInstances.lunInstances.name", "query":"storageInstances.name:cent7-pbs-client-app__ST__storage-1"}"

@klyngbaek
Copy link

+1

@vaibhavinbayarea
Copy link
Contributor Author

So this seems to be working fine with top of the tree. I guess it got fixed sometime recently. Confirmation would be nice.

./bin/grafana-server -v
Version 4.0.0-pre1 (commit: v3.1.0+113-g3f861dd)

@torkelo
Copy link
Member

torkelo commented Jul 21, 2016

maybe it was fixed by this commit?
8bd6b95

@torkelo torkelo added this to the 3.1.1 milestone Jul 21, 2016
@torkelo
Copy link
Member

torkelo commented Jul 21, 2016

can try to cherry pick that to 3.1.x branch and have it included in next patch release

@torkelo
Copy link
Member

torkelo commented Jul 23, 2016

this is now in 3.1.x branch, will be included in next patch.

@torkelo torkelo closed this as completed Jul 23, 2016
@vaibhavinbayarea
Copy link
Contributor Author

Sorry for the late reply.. I did try the patch it and it works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants