From 2df8b5785b2bad916158f766b3617685be88b5aa Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 23 Nov 2024 20:57:48 +0100 Subject: [PATCH] console: use avg/max for LimitType (instead of Avg/Max) --- console/config.go | 4 ++-- console/config_test.go | 2 +- console/data/docs/03-usage.md | 9 ++++++--- .../frontend/src/components/InputDimensions.vue | 4 ++-- console/graph.go | 2 +- console/line.go | 2 +- console/line_test.go | 14 +++++++------- console/query.go | 2 +- console/sankey_test.go | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/console/config.go b/console/config.go index 5e78e825..60d30823 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"` // 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) @@ -87,7 +87,7 @@ func DefaultConfiguration() Configuration { Filter: "InIfBoundary = external", Dimensions: []query.Column{query.NewColumn("SrcAS")}, Limit: 10, - LimitType: "Avg", + LimitType: "avg", }, HomepageTopWidgets: []HomepageTopWidget{ HomepageTopWidgetSrcAS, diff --git a/console/config_test.go b/console/config_test.go index de113524..57e3a66d 100644 --- a/console/config_test.go +++ b/console/config_test.go @@ -26,7 +26,7 @@ func TestConfigHandler(t *testing.T) { "filter": "InIfBoundary = external", "dimensions": []string{"SrcAS"}, "limit": 10, - "limitType": "Avg", + "limitType": "avg", "bidirectional": false, "previousPeriod": false, }, diff --git a/console/data/docs/03-usage.md b/console/data/docs/03-usage.md index 42dd2d44..f8aa762d 100644 --- a/console/data/docs/03-usage.md +++ b/console/data/docs/03-usage.md @@ -151,9 +151,12 @@ aspect of the graph. "limit" parameter tells how many. The remaining values are categorized as "Other". -- Associated with the `limit` parameter, the `limitType` parameter help find traffic surges according to 2 modes: - - Avg: default mode, the query focuses on getting the highest cumulative traffics over the time selection. - - Max: the query focuses on getting the traffic bursts over the time selection. +- Associated with the `limit` parameter, the `limitType` parameter help find + traffic surges according to 2 modes: + - `avg`: default mode, the query focuses on getting the highest cumulative + traffics over the time selection. + - `max`: the query focuses on getting the traffic bursts 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 26c3c8d4..ddabf3a8 100644 --- a/console/frontend/src/components/InputDimensions.vue +++ b/console/frontend/src/components/InputDimensions.vue @@ -201,7 +201,7 @@ watch( if (value) { limit.value = value.limit.toString(); limitType.value = - computationModeList.find((mode) => mode.name === value.limitType) || + computationModeList.find((mode) => mode.type === value.limitType) || computationModeList[0]; truncate4.value = value.truncate4.toString(); truncate6.value = value.truncate6.toString(); @@ -226,7 +226,7 @@ watch( const updated = { selected: selected.map((d) => d.name), limit: parseInt(limit), - limitType: limitType.name, + limitType: limitType.type, truncate4: parseInt(truncate4), truncate6: parseInt(truncate6), errors: hasErrors, diff --git a/console/graph.go b/console/graph.go index a2c9692b..21e9f760 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"` 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 08058de3..27eadfad 100644 --- a/console/line.go +++ b/console/line.go @@ -340,7 +340,7 @@ func (c *Component) graphLineHandlerFunc(gc *gin.Context) { if rows[axis][jKey][0] == "Other" { return true } - if input.LimitType == "Max" { + if input.LimitType == "max" { return maxes[axis][iKey] > maxes[axis][jKey] } diff --git a/console/line_test.go b/console/line_test.go index 48c6d598..c4fc7f24 100644 --- a/console/line_test.go +++ b/console/line_test.go @@ -495,7 +495,7 @@ ORDER BY time WITH FILL Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Limit: 20, - LimitType: "Max", + LimitType: "max", Dimensions: []query.Column{ query.NewColumn("ExporterName"), query.NewColumn("InIfProvider"), @@ -768,7 +768,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Avg", + "limitType": "avg", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", @@ -844,7 +844,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Avg", + "limitType": "avg", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", @@ -964,7 +964,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Avg", + "limitType": "avg", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", @@ -1158,7 +1158,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Max", + "limitType": "max", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", @@ -1234,7 +1234,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Max", + "limitType": "max", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", @@ -1354,7 +1354,7 @@ func TestGraphLineHandler(t *testing.T) { "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, - "limitType": "Max", + "limitType": "max", "dimensions": []string{"ExporterName", "InIfProvider"}, "filter": "DstCountry = 'FR' AND SrcCountry = 'US'", "units": "l3bps", diff --git a/console/query.go b/console/query.go index c732dbfd..ba02c01e 100644 --- a/console/query.go +++ b/console/query.go @@ -46,7 +46,7 @@ func selectRowsByLimitType(input graphCommonHandlerInput, dimensions []string, w var rowsType string var source string var orderBy string - if input.LimitType == "Max" { + if input.LimitType == "max" { source = fmt.Sprintf("( SELECT %s AS sum_at_time FROM source WHERE %s GROUP BY %s )", strings.Join(append(dimensions, "{{ .Units }}"), ", "), where, diff --git a/console/sankey_test.go b/console/sankey_test.go index 27abfeac..89ec0338 100644 --- a/console/sankey_test.go +++ b/console/sankey_test.go @@ -66,7 +66,7 @@ ORDER BY xps DESC query.NewColumn("ExporterName"), }, Limit: 5, - LimitType: "Max", + LimitType: "max", Filter: query.Filter{}, Units: "l3bps", },