Need to display Timeseries Panel with Infinity Plugin

Hello,

I am using inifinity-datasource where I am calling the Elasticsearch with some query and getting some result like below, I need to visualize this result using Timeseries panel (specially the key_as_string and value) but I am getting a message like “Data is missing a time field”,

Can anyone please help me on this ?

[{
        "key_as_string" : "2024-01-14",
        "key" : 1705170400000,
        "doc_count" : 10,
        "average_of_age" : {
          "value" : 13.86
        }
}]

Hi @laksh009

Something like this?

First thing I did was create some dummy data based on your template in order to get some different values that could be plotted over time. I created 3 different values with 3 different dates (3-14, 3-15 3-16):

[{
        "key_as_string" : "2024-03-14",
        "key" : 1705170400000,
        "doc_count" : 10,
        "average_of_age" : {
          "value" : 17.33
        }
},
{
        "key_as_string" : "2024-03-15",
        "key" : 1705170400000,
        "doc_count" : 11,
        "average_of_age" : {
          "value" : 12.86
        }
},
{
        "key_as_string" : "2024-03-16",
        "key" : 1705170400000,
        "doc_count" : 9,
        "average_of_age" : {
          "value" : 26.86
        }
}]

In the Infinity data source, remember to select Time Series.

I used the following UQL commands:

parse-json
| project "key_as_string", "average_of_age.value"
| extend "value"="average_of_age.value"
| extend "date"=todatetime("key_as_string")
| project-away "key_as_string", "average_of_age"

which does the following:

  • parse-json is the command to instruct the UQL to parse the response as JSON
  • project command is used to select the columns to include in the results. To select a property inside a nested object, I used dot notation (average_of_age.value).
  • extend command is similar to project but instead of selecting the columns, it adds/replaces columns in existing data and I also used the todatetime function to convert key_as_string so that it can be interpreted by Grafana as a date/time field.
  • project-away command is exactly opposite as project . It drops specific columns from the data. It doesn’t support alias or dot notation selector.
2 Likes

Thankyou so much for your update, I will be trying this solution and will let you know.

Hi,

Since you are using the INFINITY datasource and your data is already in JSON format then I suggest you just use the JSON option as is.

As you do not have many levels of nested data just use the Columns selector to select whatever JSON data you require as shown below

Now as you can see key_as_string is in string format and you want to transform into datetime to be able to use the Timeseries chart panel.

One may then use the Transform data option Convert field type as shown below to convert from string to time.

And it is done. Select Times Series as the visualization option and you get

I have added this as although UQL is indeed very powerful it takes a lot of getting used to and sweat if you are not a dedicated programmer.

What many do not realise is that one may traverse the nested levels using the . operator.

In your case all data bar the value is not nested.

One may access it using average_of_age.value

Also when using UQL if time data is not correctly formatted then using the Time Series Chart it will throw errors until time is correctly formatted so it is best to start with using a Table Panel.

Anyway hope this helps a little

2 Likes