Skip to content

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

Closed
@vaibhavinbayarea

Description

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions