From a9b6ea66053454867193c421f59adadf255f1c29 Mon Sep 17 00:00:00 2001 From: Peter Grlica Date: Wed, 23 Mar 2022 09:32:25 +0100 Subject: [PATCH] Added http method sorting to profiler --- system/service/apigw_profiler.go | 4 +++- system/types/apigw_profiler.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/system/service/apigw_profiler.go b/system/service/apigw_profiler.go index a7634a4ec..4e85da64c 100644 --- a/system/service/apigw_profiler.go +++ b/system/service/apigw_profiler.go @@ -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) } diff --git a/system/types/apigw_profiler.go b/system/types/apigw_profiler.go index fe04f9b41..6797f5641 100644 --- a/system/types/apigw_profiler.go +++ b/system/types/apigw_profiler.go @@ -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 +}