ryantxu / ajax-panel

Ajax Panel Plugin for Grafana
MIT License
153 stars 154 forks source link

Header does not parse unescaped dashboard variables #62

Open ChristopherBull opened 4 years ago

ChristopherBull commented 4 years ago

I have a dashboard variable which I refer to in the 'Headers' field: {Authorization: "api-key $apiKey"}

But Chrome Inspector shows it passing the variable as a string, instead of parsing the value of the variable. Chrome outputs: authorization | api-key $apiKey

I expect it to parse the variable, i.e: authorization | api-key the-value-of-my-variable

I can see the variable exists and has the correct value (as you have handily shown a list of variables in the panel edit page).

Variables are correctly parsed for the URL. So looks as if it is specific to parsing the header.

Would be good if there was a preview of the header too.

Grafana version: 6.7.2 AJAX Panel version: 0.0.6 (latest)

ChristopherBull commented 4 years ago

I managed to get my instance working by using: {Authorization: 'api-key ' + ctrl.template('$apiKey')}

I was lead to believe that unescaped dashboard variables could be parsed within a string, as I can see an example of that in the screenshot images in your README file.

ChristopherBull commented 4 years ago

My previous work-around no longer works with the latest versions of Grafana.

I have a varable in a template called apiKey with a template value of REPLACE-WITH-KEY. I update the variable in the Grafana web UI with an API key (it is still there after refreshing). But when I look at Chrome's inspection view, the AJAX panel is sending REPLACE-WITH-KEY instead of the updated private API key. Presumably because it is getting the template variable value instead of the updated actual variable value.

I do not know how to get the variable value as I cannot find the documentation for ctrl. Please send help.

Grafana version: 7.0.6 AJAX Panel version: 0.0.7-dev

ChristopherBull commented 4 years ago

This appears to be a joint problem with Grafana and this plugin:

  1. Grafana appears to have an issue whereby variables are not saved/loaded correctly, for example: https://github.com/grafana/grafana/issues/20600
  2. This plugin does not update the visualisation of the contents for subsequent requests. I have observed several HTTP 401 (unauthorised) errors when my API key could not be read from its variable and the correct associated error was shown in this plugin's panel-as expected (except for Grafana apparently being unable to read the variable). However, with Some Magic™ (examples in the Grafana issue cited above), I managed to get the panel to read the correct value, send the request, and receive a HTTP 200 (OK) request, but this plugin ignored it and did not replace the previous error message in the visualisation. What if there was a server 5xx error request during dashboard load and subsequent requests work? Only the error message would get displayed, as the contents of the panel do not appear to update for subsequent requests.