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
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.
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”
]
}
]
}
}
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,
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.
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.