3
0

Added http method sorting to profiler

This commit is contained in:
Peter Grlica
2022-03-23 09:32:25 +01:00
parent 60a6e597f6
commit a9b6ea6605
2 changed files with 22 additions and 1 deletions
+3 -1
View File
@@ -17,7 +17,7 @@ import (
var (
sortAggFields = []string{"path", "count", "size_min", "size_max", "size_avg", "time_min", "time_max", "time_avg"}
sortRouteFields = []string{"time_start", "time_finish", "time_duration", "content_length", "http_status_code"}
sortRouteFields = []string{"time_start", "time_finish", "time_duration", "content_length", "http_status_code", "http_method"}
)
const (
@@ -336,6 +336,8 @@ func getSortTypeHit(s string, list *types.ApigwProfilerHitSet) sort.Interface {
return types.ByContentLength(*list)
case "http_status_code":
return types.ByStatus(*list)
case "http_method":
return types.ByMethod(*list)
default:
return types.BySTime(*list)
}
+19
View File
@@ -60,6 +60,7 @@ type (
ByDuration ApigwProfilerHitSet
ByContentLength ApigwProfilerHitSet
ByStatus ApigwProfilerHitSet
ByMethod ApigwProfilerHitSet
)
func (h ByPath) Len() int {
@@ -285,3 +286,21 @@ func (h ByStatus) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
return
}
func (h ByMethod) Len() int {
return len(h)
}
func (h ByMethod) Less(i, j int) bool {
// most will have the same status
// so for paging we need a secondary sort
if h[i].Request.Method == h[j].Request.Method {
return h[j].Ts.After(*h[i].Ts)
}
return h[i].Request.Method < h[j].Request.Method
}
func (h ByMethod) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
return
}