Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loggingapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func TestBasicCall(t *testing.T) {
}

if len(logs.GetLogs()) != 2 {
t.Errorf("bad number of logs: %v", logs)
t.Errorf("bad number of logs: (%v) %v", len(logs.GetLogs()), logs)
}
}
15 changes: 14 additions & 1 deletion loggingutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -55,7 +56,19 @@ func (s *Server) loadAllLogs(ctx context.Context, origin string) ([]*pb.Log, err
return nil
})

return logs, err
sort.SliceStable(logs, func(i, j int) bool {
return logs[i].GetTimestamp() < logs[j].GetTimestamp()
})

// Only return 20 logs
return logs[0:min(20, len(logs))], err
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func (s *Server) loadLogs(ctx context.Context, origin string, timestamp int64) ([]*pb.Log, error) {
Expand Down
6 changes: 6 additions & 0 deletions loggingutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ func TestBadFullLoad(t *testing.T) {
}

}

func TestMin(t *testing.T) {
if min(1, 10) != 1 || min(10, 1) != 1 {
t.Errorf("Min is wrong")
}
}