Fix log sort order when multiple series are returned (#1956)
Series are sorted internal by "order by", but the set of all series returned is not. Tried some ways to sort completely on database, found no way .. client side sort works at least Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
co-authored by
Vishal
parent
d7ac0ee17a
commit
3bac1d2d9d
@@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -130,6 +131,8 @@ func (influx InfluxDB) GetLogs(filter LogFilter) ([]LogEntry, error) {
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(ByTimestamp(logEntries, filter.Reverse))
|
||||
|
||||
return logEntries, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,25 @@ type LogEntry struct {
|
||||
Pod string
|
||||
}
|
||||
|
||||
type ByTimestampSort struct {
|
||||
entries []LogEntry
|
||||
desc bool
|
||||
}
|
||||
|
||||
func (a ByTimestampSort) Len() int { return len(a.entries) }
|
||||
func (a ByTimestampSort) Swap(i, j int) { a.entries[i], a.entries[j] = a.entries[j], a.entries[i] }
|
||||
func (a ByTimestampSort) Less(i, j int) bool {
|
||||
if a.desc {
|
||||
return a.entries[i].Timestamp.UnixNano() > a.entries[j].Timestamp.UnixNano()
|
||||
} else {
|
||||
return a.entries[i].Timestamp.UnixNano() < a.entries[j].Timestamp.UnixNano()
|
||||
}
|
||||
}
|
||||
|
||||
func ByTimestamp(entries []LogEntry, desc bool) ByTimestampSort {
|
||||
return ByTimestampSort{entries, desc}
|
||||
}
|
||||
|
||||
func GetLogDB(dbType string, serverURL string) (LogDatabase, error) {
|
||||
switch dbType {
|
||||
case INFLUXDB:
|
||||
|
||||
Reference in New Issue
Block a user