From 708889d55809b87e5c807906206846762374586f Mon Sep 17 00:00:00 2001 From: Fabian Bees Date: Fri, 21 Feb 2025 09:27:00 +0100 Subject: [PATCH] feat/console: option to sort by last column --- console/config.go | 2 +- console/data/docs/03-usage.md | 2 ++ console/frontend/src/components/InputDimensions.vue | 1 + console/graph.go | 2 +- console/line.go | 7 +++++++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/console/config.go b/console/config.go index 60d30823..24b69594 100644 --- a/console/config.go +++ b/console/config.go @@ -70,7 +70,7 @@ type VisualizeOptionsConfiguration struct { // Limit is the default limit to use Limit int `json:"limit" validate:"min=5"` // LimitType is the default limitType to use - LimitType string `json:"limitType" validate:"oneof=avg max"` + LimitType string `json:"limitType" validate:"oneof=avg max last"` // Bidirectional tells if a graph should be bidirectional (all except sankey) Bidirectional bool `json:"bidirectional"` // PreviousPeriod tells if a graph should display the previous period (for stacked) diff --git a/console/data/docs/03-usage.md b/console/data/docs/03-usage.md index f8aa762d..676950df 100644 --- a/console/data/docs/03-usage.md +++ b/console/data/docs/03-usage.md @@ -157,6 +157,8 @@ aspect of the graph. traffics over the time selection. - `max`: the query focuses on getting the traffic bursts over the time selection. + - `last`: the query focuses on getting the most recent (last) traffic over + the time selection. - The filter box contains an SQL-like expression to limit the data to be graphed. It features an auto-completion system that can be triggered manually diff --git a/console/frontend/src/components/InputDimensions.vue b/console/frontend/src/components/InputDimensions.vue index ddabf3a8..11afd7fe 100644 --- a/console/frontend/src/components/InputDimensions.vue +++ b/console/frontend/src/components/InputDimensions.vue @@ -136,6 +136,7 @@ const limitError = computed(() => { const computationModes = { avg: "Avg", max: "Max", + last: "Last", } as const; const computationModeList = Object.entries(computationModes).map( diff --git a/console/graph.go b/console/graph.go index 21e9f760..f36e2767 100644 --- a/console/graph.go +++ b/console/graph.go @@ -20,7 +20,7 @@ type graphCommonHandlerInput struct { End time.Time `json:"end" binding:"required,gtfield=Start"` Dimensions []query.Column `json:"dimensions"` // group by ... Limit int `json:"limit" binding:"min=1"` // limit product of dimensions - LimitType string `json:"limitType" validate:"oneof=avg max"` + LimitType string `json:"limitType" validate:"oneof=avg max last"` Filter query.Filter `json:"filter"` // where ... TruncateAddrV4 int `json:"truncate-v4" binding:"min=0,max=32"` // 0 or 32 = no truncation TruncateAddrV6 int `json:"truncate-v6" binding:"min=0,max=128"` // 0 or 128 = no truncation diff --git a/console/line.go b/console/line.go index e9f61e6e..e8ee3cc4 100644 --- a/console/line.go +++ b/console/line.go @@ -286,6 +286,7 @@ func (c *Component) graphLineHandlerFunc(gc *gin.Context) { points := map[int]map[string][]int{} // for each axis, a map from row to list of points (one point per ts) sums := map[int]map[string]uint64{} // for each axis, a map from row to sum (for sorting purpose) maxes := map[int]map[string]uint64{} // for each axis, a map from row to max (for sorting purpose) + lasts := map[int]map[string]int{} // for each axis, a map from row to last(for sorting purpose) lastTimeForAxis := map[int]time.Time{} timeIndexForAxis := map[int]int{} for _, result := range results { @@ -301,6 +302,7 @@ func (c *Component) graphLineHandlerFunc(gc *gin.Context) { points[axis] = map[string][]int{} sums[axis] = map[string]uint64{} maxes[axis] = map[string]uint64{} + lasts[axis] = map[string]int{} } if result.Time != lastTime { // New timestamp, increment time index @@ -316,12 +318,14 @@ func (c *Component) graphLineHandlerFunc(gc *gin.Context) { points[axis][rowKey] = row sums[axis][rowKey] = 0 maxes[axis][rowKey] = 0 + lasts[axis][rowKey] = 0 } points[axis][rowKey][timeIndexForAxis[axis]] = int(result.Xps) sums[axis][rowKey] += uint64(result.Xps) if uint64(result.Xps) > maxes[axis][rowKey] { maxes[axis][rowKey] = uint64(result.Xps) } + lasts[axis][rowKey] = int(result.Xps) } // Sort axes sort.Ints(axes) @@ -344,6 +348,9 @@ func (c *Component) graphLineHandlerFunc(gc *gin.Context) { if input.LimitType == "max" { return maxes[axis][iKey] > maxes[axis][jKey] } + if input.LimitType == "last" { + return lasts[axis][iKey] > lasts[axis][jKey] + } return sums[axis][iKey] > sums[axis][jKey] })