Grafana did not display the records in the expected order in table

I created a table on grafana, and the metrics for the table is as below,
sort_desc(avg(my_test_count) by (tenantid))

I expect that the records should be displayed in decending order based on the metrics value, but actually it isn’t the case. Note that the data displayed in table is correct, but the order isn’t expected.

I verified the query on prometheus GUI, and it worked well.

Is it a bug of grafana?

Some related information is as below,
prometheus version: v2.0.0
grafana version: v4.6.2
OS: Oracle Linux 7.3

Hi,

Please note that you can sort a table on the client as well. So make sure that you sort the metrcis value in client descending.

Please let me know if this works

Marcus

Yes, I can sort the table on clicking the column header. But I would like to all records to be displayed in descending order by default.

Please try and remove all the client side sorting by clicking on the column header until there are no ascending/descending arrow displayed. If your data is properly ordered from the query it should sort by that I think.

To verify that the data returned are sorted according to your assumption, please have a look at the query inspector and include data/screenshot of the response here.

Thanks

Marcus

Yes, I just tried, and the data returned by prometheus are sorted in descending order, the response is as below,
{
“status”: “success”,
“data”: {
“resultType”: “vector”,
“result”: [
{
“metric”: {
“tenantid”: “4634a772-5d8d-4063-ad4f-6a1173593fd5”
},
“value”: [
1514546062,
“4”
]
},
{
“metric”: {
“tenantid”: “ee472784-a555-4afb-80ff-ee80ef6577c8”
},
“value”: [
1514546062,
“3”
]
}
]
}
}

1 Like

But In grafana table, the record with value 4 isn’t the first row, instead, it’s the second rows.

I noticed an interesting thing, the data displayed in grafana table are indeed in descending order in editing mode, please see the folloowing screen shot,

But the order changed once I closed the editing window.

Please see the following screen shot,

Okay. It could be that it by default are looking for the time property and sorting by that.

Please note that you can sort a table on the client as well. So make sure that you sort the metrcis value in client descending.

When you done this, then save your dashboard. Next time you visit it, the sort should be persisted.

If this not is working out for you, please show me a screenshot of your metrics tab, options tab and column styles tab.

Marcus

Yes, it worked per your suggestion, although it isn’t perfect. Thanks.

Actually I raised an issue a couple of days before as below for grafana to request two level sorting. Firstly sorting the records via time, and then sorting by the functions included in query statement,
https://github.com/grafana/grafana/issues/10208

The other option would not to sort the records by time at all if the time column is hidden. Actually I checked the “Instant” option for the table, and hid the time column, which means that I don’t care the time at all, so it makes no sense to sort the data via time.

Okay :+1:

Maybe you can create a separate issue for this. That’s a minor thing and doesn’t involve prometheus which should make it possible for someone to contribute. Your also welcome to contribute a pull request if you want/can. That would be super appreciated.

Marcus

Just raised an issue as below,

1 Like