How does grafana decode Redis CLI query?

Hi,

When I do a CLI query to Redis from within Grafana (this is supported by the Redis datasource) with the following code that I insert with a Text/HTML panel…

<p id="value"></p>

<button onclick="get_value_from_Redis()">Get value</button>

<script>
function get_value_from_Redis(){
  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", "/api/ds/query", false);
  xhttp.setRequestHeader("Content-type", "application/json");
  xhttp.send(JSON.stringify({"queries":[{"refId":"A","type":"cli","query":"lrange test 0 0","datasource":"Redis","datasourceId":1}]}));
  var response = JSON.parse(xhttp.responseText);
  document.getElementById("value").innerHTML = JSON.stringify(response);
}
</script>

… I get the following response from the api:

{"results":{"A":{"refId":"A","series":null,"tables":null,"dataframes":["QVJST1cxAAD/////AAEAABAAAAAAAAoADgAMAAsABAAKAAAAFAAAAAAAAAEEAAoADAAAAAgABAAKAAAACAAAAFAAAAACAAAAKAAAAAQAAACE////CAAAAAwAAAABAAAAQQAAAAUAAAByZWZJZAAAAKT///8IAAAADAAAAAAAAAAAAAAABAAAAG5hbWUAAAAAAQAAABgAAAAAABIAGAAUAAAAEwAMAAAACAAEABIAAAAUAAAARAAAAEgAAAAAAAAFRAAAAAEAAAAMAAAACAAMAAgABAAIAAAACAAAABAAAAAFAAAAVmFsdWUAAAAEAAAAbmFtZQAAAAAAAAAABAAEAAQAAAAFAAAAVmFsdWUAAAD/////mAAAABQAAAAAAAAADAAWABQAEwAMAAQADAAAABAAAAAAAAAAFAAAAAAAAAMEAAoAGAAMAAgABAAKAAAAFAAAAEgAAAABAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAAAAAAAAUAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAUAAABoZWxsbwAAABAAAAAMABQAEgAMAAgABAAMAAAAEAAAACwAAAA8AAAAAAAEAAEAAAAQAQAAAAAAAKAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoADAAAAAgABAAKAAAACAAAAFAAAAACAAAAKAAAAAQAAACE////CAAAAAwAAAABAAAAQQAAAAUAAAByZWZJZAAAAKT///8IAAAADAAAAAAAAAAAAAAABAAAAG5hbWUAAAAAAQAAABgAAAAAABIAGAAUAAAAEwAMAAAACAAEABIAAAAUAAAARAAAAEgAAAAAAAAFRAAAAAEAAAAMAAAACAAMAAgABAAIAAAACAAAABAAAAAFAAAAVmFsdWUAAAAEAAAAbmFtZQAAAAAAAAAABAAEAAQAAAAFAAAAVmFsdWUAAAAwAQAAQVJST1cx"]}}}

What I am trying to get out of Redis this way is simply the string “hello” that I did put in to Redis beforehand. I’d expect kind of the same result as executing this query with Grafana’s Explore tool as shown in this picture:

So appearantly the ‘dataframe’ that is sent back by the api is encoded in some way. Trying to decode this using “atob(response.results.A.dataframes)” (it looks like it is encoded as someting like base64?) results in the following:

ARROW1ÿÿÿÿ    P(„ÿÿÿArefId¤ÿÿÿnameDHDValuenameValueÿÿÿÿ˜  Hhello,<�   P(„ÿÿÿArefId¤ÿÿÿnameDHDValuenameValue0ARROW1

which still looks scrambled, though the phrase “hello” I am looking for actually seems to be embedded in this response. Now my question is if anyone knows how Grafana is able to decode this ‘dataframe’ response as shown in the image above. I’m pretty sure this is happening in the browser as the F12 screen in Google Chrome shows that the browser is also receiving the dataframe in this encoded way as the result shown above.

Just to put this question into context, I’m using the Text panel to show a control panel with input fields and buttons in Grafana, and I would like to use the little script as shown above to get the previous set values of this panel to ‘preload’ the input fields on page load.

I am using Grafana v7.5.7 (91de51771c) @ Raspberry Pi 3 B+ (Raspbian Buster) using the official Grafana docker container with docker-compose

Thanks in advance !

Ok, so I found out it has to do with something called “Apache Arrow” data format. If anyone is more familiar with this I’d love to hear about it!

It seems I’m pretty much the only one dealing with this, but if anyone else ever runs into this as well, the best solution is to update to Grafana 8 as in this version the response to the browser is no longer encoded as seen in the original post :+1:

EDIT:
The little piece of HTML (deployed in a ‘Text box’ (don’t forget to set disable_sanitize_html to true)) would then be:

<style>p { word-break: break-all }</style>
<p id="value"></p>
<button onclick="get_value_from_Redis()">Get value</button>
<script>
function get_value_from_Redis(){
  var xhttp = new XMLHttpRequest();
  xhttp.open("POST", "/api/ds/query", false);
  xhttp.setRequestHeader("Content-type", "application/json");
  xhttp.send(JSON.stringify({"queries":[{"refId":"A","type":"cli","query":"lrange test 0 0","datasource":"Redis","datasourceId":1}]}));
  var response = JSON.parse(xhttp.responseText);
  //document.getElementById("value").innerHTML = JSON.stringify(response);
  document.getElementById("value").innerHTML = response.results.A.frames[0].data.values[0][0];
}
</script>

This topic was automatically closed after 365 days. New replies are no longer allowed.