I have seen there are two operate: sort and sort_desc to sort samples.
In this case, I want to sort the logs by Id. How to realize it?
I don’t think what you are looking to do is possible. Hopefully someone more knowledgable can comment.
sort and sort_desc are for metric queries, and they sort by the value
of metric query, not the logs.
what is sort and sort_desc use for?how to use it to sort values?
sort_desc(max_over_time({env= production
} | unwrap cost[1h]
sort(max_over_time({env= production
} | unwrap cost[1h]
this two query return the same result.
Order of value is not represented in a time series graph. You have X-axis as time, and Y-axis as cost, neither of which can be used to represent order.
Can you give me some idea on what you are trying to achieve?
I want to sort labels by cost. for example(I don’t know if I use right)In this case, I want to sort id desc by cost.
sort_desc(max_over_time({env= production
} | unwrap cost[1h])by (id))
Then I think you are doing it right, but your representation needs to change to maybe something like table, so that time is no longer important (you’d aggregate metrics for a certain period of time), and instead you can show ID, cost, and the order (represented by table naturally).
Then again, if you were to use table view you can simply sort it in the table view in Grafana. I’ve never used the sort
function (i think for good reason), because you can in most cases sort them yourself afterwards either using Grafana’s graph or with some sort of simple scripting.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.