diff --git a/cmd/components_test.go b/cmd/components_test.go index 537c43c7..d198035e 100644 --- a/cmd/components_test.go +++ b/cmd/components_test.go @@ -24,6 +24,7 @@ func (c *Startable) Start() error { c.Started = true return nil } + func (c *Stopable) Stop() error { c.Stopped = true return nil @@ -39,10 +40,12 @@ type ComponentStop struct { type ComponentStart struct { Startable } -type ComponentNone struct{} -type ComponentStartError struct { - Stopable -} +type ( + ComponentNone struct{} + ComponentStartError struct { + Stopable + } +) func (c ComponentStartError) Start() error { return errors.New("nooo") diff --git a/cmd/config_test.go b/cmd/config_test.go index 2aff12ac..09ccbd32 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -84,7 +84,7 @@ module1: workers: -5 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, @@ -117,7 +117,7 @@ module2: - name: second ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, @@ -198,7 +198,7 @@ module2: interval-value: 20m ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) // Environment clean := func() { @@ -319,7 +319,7 @@ module1: workers: 10 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{Path: configFile} @@ -339,7 +339,7 @@ module1: workers: 10 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{Path: configFile} @@ -366,7 +366,7 @@ modules: topic: flows2 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0644) + ioutil.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, diff --git a/cmd/orchestrator_test.go b/cmd/orchestrator_test.go index 10b3eda2..4d3d847b 100644 --- a/cmd/orchestrator_test.go +++ b/cmd/orchestrator_test.go @@ -51,8 +51,10 @@ func TestOrchestratorConfig(t *testing.T) { root := RootCmd buf := new(bytes.Buffer) root.SetOut(buf) - root.SetArgs([]string{"orchestrator", "--dump", "--check", - filepath.Join("testdata/configurations", test.Name(), "in.yaml")}) + root.SetArgs([]string{ + "orchestrator", "--dump", "--check", + filepath.Join("testdata/configurations", test.Name(), "in.yaml"), + }) if err := root.Execute(); err != nil { t.Fatalf("`orchestrator` command error:\n%+v", err) } diff --git a/common/helpers/cache/cache.go b/common/helpers/cache/cache.go index 8501014a..1b1c85ac 100644 --- a/common/helpers/cache/cache.go +++ b/common/helpers/cache/cache.go @@ -14,10 +14,8 @@ import ( "time" ) -var ( - // ErrVersion is triggered when loading a cache from an incompatible version - ErrVersion = errors.New("cache version mismatch") -) +// ErrVersion is triggered when loading a cache from an incompatible version +var ErrVersion = errors.New("cache version mismatch") // Cache is a thread-safe in-memory key/value store type Cache[K comparable, V any] struct { diff --git a/common/helpers/cache/persist.go b/common/helpers/cache/persist.go index 4e185864..3645ff99 100644 --- a/common/helpers/cache/persist.go +++ b/common/helpers/cache/persist.go @@ -36,7 +36,6 @@ func (c *Cache[K, V]) Save(cacheFile string) error { return fmt.Errorf("unable to write cache file %q: %w", cacheFile, err) } return nil - } // Load loads the cache from the provided location. diff --git a/common/helpers/mapstructure_test.go b/common/helpers/mapstructure_test.go index e2be4953..3bb402bd 100644 --- a/common/helpers/mapstructure_test.go +++ b/common/helpers/mapstructure_test.go @@ -155,7 +155,6 @@ func TestParametrizedConfig(t *testing.T) { Error: true, }, }) - }) t.Run("marshal", func(t *testing.T) { config1 := OuterConfiguration{ diff --git a/common/kafka/config_test.go b/common/kafka/config_test.go index 1056595c..46862c95 100644 --- a/common/kafka/config_test.go +++ b/common/kafka/config_test.go @@ -150,5 +150,4 @@ func TestTLSConfiguration(t *testing.T) { }, }, }) - } diff --git a/common/kafka/logs.go b/common/kafka/logs.go index 23af9090..c8ab6916 100644 --- a/common/kafka/logs.go +++ b/common/kafka/logs.go @@ -43,6 +43,7 @@ func (l *kafkaLogger) Print(v ...interface{}) { } } } + func (l *kafkaLogger) Println(v ...interface{}) { r := l.r.Load() if r != nil { @@ -51,6 +52,7 @@ func (l *kafkaLogger) Println(v ...interface{}) { } } } + func (l *kafkaLogger) Printf(format string, v ...interface{}) { r := l.r.Load() if r != nil { diff --git a/common/reporter/healthcheck.go b/common/reporter/healthcheck.go index b7839af1..7af65778 100644 --- a/common/reporter/healthcheck.go +++ b/common/reporter/healthcheck.go @@ -187,6 +187,5 @@ func ChannelHealthcheck(ctx context.Context, contact chan<- ChannelHealthcheckFu case result := <-answerChan: return result } - } } diff --git a/common/reporter/logger/root.go b/common/reporter/logger/root.go index 73c85765..fb41f657 100644 --- a/common/reporter/logger/root.go +++ b/common/reporter/logger/root.go @@ -30,7 +30,7 @@ type Logger struct { // New creates a new logger func New(config Configuration) (Logger, error) { // Initialize the logger - var logger = log.Logger.Hook(contextHook{}) + logger := log.Logger.Hook(contextHook{}) return Logger{logger}, nil } diff --git a/common/reporter/logger/root_example_test.go b/common/reporter/logger/root_example_test.go index b923c895..73a6c100 100644 --- a/common/reporter/logger/root_example_test.go +++ b/common/reporter/logger/root_example_test.go @@ -17,7 +17,7 @@ func ExampleNew() { // Initialize zerolog log.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger() zerolog.TimestampFunc = func() time.Time { - return time.Date(2008, 1, 8, 17, 5, 05, 0, time.UTC) + return time.Date(2008, 1, 8, 17, 5, 5, 0, time.UTC) } // Initialize logger diff --git a/common/reporter/metrics_test.go b/common/reporter/metrics_test.go index 1ad13ee7..b1253220 100644 --- a/common/reporter/metrics_test.go +++ b/common/reporter/metrics_test.go @@ -47,7 +47,8 @@ func TestMetrics(t *testing.T) { gauge3 := r.GaugeVec(reporter.GaugeOpts{ Name: "gauge3", - Help: "Another gauge"}, + Help: "Another gauge", + }, []string{"label1", "label2"}) gauge3.WithLabelValues("value1", "value2").Set(44) gauge3.WithLabelValues("value3", "value4").Set(48) diff --git a/common/reporter/stack/root.go b/common/reporter/stack/root.go index 5e5db510..f0fc477e 100644 --- a/common/reporter/stack/root.go +++ b/common/reporter/stack/root.go @@ -27,6 +27,7 @@ var pcStackPool = sync.Pool{ func poolBuf() []uintptr { return pcStackPool.Get().([]uintptr) } + func putPoolBuf(p []uintptr) { pcStackPool.Put(p) } diff --git a/common/schema/definition.go b/common/schema/definition.go index 070d2bd1..02f4963a 100644 --- a/common/schema/definition.go +++ b/common/schema/definition.go @@ -134,12 +134,14 @@ func flows() Schema { ClickHouseMainOnly: true, ClickHouseType: "IPv6", ClickHouseCodec: "ZSTD(1)", - }, { + }, + { Key: ColumnSrcNetMask, ClickHouseMainOnly: true, ClickHouseType: "UInt8", ConsoleNotDimension: true, - }, { + }, + { Key: ColumnSrcNetPrefix, ClickHouseMainOnly: true, ClickHouseType: "String", @@ -154,39 +156,48 @@ END`, Key: ColumnSrcNetName, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'name', SrcAddr, '')", - }, { + }, + { Key: ColumnDstNetName, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'name', DstAddr, '')", - }, { + }, + { Key: ColumnSrcNetRole, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'role', SrcAddr, '')", - }, { + }, + { Key: ColumnDstNetRole, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'role', DstAddr, '')", - }, { + }, + { Key: ColumnSrcNetSite, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'site', SrcAddr, '')", - }, { + }, + { Key: ColumnDstNetSite, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'site', DstAddr, '')", - }, { + }, + { Key: ColumnSrcNetRegion, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'region', SrcAddr, '')", - }, { + }, + { Key: ColumnDstNetRegion, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'region', DstAddr, '')", - }, { + }, + { Key: ColumnSrcNetTenant, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'tenant', SrcAddr, '')", - }, { + }, + { Key: ColumnDstNetTenant, ClickHouseType: "LowCardinality(String)", ClickHouseGenerateFrom: "dictGetOrDefault('networks', 'tenant', DstAddr, '')", @@ -197,26 +208,31 @@ END`, Key: ColumnDstASPath, ClickHouseMainOnly: true, ClickHouseType: "Array(UInt32)", - }, { + }, + { Key: ColumnDst1stAS, Depends: []ColumnKey{ColumnDstASPath}, ClickHouseType: "UInt32", ClickHouseGenerateFrom: "c_DstASPath[1]", - }, { + }, + { Key: ColumnDst2ndAS, Depends: []ColumnKey{ColumnDstASPath}, ClickHouseType: "UInt32", ClickHouseGenerateFrom: "c_DstASPath[2]", - }, { + }, + { Key: ColumnDst3rdAS, Depends: []ColumnKey{ColumnDstASPath}, ClickHouseType: "UInt32", ClickHouseGenerateFrom: "c_DstASPath[3]", - }, { + }, + { Key: ColumnDstCommunities, ClickHouseMainOnly: true, ClickHouseType: "Array(UInt32)", - }, { + }, + { Key: ColumnDstLargeCommunities, ClickHouseMainOnly: true, ClickHouseType: "Array(UInt128)", @@ -279,13 +295,16 @@ END`, ClickHouseType: "UInt64", ClickHouseAlias: "intDiv(Bytes, Packets)", ConsoleNotDimension: true, - }, { + }, + { Key: ColumnPacketSizeBucket, Depends: []ColumnKey{ColumnPacketSize}, ClickHouseType: "LowCardinality(String)", ClickHouseAlias: func() string { - boundaries := []int{64, 128, 256, 512, 768, 1024, 1280, 1501, - 2048, 3072, 4096, 8192, 10240, 16384, 32768, 65536} + boundaries := []int{ + 64, 128, 256, 512, 768, 1024, 1280, 1501, + 2048, 3072, 4096, 8192, 10240, 16384, 32768, 65536, + } conditions := []string{} last := 0 for _, boundary := range boundaries { diff --git a/common/schema/protobuf_test.go b/common/schema/protobuf_test.go index 83d81d88..4605c9d1 100644 --- a/common/schema/protobuf_test.go +++ b/common/schema/protobuf_test.go @@ -29,10 +29,12 @@ func TestProtobufDefinition(t *testing.T) { { Key: ColumnSrcAddr, ClickHouseType: "IPv6", - }, { + }, + { Key: ColumnSrcNetMask, ClickHouseType: "UInt8", - }, { + }, + { Key: ColumnSrcNetPrefix, ClickHouseType: "String", ClickHouseAlias: `something`, @@ -47,7 +49,8 @@ func TestProtobufDefinition(t *testing.T) { { Key: ColumnDstASPath, ClickHouseType: "Array(UInt32)", - }, { + }, + { Key: ColumnDstLargeCommunities, ClickHouseType: "Array(UInt128)", ClickHouseTransformFrom: []Column{ @@ -107,7 +110,6 @@ message FlowMessagevLH2TTFF7P352DSYYCJYWFCXHAM { if diff := helpers.Diff(strings.Split(got, "\n"), strings.Split(expected, "\n")); diff != "" { t.Fatalf("ProtobufDefinition() (-got, +want): %s", diff) } - } func TestProtobufMarshal(t *testing.T) { diff --git a/common/schema/root_test.go b/common/schema/root_test.go index ca3db0c5..7f1934f6 100644 --- a/common/schema/root_test.go +++ b/common/schema/root_test.go @@ -29,7 +29,6 @@ func TestEnableDisableColumns(t *testing.T) { } else if !column.Disabled { t.Fatal("DstCountry is not disabled") } - } func TestDisableForbiddenColumns(t *testing.T) { diff --git a/console/clickhouse_test.go b/console/clickhouse_test.go index 2b95d731..baa25b20 100644 --- a/console/clickhouse_test.go +++ b/console/clickhouse_test.go @@ -37,34 +37,34 @@ AND engine LIKE '%MergeTree' Return(nil). SetArg(1, []struct { T time.Time `ch:"t"` - }{{time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC)}}) + }{{time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC)}}) mockConn.EXPECT(). Select(gomock.Any(), gomock.Any(), `SELECT MIN(TimeReceived) AS t FROM flows_1h0m0s`). Return(nil). SetArg(1, []struct { T time.Time `ch:"t"` - }{{time.Date(2022, 01, 10, 15, 45, 10, 0, time.UTC)}}) + }{{time.Date(2022, 1, 10, 15, 45, 10, 0, time.UTC)}}) mockConn.EXPECT(). Select(gomock.Any(), gomock.Any(), `SELECT MIN(TimeReceived) AS t FROM flows_1m0s`). Return(nil). SetArg(1, []struct { T time.Time `ch:"t"` - }{{time.Date(2022, 04, 20, 15, 45, 10, 0, time.UTC)}}) + }{{time.Date(2022, 4, 20, 15, 45, 10, 0, time.UTC)}}) mockConn.EXPECT(). Select(gomock.Any(), gomock.Any(), `SELECT MIN(TimeReceived) AS t FROM flows_5m0s`). Return(nil). SetArg(1, []struct { T time.Time `ch:"t"` - }{{time.Date(2022, 02, 10, 15, 45, 10, 0, time.UTC)}}) + }{{time.Date(2022, 2, 10, 15, 45, 10, 0, time.UTC)}}) if err := c.refreshFlowsTables(); err != nil { t.Fatalf("refreshFlowsTables() error:\n%+v", err) } expected := []flowsTable{ - {"flows", time.Duration(0), time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC)}, - {"flows_1h0m0s", time.Hour, time.Date(2022, 01, 10, 15, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 20, 15, 45, 10, 0, time.UTC)}, - {"flows_5m0s", 5 * time.Minute, time.Date(2022, 02, 10, 15, 45, 10, 0, time.UTC)}, + {"flows", time.Duration(0), time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC)}, + {"flows_1h0m0s", time.Hour, time.Date(2022, 1, 10, 15, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 20, 15, 45, 10, 0, time.UTC)}, + {"flows_5m0s", 5 * time.Minute, time.Date(2022, 2, 10, 15, 45, 10, 0, time.UTC)}, } if diff := helpers.Diff(c.flowsTables, expected); diff != "" { t.Fatalf("refreshFlowsTables() diff:\n%s", diff) @@ -83,8 +83,8 @@ func TestFinalizeQuery(t *testing.T) { Description: "simple query without additional tables", Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 86400, }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC')", @@ -92,106 +92,106 @@ func TestFinalizeQuery(t *testing.T) { Description: "query with source port", Query: "SELECT TimeReceived, SrcPort FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), MainTableRequired: true, Points: 86400, }, Expected: "SELECT TimeReceived, SrcPort FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC')", }, { Description: "only flows table available", - Tables: []flowsTable{{"flows", 0, time.Date(2022, 03, 10, 15, 45, 10, 0, time.UTC)}}, + Tables: []flowsTable{{"flows", 0, time.Date(2022, 3, 10, 15, 45, 10, 0, time.UTC)}}, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 86400, }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC')", }, { Description: "timefilter.Start and timefilter.Stop", - Tables: []flowsTable{{"flows", 0, time.Date(2022, 03, 10, 15, 45, 10, 0, time.UTC)}}, + Tables: []flowsTable{{"flows", 0, time.Date(2022, 3, 10, 15, 45, 10, 0, time.UTC)}}, Query: "SELECT {{ .TimefilterStart }}, {{ .TimefilterEnd }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 86400, }, Expected: "SELECT toDateTime('2022-04-10 15:45:10', 'UTC'), toDateTime('2022-04-11 15:45:10', 'UTC')", }, { Description: "only flows table and out of range request", - Tables: []flowsTable{{"flows", 0, time.Date(2022, 04, 10, 22, 45, 10, 0, time.UTC)}}, + Tables: []flowsTable{{"flows", 0, time.Date(2022, 4, 10, 22, 45, 10, 0, time.UTC)}}, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 86400, }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC')", }, { Description: "select consolidated table", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 03, 10, 22, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 2, 22, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 3, 10, 22, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 2, 22, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }} // {{ .Interval }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 720, // 2-minute resolution }, Expected: "SELECT 1 FROM flows_1m0s WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:00', 'UTC') AND toDateTime('2022-04-11 15:45:00', 'UTC') // 120", }, { Description: "select consolidated table out of range", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 22, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 10, 17, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 22, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 10, 17, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 720, // 2-minute resolution, }, Expected: "SELECT 1 FROM flows_1m0s WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:00', 'UTC') AND toDateTime('2022-04-11 15:45:00', 'UTC')", }, { Description: "select flows table out of range", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 16, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 10, 17, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 16, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 10, 17, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 720, // 2-minute resolution, }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC')", }, { Description: "use flows table for resolution (control for next case)", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 10, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 03, 10, 10, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 10, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 3, 10, 10, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }} // {{ .Interval }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 2880, // 30-second resolution }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC') // 30", }, { Description: "use flows table for resolution (but flows_1m0s for data)", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 10, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 03, 10, 10, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 10, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 3, 10, 10, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }} // {{ .Interval }}", Context: inputContext{ - Start: time.Date(2022, 03, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 03, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 3, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 3, 11, 15, 45, 10, 0, time.UTC), StartForInterval: func() *time.Time { - t := time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC) + t := time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC) return &t }(), Points: 2880, // 30-second resolution @@ -200,55 +200,55 @@ func TestFinalizeQuery(t *testing.T) { }, { Description: "select flows table with better resolution", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 03, 10, 16, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 03, 10, 17, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 3, 10, 16, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 3, 10, 17, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }} // {{ .Interval }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 2880, }, Expected: "SELECT 1 FROM flows WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:10', 'UTC') AND toDateTime('2022-04-11 15:45:10', 'UTC') // 30", }, { Description: "select consolidated table with better resolution", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 03, 10, 22, 45, 10, 0, time.UTC)}, - {"flows_5m0s", 5 * time.Minute, time.Date(2022, 04, 2, 22, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 2, 22, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 3, 10, 22, 45, 10, 0, time.UTC)}, + {"flows_5m0s", 5 * time.Minute, time.Date(2022, 4, 2, 22, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 2, 22, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }} // {{ .Interval }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 720, // 2-minute resolution, }, Expected: "SELECT 1 FROM flows_1m0s WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:00', 'UTC') AND toDateTime('2022-04-11 15:45:00', 'UTC') // 120", }, { Description: "select consolidated table with better range", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 22, 45, 10, 0, time.UTC)}, - {"flows_5m0s", 5 * time.Minute, time.Date(2022, 04, 2, 22, 45, 10, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 10, 22, 45, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 22, 45, 10, 0, time.UTC)}, + {"flows_5m0s", 5 * time.Minute, time.Date(2022, 4, 2, 22, 45, 10, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 10, 22, 45, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 46, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 46, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 46, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 46, 10, 0, time.UTC), Points: 720, // 2-minute resolution, }, Expected: "SELECT 1 FROM flows_5m0s WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:45:00', 'UTC') AND toDateTime('2022-04-11 15:45:00', 'UTC')", }, { Description: "select best resolution when equality for oldest data", Tables: []flowsTable{ - {"flows", 0, time.Date(2022, 04, 10, 22, 40, 55, 0, time.UTC)}, - {"flows_1m0s", time.Minute, time.Date(2022, 04, 10, 22, 40, 00, 0, time.UTC)}, - {"flows_1h0m0s", time.Hour, time.Date(2022, 04, 10, 22, 00, 10, 0, time.UTC)}, + {"flows", 0, time.Date(2022, 4, 10, 22, 40, 55, 0, time.UTC)}, + {"flows_1m0s", time.Minute, time.Date(2022, 4, 10, 22, 40, 0, 0, time.UTC)}, + {"flows_1h0m0s", time.Hour, time.Date(2022, 4, 10, 22, 0, 10, 0, time.UTC)}, }, Query: "SELECT 1 FROM {{ .Table }} WHERE {{ .Timefilter }}", Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 46, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 46, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 46, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 46, 10, 0, time.UTC), Points: 720, // 2-minute resolution, }, Expected: "SELECT 1 FROM flows_1m0s WHERE TimeReceived BETWEEN toDateTime('2022-04-10 15:46:00', 'UTC') AND toDateTime('2022-04-11 15:46:00', 'UTC')", @@ -256,8 +256,8 @@ func TestFinalizeQuery(t *testing.T) { Description: "query with escaped template", Query: `SELECT TimeReceived, SrcPort WHERE InIfDescription = '{{"{{"}} hello }}'`, Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 86400, }, Expected: `SELECT TimeReceived, SrcPort WHERE InIfDescription = '{{ hello }}'`, @@ -265,8 +265,8 @@ func TestFinalizeQuery(t *testing.T) { Description: "use of ToStartOfInterval", Query: `{{ call .ToStartOfInterval "TimeReceived" }}`, Context: inputContext{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 720, }, Expected: `toStartOfInterval(TimeReceived + INTERVAL 50 second, INTERVAL 120 second) - INTERVAL 50 second`, @@ -274,8 +274,8 @@ func TestFinalizeQuery(t *testing.T) { Description: "Small interval outside main table expiration", Query: "SELECT InIfProvider FROM {{ .Table }}", Tables: []flowsTable{ - {"flows", time.Duration(0), time.Date(2022, 11, 06, 12, 0, 0, 0, time.UTC)}, - {"flows_1h0m0s", time.Hour, time.Date(2022, 04, 25, 18, 0, 0, 0, time.UTC)}, + {"flows", time.Duration(0), time.Date(2022, 11, 6, 12, 0, 0, 0, time.UTC)}, + {"flows_1h0m0s", time.Hour, time.Date(2022, 4, 25, 18, 0, 0, 0, time.UTC)}, {"flows_1m0s", time.Minute, time.Date(2022, 11, 14, 12, 0, 0, 0, time.UTC)}, {"flows_5m0s", 5 * time.Minute, time.Date(2022, 8, 23, 12, 0, 0, 0, time.UTC)}, }, diff --git a/console/config_test.go b/console/config_test.go index 6a48104e..02220d0f 100644 --- a/console/config_test.go +++ b/console/config_test.go @@ -30,7 +30,8 @@ func TestConfigHandler(t *testing.T) { }, "homepageTopWidgets": []string{"src-as", "src-port", "protocol", "src-country", "etype"}, "dimensionsLimit": 50, - "dimensions": []string{"ExporterAddress", + "dimensions": []string{ + "ExporterAddress", "ExporterName", "ExporterGroup", "ExporterRole", diff --git a/console/filter/error.go b/console/filter/error.go index 0839ae45..6534d205 100644 --- a/console/filter/error.go +++ b/console/filter/error.go @@ -23,13 +23,15 @@ func HumanError(err error) string { } // Errors represents a serializable list of errors. -type Errors []oneError -type oneError struct { - Message string `json:"message"` - Line int `json:"line"` - Column int `json:"column"` - Offset int `json:"offset"` -} +type ( + Errors []oneError + oneError struct { + Message string `json:"message"` + Line int `json:"line"` + Column int `json:"column"` + Offset int `json:"offset"` + } +) // AllErrors returns all parsed errors. The returned value can be serialized to JSON. func AllErrors(err error) Errors { diff --git a/console/filter/parser_test.go b/console/filter/parser_test.go index bae96348..b098be4e 100644 --- a/console/filter/parser_test.go +++ b/console/filter/parser_test.go @@ -18,8 +18,10 @@ func TestValidFilter(t *testing.T) { MetaOut Meta }{ {Input: `ExporterName = 'something'`, Output: `ExporterName = 'something'`}, - {Input: `ExporterName = 'something'`, Output: `ExporterName = 'something'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `ExporterName = 'something'`, Output: `ExporterName = 'something'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `exportername = 'something'`, Output: `ExporterName = 'something'`}, {Input: `ExporterName='something'`, Output: `ExporterName = 'something'`}, {Input: `ExporterName="something"`, Output: `ExporterName = 'something'`}, @@ -39,59 +41,75 @@ func TestValidFilter(t *testing.T) { { Input: `ExporterAddress << 2001:db8:0::/64`, Output: `ExporterAddress BETWEEN toIPv6('2001:db8::') AND toIPv6('2001:db8::ffff:ffff:ffff:ffff')`, - }, { + }, + { Input: `ExporterAddress << 2001:db8::c000/115`, Output: `ExporterAddress BETWEEN toIPv6('2001:db8::c000') AND toIPv6('2001:db8::dfff')`, - }, { + }, + { Input: `ExporterAddress << 192.168.0.0/24`, Output: `ExporterAddress BETWEEN toIPv6('::ffff:192.168.0.0') AND toIPv6('::ffff:192.168.0.255')`, - }, { + }, + { Input: `DstAddr << 192.168.0.0/24`, Output: `DstAddr BETWEEN toIPv6('::ffff:192.168.0.0') AND toIPv6('::ffff:192.168.0.255')`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstAddr << 192.168.0.0/24`, Output: `SrcAddr BETWEEN toIPv6('::ffff:192.168.0.0') AND toIPv6('::ffff:192.168.0.255')`, MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true, MainTableRequired: true}, - }, { + }, + { Input: `SrcAddr << 192.168.0.1/24`, Output: `SrcAddr BETWEEN toIPv6('::ffff:192.168.0.0') AND toIPv6('::ffff:192.168.0.255')`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstAddr !<< 192.168.0.0/24`, Output: `DstAddr NOT BETWEEN toIPv6('::ffff:192.168.0.0') AND toIPv6('::ffff:192.168.0.255')`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstAddr !<< 192.168.0.128/27`, Output: `DstAddr NOT BETWEEN toIPv6('::ffff:192.168.0.128') AND toIPv6('::ffff:192.168.0.159')`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstNetPrefix = 192.168.0.128/27`, Output: `DstAddr BETWEEN toIPv6('::ffff:192.168.0.128') AND toIPv6('::ffff:192.168.0.159') AND DstNetMask = 27`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `SrcNetPrefix = 192.168.0.128/27`, Output: `SrcAddr BETWEEN toIPv6('::ffff:192.168.0.128') AND toIPv6('::ffff:192.168.0.159') AND SrcNetMask = 27`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `SrcNetPrefix = 2001:db8::/48`, Output: `SrcAddr BETWEEN toIPv6('2001:db8::') AND toIPv6('2001:db8:0:ffff:ffff:ffff:ffff:ffff') AND SrcNetMask = 48`, MetaOut: Meta{MainTableRequired: true}, }, {Input: `ExporterGroup= "group"`, Output: `ExporterGroup = 'group'`}, - {Input: `SrcAddr=203.0.113.1`, Output: `SrcAddr = toIPv6('203.0.113.1')`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `DstAddr=203.0.113.2`, Output: `DstAddr = toIPv6('203.0.113.2')`, - MetaOut: Meta{MainTableRequired: true}}, + { + Input: `SrcAddr=203.0.113.1`, Output: `SrcAddr = toIPv6('203.0.113.1')`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `DstAddr=203.0.113.2`, Output: `DstAddr = toIPv6('203.0.113.2')`, + MetaOut: Meta{MainTableRequired: true}, + }, {Input: `SrcNetName="alpha"`, Output: `SrcNetName = 'alpha'`}, {Input: `DstNetName="alpha"`, Output: `DstNetName = 'alpha'`}, {Input: `DstNetRole="stuff"`, Output: `DstNetRole = 'stuff'`}, {Input: `SrcNetTenant="mobile"`, Output: `SrcNetTenant = 'mobile'`}, {Input: `SrcAS=12322`, Output: `SrcAS = 12322`}, {Input: `SrcAS=AS12322`, Output: `SrcAS = 12322`}, - {Input: `SrcAS=AS12322`, Output: `DstAS = 12322`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `SrcAS=AS12322`, Output: `DstAS = 12322`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `SrcAS=as12322`, Output: `SrcAS = 12322`}, {Input: `SrcAS IN(12322, 29447)`, Output: `SrcAS IN (12322, 29447)`}, {Input: `SrcAS IN( 12322 , 29447 )`, Output: `SrcAS IN (12322, 29447)`}, @@ -99,88 +117,134 @@ func TestValidFilter(t *testing.T) { {Input: `SrcAS NOTIN (AS12322, 29447)`, Output: `SrcAS NOT IN (12322, 29447)`}, {Input: `DstAS=12322`, Output: `DstAS = 12322`}, {Input: `SrcCountry='FR'`, Output: `SrcCountry = 'FR'`}, - {Input: `SrcCountry='FR'`, Output: `DstCountry = 'FR'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `SrcCountry='FR'`, Output: `DstCountry = 'FR'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `DstCountry='FR'`, Output: `DstCountry = 'FR'`}, - {Input: `DstCountry='FR'`, Output: `SrcCountry = 'FR'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `DstCountry='FR'`, Output: `SrcCountry = 'FR'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfName='Gi0/0/0/1'`, Output: `InIfName = 'Gi0/0/0/1'`}, - {Input: `InIfName='Gi0/0/0/1'`, Output: `OutIfName = 'Gi0/0/0/1'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfName='Gi0/0/0/1'`, Output: `OutIfName = 'Gi0/0/0/1'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `OutIfName = 'Gi0/0/0/1'`, Output: `OutIfName = 'Gi0/0/0/1'`}, - {Input: `OutIfName = 'Gi0/0/0/1'`, Output: `InIfName = 'Gi0/0/0/1'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `OutIfName = 'Gi0/0/0/1'`, Output: `InIfName = 'Gi0/0/0/1'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfDescription='Some description'`, Output: `InIfDescription = 'Some description'`}, - {Input: `InIfDescription='Some description'`, Output: `OutIfDescription = 'Some description'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfDescription='Some description'`, Output: `OutIfDescription = 'Some description'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `OutIfDescription='Some other description'`, Output: `OutIfDescription = 'Some other description'`}, - {Input: `OutIfDescription='Some other description'`, Output: `InIfDescription = 'Some other description'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `OutIfDescription='Some other description'`, Output: `InIfDescription = 'Some other description'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfSpeed>=1000`, Output: `InIfSpeed >= 1000`}, - {Input: `InIfSpeed>=1000`, Output: `OutIfSpeed >= 1000`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfSpeed>=1000`, Output: `OutIfSpeed >= 1000`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfSpeed!=1000`, Output: `InIfSpeed != 1000`}, {Input: `InIfSpeed<1000`, Output: `InIfSpeed < 1000`}, {Input: `OutIfSpeed!=1000`, Output: `OutIfSpeed != 1000`}, - {Input: `OutIfSpeed!=1000`, Output: `InIfSpeed != 1000`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `OutIfSpeed!=1000`, Output: `InIfSpeed != 1000`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfConnectivity = 'pni'`, Output: `InIfConnectivity = 'pni'`}, - {Input: `InIfConnectivity = 'pni'`, Output: `OutIfConnectivity = 'pni'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfConnectivity = 'pni'`, Output: `OutIfConnectivity = 'pni'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `OutIfConnectivity = 'ix'`, Output: `OutIfConnectivity = 'ix'`}, - {Input: `OutIfConnectivity = 'ix'`, Output: `InIfConnectivity = 'ix'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `OutIfConnectivity = 'ix'`, Output: `InIfConnectivity = 'ix'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfProvider = 'cogent'`, Output: `InIfProvider = 'cogent'`}, - {Input: `InIfProvider = 'cogent'`, Output: `OutIfProvider = 'cogent'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfProvider = 'cogent'`, Output: `OutIfProvider = 'cogent'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `OutIfProvider = 'telia'`, Output: `OutIfProvider = 'telia'`}, - {Input: `OutIfProvider = 'telia'`, Output: `InIfProvider = 'telia'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `OutIfProvider = 'telia'`, Output: `InIfProvider = 'telia'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfBoundary = external`, Output: `InIfBoundary = 'external'`}, - {Input: `InIfBoundary = external`, Output: `OutIfBoundary = 'external'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfBoundary = external`, Output: `OutIfBoundary = 'external'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `InIfBoundary = EXTERNAL`, Output: `InIfBoundary = 'external'`}, - {Input: `InIfBoundary = EXTERNAL`, Output: `OutIfBoundary = 'external'`, - MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}}, + { + Input: `InIfBoundary = EXTERNAL`, Output: `OutIfBoundary = 'external'`, + MetaIn: Meta{ReverseDirection: true}, MetaOut: Meta{ReverseDirection: true}, + }, {Input: `OutIfBoundary != internal`, Output: `OutIfBoundary != 'internal'`}, {Input: `EType = ipv4`, Output: `EType = 2048`}, {Input: `EType != ipv6`, Output: `EType != 34525`}, {Input: `Proto = 1`, Output: `Proto = 1`}, {Input: `Proto = 'gre'`, Output: `dictGetOrDefault('protocols', 'name', Proto, '???') = 'gre'`}, - {Input: `SrcPort = 80`, Output: `SrcPort = 80`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `SrcPort = 80`, Output: `DstPort = 80`, + { + Input: `SrcPort = 80`, Output: `SrcPort = 80`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `SrcPort = 80`, Output: `DstPort = 80`, MetaIn: Meta{ReverseDirection: true}, - MetaOut: Meta{ReverseDirection: true, MainTableRequired: true}}, - {Input: `DstPort > 1024`, Output: `DstPort > 1024`, - MetaOut: Meta{MainTableRequired: true}}, + MetaOut: Meta{ReverseDirection: true, MainTableRequired: true}, + }, + { + Input: `DstPort > 1024`, Output: `DstPort > 1024`, + MetaOut: Meta{MainTableRequired: true}, + }, {Input: `ForwardingStatus >= 128`, Output: `ForwardingStatus >= 128`}, {Input: `PacketSize > 1500`, Output: `PacketSize > 1500`}, - {Input: `DstPort > 1024 AND SrcPort < 1024`, Output: `DstPort > 1024 AND SrcPort < 1024`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `DstPort > 1024 OR SrcPort < 1024`, Output: `DstPort > 1024 OR SrcPort < 1024`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `NOT DstPort > 1024 AND SrcPort < 1024`, Output: `NOT DstPort > 1024 AND SrcPort < 1024`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `not DstPort > 1024 and SrcPort < 1024`, Output: `NOT DstPort > 1024 AND SrcPort < 1024`, - MetaOut: Meta{MainTableRequired: true}}, + { + Input: `DstPort > 1024 AND SrcPort < 1024`, Output: `DstPort > 1024 AND SrcPort < 1024`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `DstPort > 1024 OR SrcPort < 1024`, Output: `DstPort > 1024 OR SrcPort < 1024`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `NOT DstPort > 1024 AND SrcPort < 1024`, Output: `NOT DstPort > 1024 AND SrcPort < 1024`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `not DstPort > 1024 and SrcPort < 1024`, Output: `NOT DstPort > 1024 AND SrcPort < 1024`, + MetaOut: Meta{MainTableRequired: true}, + }, { Input: `DstPort > 1024 AND SrcPort < 1024 OR InIfSpeed >= 1000`, Output: `DstPort > 1024 AND SrcPort < 1024 OR InIfSpeed >= 1000`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, Output: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: ` DstPort > 1024 AND ( SrcPort < 1024 OR InIfSpeed >= 1000 ) `, Output: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstPort > 1024 AND(SrcPort < 1024 OR InIfSpeed >= 1000)`, Output: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, Output: `DstPort > 1024 AND (SrcPort < 1024 OR InIfSpeed >= 1000)`, @@ -196,10 +260,12 @@ DstPort > 1024 -- Non-privileged port AND SrcAS = AS12322 -- Proxad ASN`, Output: `DstPort > 1024 AND SrcAS = 12322`, MetaOut: Meta{MainTableRequired: true}, - }, { + }, + { Input: `InIfDescription = "This contains a -- comment" -- nope`, Output: `InIfDescription = 'This contains a -- comment'`, - }, { + }, + { Input: `InIfDescription = "This contains a /* comment"`, Output: `InIfDescription = 'This contains a /* comment'`, }, @@ -217,14 +283,22 @@ output provider */ = 'telia'`, {Input: `DstCommunities != 65000:100:200`, Output: `NOT has(DstLargeCommunities, bitShiftLeft(65000::UInt128, 64) + bitShiftLeft(100::UInt128, 32) + 200::UInt128)`, MetaOut: Meta{MainTableRequired: true}}, {Input: `SrcVlan = 1000`, Output: `SrcVlan = 1000`}, {Input: `DstVlan = 1000`, Output: `DstVlan = 1000`}, - {Input: `SrcAddrNAT = 203.0.113.4`, Output: `SrcAddrNAT = toIPv6('203.0.113.4')`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `DstAddrNAT = 203.0.113.4`, Output: `DstAddrNAT = toIPv6('203.0.113.4')`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `SrcPortNAT = 22`, Output: `SrcPortNAT = 22`, - MetaOut: Meta{MainTableRequired: true}}, - {Input: `DstPortNAT = 22`, Output: `DstPortNAT = 22`, - MetaOut: Meta{MainTableRequired: true}}, + { + Input: `SrcAddrNAT = 203.0.113.4`, Output: `SrcAddrNAT = toIPv6('203.0.113.4')`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `DstAddrNAT = 203.0.113.4`, Output: `DstAddrNAT = toIPv6('203.0.113.4')`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `SrcPortNAT = 22`, Output: `SrcPortNAT = 22`, + MetaOut: Meta{MainTableRequired: true}, + }, + { + Input: `DstPortNAT = 22`, Output: `DstPortNAT = 22`, + MetaOut: Meta{MainTableRequired: true}, + }, {Input: `SrcMAC = 00:11:22:33:44:55`, Output: `SrcMAC = MACStringToNum('00:11:22:33:44:55')`}, {Input: `DstMAC = 00:11:22:33:44:55`, Output: `DstMAC = MACStringToNum('00:11:22:33:44:55')`}, {Input: `SrcMAC != 00:0c:fF:33:44:55`, Output: `SrcMAC != MACStringToNum('00:0c:ff:33:44:55')`}, diff --git a/console/filter_test.go b/console/filter_test.go index dfb6b7f9..7c1a32b2 100644 --- a/console/filter_test.go +++ b/console/filter_test.go @@ -31,7 +31,8 @@ LIMIT 20`, }{ {"th2-router1"}, {"th2-router2"}, - {"th2-router3"}}). + {"th2-router3"}, + }). Return(nil) mockConn.EXPECT(). Select(gomock.Any(), gomock.Any(), ` @@ -138,7 +139,8 @@ LIMIT 20`, "6540"). JSONInput: gin.H{"filter": `InIfName = "Gi0/0/0/1"`}, JSONOutput: gin.H{ "message": "ok", - "parsed": `InIfName = 'Gi0/0/0/1'`}, + "parsed": `InIfName = 'Gi0/0/0/1'`, + }, }, { URL: "/api/v0/console/filter/validate", @@ -152,7 +154,8 @@ LIMIT 20`, "6540"). "message": "string literal not terminated", }}, }, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "column", "prefix": "dSt"}, @@ -173,7 +176,8 @@ LIMIT 20`, "6540"). {"label": "DstNetTenant", "detail": "column name", "quoted": false}, {"label": "DstPort", "detail": "column name", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "operator", "column": "ExporterName"}, @@ -187,7 +191,8 @@ LIMIT 20`, "6540"). {"label": "NOTIN (", "detail": "comparison operator", "quoted": false}, {"label": "UNLIKE", "detail": "comparison operator", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "outifboundary"}, @@ -196,7 +201,8 @@ LIMIT 20`, "6540"). {"label": "external", "detail": "network boundary", "quoted": false}, {"label": "undefined", "detail": "network boundary", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "etype"}, @@ -204,7 +210,8 @@ LIMIT 20`, "6540"). {"label": "IPv4", "detail": "ethernet type", "quoted": false}, {"label": "IPv6", "detail": "ethernet type", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "proto", "prefix": "I"}, @@ -216,7 +223,8 @@ LIMIT 20`, "6540"). {"label": "IPv4", "detail": "protocol", "quoted": true}, {"label": "IPv6", "detail": "protocol", "quoted": true}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "exportername", "prefix": "th2-"}, @@ -225,7 +233,8 @@ LIMIT 20`, "6540"). {"label": "th2-router2", "detail": "exporter name", "quoted": true}, {"label": "th2-router3", "detail": "exporter name", "quoted": true}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "dstAS", "prefix": "goog"}, @@ -242,7 +251,8 @@ LIMIT 20`, "6540"). {"label": "AS36987", "detail": "Google Kenya", "quoted": false}, {"label": "AS41264", "detail": "Google Switzerland", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "dstcommunities", "prefix": "6540"}, @@ -252,7 +262,8 @@ LIMIT 20`, "6540"). {"label": "65401:13", "detail": "community", "quoted": false}, {"label": "65402:200:100", "detail": "large community", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "dstASpath", "prefix": "goog"}, @@ -269,7 +280,8 @@ LIMIT 20`, "6540"). {"label": "AS36987", "detail": "Google Kenya", "quoted": false}, {"label": "AS41264", "detail": "Google Switzerland", "quoted": false}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "srcnetName", "prefix": "c"}, @@ -278,19 +290,22 @@ LIMIT 20`, "6540"). {"label": "customer-2", "detail": "network name", "quoted": true}, {"label": "customer-3", "detail": "network name", "quoted": true}, }}, - }, { + }, + { URL: "/api/v0/console/filter/complete", StatusCode: 200, JSONInput: gin.H{"what": "value", "column": "dstnetRole", "prefix": "c"}, JSONOutput: gin.H{"completions": []gin.H{ {"label": "customer", "detail": "network name", "quoted": true}, }}, - }, { + }, + { Description: "list, no filters", URL: "/api/v0/console/filter/saved", StatusCode: 200, JSONOutput: gin.H{"filters": []gin.H{}}, - }, { + }, + { Description: "store one filter", URL: "/api/v0/console/filter/saved", StatusCode: 204, @@ -299,7 +314,8 @@ LIMIT 20`, "6540"). "content": "InIfBoundary = external", }, ContentType: "application/json; charset=utf-8", - }, { + }, + { Description: "list stored filters", URL: "/api/v0/console/filter/saved", JSONOutput: gin.H{"filters": []gin.H{ @@ -311,7 +327,8 @@ LIMIT 20`, "6540"). "content": "InIfBoundary = external", }, }}, - }, { + }, + { Description: "list stored filters as another user", URL: "/api/v0/console/filter/saved", Header: func() netHTTP.Header { @@ -320,7 +337,8 @@ LIMIT 20`, "6540"). return headers }(), JSONOutput: gin.H{"filters": []gin.H{}}, - }, { + }, + { Description: "delete stored filter as another user", Method: "DELETE", URL: "/api/v0/console/filter/saved/1", @@ -331,19 +349,22 @@ LIMIT 20`, "6540"). }(), StatusCode: 404, JSONOutput: gin.H{"message": "filter not found"}, - }, { + }, + { Description: "delete stored filter", Method: "DELETE", URL: "/api/v0/console/filter/saved/1", StatusCode: 204, ContentType: "application/json; charset=utf-8", - }, { + }, + { Description: "delete stored filter with invalid ID", Method: "DELETE", URL: "/api/v0/console/filter/saved/kjgdfhgh", StatusCode: 400, JSONOutput: gin.H{"message": "bad ID format"}, - }, { + }, + { Description: "list stored filter after delete", URL: "/api/v0/console/filter/saved", StatusCode: 200, diff --git a/console/graph_test.go b/console/graph_test.go index 0f37d06e..3556978f 100644 --- a/console/graph_test.go +++ b/console/graph_test.go @@ -20,8 +20,8 @@ import ( func TestGraphInputReverseDirection(t *testing.T) { input := graphHandlerInput{ schema: schema.NewMock(t), - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: query.Columns{ query.NewColumn("ExporterName"), @@ -32,8 +32,8 @@ func TestGraphInputReverseDirection(t *testing.T) { } original1 := fmt.Sprintf("%+v", input) expected := graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: query.Columns{ query.NewColumn("ExporterName"), @@ -147,8 +147,8 @@ func TestGraphQuerySQL(t *testing.T) { { Description: "no dimensions, no filters, bps", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.Filter{}, @@ -173,8 +173,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions, no filters, l2 bps", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.Filter{}, @@ -200,8 +200,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions, no filters, pps", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.Filter{}, @@ -226,8 +226,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.NewFilter("DstCountry = 'FR' AND SrcCountry = 'US'"), @@ -252,8 +252,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions, escaped filter", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.NewFilter("InIfDescription = '{{ hello }}' AND SrcCountry = 'US'"), @@ -278,8 +278,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions, reverse direction", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.NewFilter("DstCountry = 'FR' AND SrcCountry = 'US'"), @@ -321,8 +321,8 @@ ORDER BY time WITH FILL }, { Description: "no dimensions, reverse direction, inl2%", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Dimensions: []query.Column{}, Filter: query.NewFilter("DstCountry = 'FR' AND SrcCountry = 'US'"), @@ -364,8 +364,8 @@ ORDER BY time WITH FILL }, { Description: "no filters", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Limit: 20, Dimensions: []query.Column{ @@ -396,8 +396,8 @@ ORDER BY time WITH FILL }, { Description: "no filters, reverse", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Limit: 20, Dimensions: []query.Column{ @@ -445,8 +445,8 @@ ORDER BY time WITH FILL }, { Description: "no filters, previous period", Input: graphHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Points: 100, Limit: 20, Dimensions: []query.Column{ @@ -624,8 +624,8 @@ func TestGraphHandler(t *testing.T) { Description: "single direction", URL: "/api/v0/console/graph", JSONInput: gin.H{ - "start": time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - "end": time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + "start": time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, "dimensions": []string{"ExporterName", "InIfProvider"}, @@ -699,8 +699,8 @@ func TestGraphHandler(t *testing.T) { Description: "bidirectional", URL: "/api/v0/console/graph", JSONInput: gin.H{ - "start": time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - "end": time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + "start": time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, "dimensions": []string{"ExporterName", "InIfProvider"}, @@ -818,8 +818,8 @@ func TestGraphHandler(t *testing.T) { Description: "previous period", URL: "/api/v0/console/graph", JSONInput: gin.H{ - "start": time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - "end": time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + "start": time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "points": 100, "limit": 20, "dimensions": []string{"ExporterName", "InIfProvider"}, diff --git a/console/sankey_test.go b/console/sankey_test.go index dcb71dfe..154ff42d 100644 --- a/console/sankey_test.go +++ b/console/sankey_test.go @@ -25,11 +25,12 @@ func TestSankeyQuerySQL(t *testing.T) { { Description: "two dimensions, no filters, l3 bps", Input: sankeyHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Dimensions: []query.Column{ query.NewColumn("SrcAS"), - query.NewColumn("ExporterName")}, + query.NewColumn("ExporterName"), + }, Limit: 5, Filter: query.Filter{}, Units: "l3bps", @@ -51,11 +52,12 @@ ORDER BY xps DESC }, { Description: "two dimensions, no filters, l2 bps", Input: sankeyHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Dimensions: []query.Column{ query.NewColumn("SrcAS"), - query.NewColumn("ExporterName")}, + query.NewColumn("ExporterName"), + }, Limit: 5, Filter: query.Filter{}, Units: "l2bps", @@ -78,11 +80,12 @@ ORDER BY xps DESC }, { Description: "two dimensions, no filters, pps", Input: sankeyHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Dimensions: []query.Column{ query.NewColumn("SrcAS"), - query.NewColumn("ExporterName")}, + query.NewColumn("ExporterName"), + }, Limit: 5, Filter: query.Filter{}, Units: "pps", @@ -104,11 +107,12 @@ ORDER BY xps DESC }, { Description: "two dimensions, with filter", Input: sankeyHandlerInput{ - Start: time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + Start: time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + End: time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), Dimensions: []query.Column{ query.NewColumn("SrcAS"), - query.NewColumn("ExporterName")}, + query.NewColumn("ExporterName"), + }, Limit: 10, Filter: query.NewFilter("DstCountry = 'FR'"), Units: "l3bps", @@ -190,8 +194,8 @@ func TestSankeyHandler(t *testing.T) { { URL: "/api/v0/console/sankey", JSONInput: gin.H{ - "start": time.Date(2022, 04, 10, 15, 45, 10, 0, time.UTC), - "end": time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC), + "start": time.Date(2022, 4, 10, 15, 45, 10, 0, time.UTC), + "end": time.Date(2022, 4, 11, 15, 45, 10, 0, time.UTC), "dimensions": []string{"SrcAS", "InIfProvider", "ExporterName"}, "limit": 10, "filter": "DstCountry = 'FR'", @@ -260,54 +264,102 @@ func TestSankeyHandler(t *testing.T) { "ExporterName: router2", }, "links": []gin.H{ - {"source": "InIfProvider: provider1", "target": "ExporterName: Other", - "xps": 9472 + 7234 + 6006 + 5988}, - {"source": "InIfProvider: Other", "target": "ExporterName: router1", - "xps": 9677 + 3623 + 2915 + 1360}, - {"source": "SrcAS: AS100", "target": "InIfProvider: Other", - "xps": 9677}, - {"source": "SrcAS: AS300", "target": "InIfProvider: provider1", - "xps": 9472}, - {"source": "InIfProvider: provider3", "target": "ExporterName: Other", - "xps": 4675 + 3999}, - {"source": "SrcAS: AS100", "target": "InIfProvider: provider1", - "xps": 6006 + 2623}, - {"source": "SrcAS: AS100", "target": "InIfProvider: provider3", - "xps": 3999 + 3978}, - {"source": "InIfProvider: provider3", "target": "ExporterName: router2", - "xps": 3978 + 3080 + 717}, - {"source": "InIfProvider: provider2", "target": "ExporterName: router1", - "xps": 7593}, - {"source": "SrcAS: AS300", "target": "InIfProvider: provider2", - "xps": 7593}, - {"source": "SrcAS: AS200", "target": "InIfProvider: provider1", - "xps": 7234}, - {"source": "SrcAS: Other", "target": "InIfProvider: provider1", - "xps": 5988 + 159}, - {"source": "SrcAS: AS200", "target": "InIfProvider: Other", - "xps": 4348 + 1360}, - {"source": "SrcAS: AS200", "target": "InIfProvider: provider3", - "xps": 4675 + 717}, - {"source": "InIfProvider: Other", "target": "ExporterName: router2", - "xps": 4348}, - {"source": "SrcAS: Other", "target": "InIfProvider: Other", - "xps": 3623 + 621}, - {"source": "SrcAS: AS300", "target": "InIfProvider: Other", - "xps": 2915 + 975}, - {"source": "SrcAS: AS300", "target": "InIfProvider: provider3", - "xps": 3080}, - {"source": "InIfProvider: provider1", "target": "ExporterName: router1", - "xps": 2623 + 159}, - {"source": "InIfProvider: provider2", "target": "ExporterName: router2", - "xps": 2482}, - {"source": "SrcAS: AS200", "target": "InIfProvider: provider2", - "xps": 2482}, - {"source": "InIfProvider: provider2", "target": "ExporterName: Other", - "xps": 2234}, - {"source": "SrcAS: AS100", "target": "InIfProvider: provider2", - "xps": 2234}, - {"source": "InIfProvider: Other", "target": "ExporterName: Other", - "xps": 975 + 621}, + { + "source": "InIfProvider: provider1", "target": "ExporterName: Other", + "xps": 9472 + 7234 + 6006 + 5988, + }, + { + "source": "InIfProvider: Other", "target": "ExporterName: router1", + "xps": 9677 + 3623 + 2915 + 1360, + }, + { + "source": "SrcAS: AS100", "target": "InIfProvider: Other", + "xps": 9677, + }, + { + "source": "SrcAS: AS300", "target": "InIfProvider: provider1", + "xps": 9472, + }, + { + "source": "InIfProvider: provider3", "target": "ExporterName: Other", + "xps": 4675 + 3999, + }, + { + "source": "SrcAS: AS100", "target": "InIfProvider: provider1", + "xps": 6006 + 2623, + }, + { + "source": "SrcAS: AS100", "target": "InIfProvider: provider3", + "xps": 3999 + 3978, + }, + { + "source": "InIfProvider: provider3", "target": "ExporterName: router2", + "xps": 3978 + 3080 + 717, + }, + { + "source": "InIfProvider: provider2", "target": "ExporterName: router1", + "xps": 7593, + }, + { + "source": "SrcAS: AS300", "target": "InIfProvider: provider2", + "xps": 7593, + }, + { + "source": "SrcAS: AS200", "target": "InIfProvider: provider1", + "xps": 7234, + }, + { + "source": "SrcAS: Other", "target": "InIfProvider: provider1", + "xps": 5988 + 159, + }, + { + "source": "SrcAS: AS200", "target": "InIfProvider: Other", + "xps": 4348 + 1360, + }, + { + "source": "SrcAS: AS200", "target": "InIfProvider: provider3", + "xps": 4675 + 717, + }, + { + "source": "InIfProvider: Other", "target": "ExporterName: router2", + "xps": 4348, + }, + { + "source": "SrcAS: Other", "target": "InIfProvider: Other", + "xps": 3623 + 621, + }, + { + "source": "SrcAS: AS300", "target": "InIfProvider: Other", + "xps": 2915 + 975, + }, + { + "source": "SrcAS: AS300", "target": "InIfProvider: provider3", + "xps": 3080, + }, + { + "source": "InIfProvider: provider1", "target": "ExporterName: router1", + "xps": 2623 + 159, + }, + { + "source": "InIfProvider: provider2", "target": "ExporterName: router2", + "xps": 2482, + }, + { + "source": "SrcAS: AS200", "target": "InIfProvider: provider2", + "xps": 2482, + }, + { + "source": "InIfProvider: provider2", "target": "ExporterName: Other", + "xps": 2234, + }, + { + "source": "SrcAS: AS100", "target": "InIfProvider: provider2", + "xps": 2234, + }, + { + "source": "InIfProvider: Other", "target": "ExporterName: Other", + "xps": 975 + 621, + }, }, }, }, diff --git a/console/widgets_test.go b/console/widgets_test.go index 74a72ad1..e1aa949f 100644 --- a/console/widgets_test.go +++ b/console/widgets_test.go @@ -195,28 +195,36 @@ func TestWidgetTop(t *testing.T) { "top": []gin.H{ {"name": "TCP/443", "percent": 51}, {"name": "UDP/443", "percent": 20}, - {"name": "TCP/80", "percent": 18}}}, + {"name": "TCP/80", "percent": 18}, + }, + }, }, { URL: "/api/v0/console/widget/top/protocol", JSONOutput: gin.H{ "top": []gin.H{ {"name": "TCP", "percent": 75}, {"name": "UDP", "percent": 24}, - {"name": "ESP", "percent": 1}}}, + {"name": "ESP", "percent": 1}, + }, + }, }, { URL: "/api/v0/console/widget/top/exporter", JSONOutput: gin.H{ "top": []gin.H{ {"name": "exporter1", "percent": 20}, {"name": "exporter3", "percent": 10}, - {"name": "exporter5", "percent": 3}}}, + {"name": "exporter5", "percent": 3}, + }, + }, }, { URL: "/api/v0/console/widget/top/src-as", JSONOutput: gin.H{ "top": []gin.H{ {"name": "2906: Netflix", "percent": 12}, {"name": "36040: Youtube", "percent": 10}, - {"name": "20940: Akamai", "percent": 9}}}, + {"name": "20940: Akamai", "percent": 9}, + }, + }, }, }) } @@ -263,9 +271,9 @@ ORDER BY Time WITH FILL {"t": "2009-11-10T23:02:00Z", "gbps": 26.4}, {"t": "2009-11-10T23:03:00Z", "gbps": 29.2}, {"t": "2009-11-10T23:04:00Z", "gbps": 0}, - {"t": "2009-11-10T23:05:00Z", "gbps": 24.7}}, + {"t": "2009-11-10T23:05:00Z", "gbps": 24.7}, + }, }, }, }) - } diff --git a/demoexporter/config.go b/demoexporter/config.go index 62767d33..e1713a6d 100644 --- a/demoexporter/config.go +++ b/demoexporter/config.go @@ -4,8 +4,7 @@ package demoexporter // Configuration describes the configuration for the demo exporter component. -type Configuration struct { -} +type Configuration struct{} // DefaultConfiguration represents the default configuration for the demo exporter component. func DefaultConfiguration() Configuration { diff --git a/demoexporter/flows/nfdata_test.go b/demoexporter/flows/nfdata_test.go index 96b0da9a..5e1c9d93 100644 --- a/demoexporter/flows/nfdata_test.go +++ b/demoexporter/flows/nfdata_test.go @@ -25,12 +25,13 @@ func TestGetNetflowData(t *testing.T) { context.Background(), 50, 30000, - time.Date(2022, 03, 15, 14, 33, 0, 0, time.UTC), - time.Date(2022, 03, 15, 15, 33, 0, 0, time.UTC)) + time.Date(2022, 3, 15, 14, 33, 0, 0, time.UTC), + time.Date(2022, 3, 15, 15, 33, 0, 0, time.UTC)) got := []interface{}{} for payload := range ch { got = append(got, nfdecoder.Decode(decoder.RawFlow{ - Payload: payload, Source: net.ParseIP("127.0.0.1")})) + Payload: payload, Source: net.ParseIP("127.0.0.1"), + })) } ch = getNetflowData( @@ -93,11 +94,12 @@ func TestGetNetflowData(t *testing.T) { }, }, 100, - time.Date(2022, 03, 15, 14, 33, 0, 0, time.UTC), - time.Date(2022, 03, 15, 16, 33, 0, 0, time.UTC)) + time.Date(2022, 3, 15, 14, 33, 0, 0, time.UTC), + time.Date(2022, 3, 15, 16, 33, 0, 0, time.UTC)) for payload := range ch { got = append(got, nfdecoder.Decode(decoder.RawFlow{ - Payload: payload, Source: net.ParseIP("127.0.0.1")})) + Payload: payload, Source: net.ParseIP("127.0.0.1"), + })) } expected := []interface{}{ []interface{}{}, // templates diff --git a/demoexporter/snmp/server_test.go b/demoexporter/snmp/server_test.go index 367f4b2d..572e7e7d 100644 --- a/demoexporter/snmp/server_test.go +++ b/demoexporter/snmp/server_test.go @@ -95,5 +95,4 @@ func TestSNMPServer(t *testing.T) { if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" { t.Fatalf("Metrics (-got, +want):\n%s", diff) } - } diff --git a/inlet/bmp/rib_test.go b/inlet/bmp/rib_test.go index c15393c9..37a89e04 100644 --- a/inlet/bmp/rib_test.go +++ b/inlet/bmp/rib_test.go @@ -46,79 +46,98 @@ func TestRTAEqual(t *testing.T) { routeAttributes{asn: 2038, asPath: []uint32{}}, routeAttributes{asn: 2038}, true, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{}}, routeAttributes{asn: 2039}, false, - }, { + }, + { routeAttributes{asn: 2038, communities: []uint32{}}, routeAttributes{asn: 2038}, true, - }, { + }, + { routeAttributes{asn: 2038, communities: []uint32{}}, routeAttributes{asn: 2039}, false, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{}}, routeAttributes{asn: 2038}, true, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{}}, routeAttributes{asn: 2039}, false, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3}}, true, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4}}, false, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 0}}, false, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 4}}, false, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4}}, true, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}}, true, - }, { + }, + { routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34}}, routeAttributes{asn: 2038, asPath: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35}}, false, - }, { + }, + { routeAttributes{asn: 2038, communities: []uint32{100, 200, 300, 400}}, routeAttributes{asn: 2038, communities: []uint32{100, 200, 300, 400}}, true, - }, { + }, + { routeAttributes{asn: 2038, communities: []uint32{100, 200, 300, 400}}, routeAttributes{asn: 2038, communities: []uint32{100, 200, 300, 402}}, false, - }, { + }, + { routeAttributes{asn: 2038, communities: []uint32{100, 200, 300}}, routeAttributes{asn: 2038, communities: []uint32{100, 200, 300, 400}}, false, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, true, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 8}}}, false, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 4}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, false, - }, { + }, + { routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}}}, routeAttributes{asn: 2038, largeCommunities: []bgp.LargeCommunity{{ASN: 1, LocalData1: 2, LocalData2: 3}, {ASN: 3, LocalData1: 4, LocalData2: 5}, {ASN: 5, LocalData1: 6, LocalData2: 7}}}, false, diff --git a/inlet/bmp/root_test.go b/inlet/bmp/root_test.go index aacbeb15..5260c24b 100644 --- a/inlet/bmp/root_test.go +++ b/inlet/bmp/root_test.go @@ -1004,7 +1004,6 @@ func TestBMP(t *testing.T) { if diff := helpers.Diff(gotRIB, expectedRIB); diff != "" { t.Errorf("RIB (-got, +want):\n%s", diff) } - }) t.Run("init, peers up, eor, reach NLRI, conn down, immediate timeout", func(t *testing.T) { diff --git a/inlet/core/classifier.go b/inlet/core/classifier.go index b0ccfa10..d3c08fb8 100644 --- a/inlet/core/classifier.go +++ b/inlet/core/classifier.go @@ -40,8 +40,10 @@ type exporterClassification struct { Tenant string } -type classifyStringFunc = func(string) bool -type classifyStringRegexFunc = func(string, string, string) (bool, error) +type ( + classifyStringFunc = func(string) bool + classifyStringRegexFunc = func(string, string, string) (bool, error) +) // exporterClassifierEnvironment defines the environment used by the exporter classifier type exporterClassifierEnvironment struct { diff --git a/inlet/flow/decoder/netflow/root.go b/inlet/flow/decoder/netflow/root.go index 93115a4c..553b442c 100644 --- a/inlet/flow/decoder/netflow/root.go +++ b/inlet/flow/decoder/netflow/root.go @@ -150,7 +150,6 @@ func (nd *Decoder) Decode(in decoder.RawFlow) []*schema.FlowMessage { ts := uint64(in.TimeReceived.UTC().Unix()) buf := bytes.NewBuffer(in.Payload) msgDec, err := netflow.DecodeMessage(buf, templates) - if err != nil { switch err.(type) { case *netflow.ErrorTemplateNotFound: diff --git a/inlet/flow/decoder/sflow/root.go b/inlet/flow/decoder/sflow/root.go index 66a1ecb3..6676f19d 100644 --- a/inlet/flow/decoder/sflow/root.go +++ b/inlet/flow/decoder/sflow/root.go @@ -86,7 +86,6 @@ func (nd *Decoder) Decode(in decoder.RawFlow) []*schema.FlowMessage { ts := uint64(in.TimeReceived.UTC().Unix()) msgDec, err := sflow.DecodeMessage(buf) - if err != nil { switch err.(type) { case *sflow.ErrorVersion: diff --git a/inlet/flow/decoder/sflow/root_test.go b/inlet/flow/decoder/sflow/root_test.go index fe1baf86..f3b45437 100644 --- a/inlet/flow/decoder/sflow/root_test.go +++ b/inlet/flow/decoder/sflow/root_test.go @@ -302,7 +302,6 @@ func TestDecodeInterface(t *testing.T) { if diff := helpers.Diff(got, expectedFlows); diff != "" { t.Fatalf("Decode() (-got, +want):\n%s", diff) } - }) t.Run("flow sample with IPv4 data", func(t *testing.T) { @@ -338,6 +337,5 @@ func TestDecodeInterface(t *testing.T) { if diff := helpers.Diff(got, expectedFlows); diff != "" { t.Fatalf("Decode() (-got, +want):\n%s", diff) } - }) } diff --git a/inlet/flow/input/udp/socket.go b/inlet/flow/input/udp/socket.go index c654f9b6..e13b90ef 100644 --- a/inlet/flow/input/udp/socket.go +++ b/inlet/flow/input/udp/socket.go @@ -16,21 +16,19 @@ type oobMessage struct { Received time.Time } -var ( - // listenConfig configures a listening socket to reuse port and return overflows - listenConfig = net.ListenConfig{ - Control: func(network, address string, c syscall.RawConn) error { - var err error - c.Control(func(fd uintptr) { - opts := udpSocketOptions - for _, opt := range opts { - err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, opt, 1) - if err != nil { - return - } +// listenConfig configures a listening socket to reuse port and return overflows +var listenConfig = net.ListenConfig{ + Control: func(network, address string, c syscall.RawConn) error { + var err error + c.Control(func(fd uintptr) { + opts := udpSocketOptions + for _, opt := range opts { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, opt, 1) + if err != nil { + return } - }) - return err - }, - } -) + } + }) + return err + }, +} diff --git a/inlet/flow/root.go b/inlet/flow/root.go index a74e8c3c..706069f4 100644 --- a/inlet/flow/root.go +++ b/inlet/flow/root.go @@ -65,7 +65,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende } // Initialize decoders (at most once each) - var alreadyInitialized = map[string]decoder.Decoder{} + alreadyInitialized := map[string]decoder.Decoder{} decs := make([]decoder.Decoder, len(configuration.Inputs)) for idx, input := range c.config.Inputs { dec, ok := alreadyInitialized[input.Decoder] diff --git a/inlet/flow/root_test.go b/inlet/flow/root_test.go index a9af0c48..a867bf54 100644 --- a/inlet/flow/root_test.go +++ b/inlet/flow/root_test.go @@ -32,7 +32,7 @@ func TestFlow(t *testing.T) { "data-260.pcap", "data-260.pcap", "data-260.pcap", "data-260.pcap", } { outFile := path.Join(outDir, fmt.Sprintf("data-%d", idx)) - err := os.WriteFile(outFile, helpers.ReadPcapPayload(t, path.Join(base, f)), 0666) + err := os.WriteFile(outFile, helpers.ReadPcapPayload(t, path.Join(base, f)), 0o666) if err != nil { t.Fatalf("WriteFile(%q) error:\n%+v", outFile, err) } diff --git a/inlet/snmp/cache_test.go b/inlet/snmp/cache_test.go index 9a5d5590..c3b8d740 100644 --- a/inlet/snmp/cache_test.go +++ b/inlet/snmp/cache_test.go @@ -65,7 +65,8 @@ func TestSimpleLookup(t *testing.T) { sc.Put(time.Now(), netip.MustParseAddr("::ffff:127.0.0.1"), "localhost", 676, Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000}) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{ ExporterName: "localhost", - Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000}, + }) expectCacheLookup(t, sc, "127.0.0.1", 787, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.2", 676, answer{NOk: true}) @@ -93,27 +94,33 @@ func TestExpire(t *testing.T) { sc.Expire(now.Add(-time.Hour)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{ ExporterName: "localhost", - Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}, + }) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{ ExporterName: "localhost2", - Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) + Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}, + }) expectCacheLookup(t, sc, "127.0.0.2", 678, answer{ ExporterName: "localhost3", - Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}, + }) sc.Expire(now.Add(-29 * time.Minute)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{ ExporterName: "localhost2", - Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) + Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}, + }) expectCacheLookup(t, sc, "127.0.0.2", 678, answer{ ExporterName: "localhost3", - Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}, + }) sc.Expire(now.Add(-19 * time.Minute)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.2", 678, answer{ ExporterName: "localhost3", - Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}, + }) sc.Expire(now.Add(-9 * time.Minute)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{NOk: true}) @@ -123,7 +130,8 @@ func TestExpire(t *testing.T) { sc.Expire(now.Add(-19 * time.Minute)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{ ExporterName: "localhost", - Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}, + }) gotMetrics := r.GetMetrics("akvorado_inlet_snmp_cache_") expectedMetrics := map[string]string{ @@ -154,11 +162,13 @@ func TestExpireRefresh(t *testing.T) { sc.Expire(now.Add(-29 * time.Minute)) expectCacheLookup(t, sc, "127.0.0.1", 676, answer{ ExporterName: "localhost", - Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "Transit"}, + }) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.2", 678, answer{ ExporterName: "localhost2", - Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "IX"}, + }) } func TestNeedUpdates(t *testing.T) { @@ -244,10 +254,12 @@ func TestSaveLoad(t *testing.T) { expectCacheLookup(t, sc, "127.0.0.1", 676, answer{NOk: true}) expectCacheLookup(t, sc, "127.0.0.1", 678, answer{ ExporterName: "localhost", - Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) + Interface: Interface{Name: "Gi0/0/0/2", Description: "Peering"}, + }) expectCacheLookup(t, sc, "127.0.0.2", 678, answer{ ExporterName: "localhost2", - Interface: Interface{Name: "Gi0/0/0/1", Description: "IX", Speed: 1000}}) + Interface: Interface{Name: "Gi0/0/0/1", Description: "IX", Speed: 1000}, + }) } func TestConcurrentOperations(t *testing.T) { diff --git a/inlet/snmp/poller.go b/inlet/snmp/poller.go index 5a69dbaf..8ab0a374 100644 --- a/inlet/snmp/poller.go +++ b/inlet/snmp/poller.go @@ -271,6 +271,7 @@ func (l *goSNMPLogger) Print(v ...interface{}) { e.Msg(fmt.Sprint(v...)) } } + func (l *goSNMPLogger) Printf(format string, v ...interface{}) { if e := l.r.Debug(); e.Enabled() { e.Msg(fmt.Sprintf(format, v...)) diff --git a/inlet/snmp/root_test.go b/inlet/snmp/root_test.go index 3070843f..6a10c3da 100644 --- a/inlet/snmp/root_test.go +++ b/inlet/snmp/root_test.go @@ -211,7 +211,6 @@ func TestCoalescing(t *testing.T) { expectSNMPLookup(t, c, "127.0.0.1", 767, answer{NOk: true}) expectSNMPLookup(t, c, "127.0.0.1", 768, answer{NOk: true}) expectSNMPLookup(t, c, "127.0.0.1", 769, answer{NOk: true}) - }) gotMetrics := r.GetMetrics("akvorado_inlet_snmp_poller_", "coalesced_count") diff --git a/orchestrator/clickhouse/http.go b/orchestrator/clickhouse/http.go index 039297c3..907ad2a7 100644 --- a/orchestrator/clickhouse/http.go +++ b/orchestrator/clickhouse/http.go @@ -106,8 +106,10 @@ func (c *Component) registerHTTPHandlers() error { defer c.networkSourcesLock.RUnlock() for _, ss := range c.networkSources { for _, v := range ss { - wr.Write([]string{v.Prefix.String(), - v.Name, v.Role, v.Site, v.Region, v.Tenant}) + wr.Write([]string{ + v.Prefix.String(), + v.Name, v.Role, v.Site, v.Region, v.Tenant, + }) } } if c.config.Networks != nil { diff --git a/orchestrator/clickhouse/http_test.go b/orchestrator/clickhouse/http_test.go index 41ae8d85..14036538 100644 --- a/orchestrator/clickhouse/http_test.go +++ b/orchestrator/clickhouse/http_test.go @@ -217,5 +217,4 @@ func TestNetworkSources(t *testing.T) { if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" { t.Fatalf("Metrics (-got, +want):\n%s", diff) } - } diff --git a/orchestrator/config.go b/orchestrator/config.go index d24e7bfa..de872875 100644 --- a/orchestrator/config.go +++ b/orchestrator/config.go @@ -4,8 +4,7 @@ package orchestrator // Configuration describes the configuration for the broker. -type Configuration struct { -} +type Configuration struct{} // DefaultConfiguration represents the default configuration for the broker. func DefaultConfiguration() Configuration { diff --git a/orchestrator/kafka/functional_test.go b/orchestrator/kafka/functional_test.go index 1cd9ebee..e5b297f0 100644 --- a/orchestrator/kafka/functional_test.go +++ b/orchestrator/kafka/functional_test.go @@ -88,7 +88,6 @@ func TestTopicCreation(t *testing.T) { } }) } - } func TestTopicMorePartitions(t *testing.T) {