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:
Mara Sophie Grosch
2021-05-20 07:55:36 +05:30
committed by GitHub
co-authored by Vishal
parent d7ac0ee17a
commit 3bac1d2d9d
2 changed files with 22 additions and 0 deletions
+3
View File
@@ -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
}
+19
View File
@@ -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: