chore: make a run of gofumpt

This commit is contained in:
Vincent Bernat
2025-08-05 06:21:19 +02:00
parent 209cbe0d61
commit 98eb1bdba5
32 changed files with 173 additions and 123 deletions

View File

@@ -42,5 +42,4 @@ func TestDemoExporter(t *testing.T) {
if diff := helpers.Diff(got, want); diff != "" { if diff := helpers.Diff(got, want); diff != "" {
t.Fatalf("`demo-exporter` (-got, +want):\n%s", diff) t.Fatalf("`demo-exporter` (-got, +want):\n%s", diff)
} }
} }

View File

@@ -216,9 +216,7 @@ func orchestratorGeoIPMigrationHook() mapstructure.DecodeHookFunc {
return from.Interface(), nil return from.Interface(), nil
} }
var ( var inletKey, geoIPKey, inletGeoIPValue *reflect.Value
inletKey, geoIPKey, inletGeoIPValue *reflect.Value
)
fromKeys := from.MapKeys() fromKeys := from.MapKeys()
for i, k := range fromKeys { for i, k := range fromKeys {

View File

@@ -35,7 +35,6 @@ type Dependencies struct {
// New creates a new ClickHouse wrapper // New creates a new ClickHouse wrapper
func New(r *reporter.Reporter, config Configuration, dependencies Dependencies) (*Component, error) { func New(r *reporter.Reporter, config Configuration, dependencies Dependencies) (*Component, error) {
tlsConfig, err := config.TLS.MakeTLSConfig() tlsConfig, err := config.TLS.MakeTLSConfig()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -35,7 +35,8 @@ func TestTransformQueryOnCluster(t *testing.T) {
"ALTER TABLE 02577_keepermap_delete_update ON CLUSTER akvorado UPDATE value2 = value2 * 10 + 2 WHERE value2 < 100", "ALTER TABLE 02577_keepermap_delete_update ON CLUSTER akvorado UPDATE value2 = value2 * 10 + 2 WHERE value2 < 100",
}, },
{ {
helpers.Mark(), "ATTACH DICTIONARY db_01018.dict1", "ATTACH DICTIONARY db_01018.dict1 ON CLUSTER akvorado"}, helpers.Mark(), "ATTACH DICTIONARY db_01018.dict1", "ATTACH DICTIONARY db_01018.dict1 ON CLUSTER akvorado",
},
{ {
helpers.Mark(), helpers.Mark(),
`CREATE DICTIONARY default.asns `CREATE DICTIONARY default.asns

View File

@@ -4,14 +4,14 @@
package kafka package kafka
import ( import (
"akvorado/common/helpers"
"akvorado/common/reporter"
"context" "context"
"fmt" "fmt"
"testing" "testing"
"time" "time"
"akvorado/common/helpers"
"akvorado/common/reporter"
"github.com/twmb/franz-go/pkg/kgo" "github.com/twmb/franz-go/pkg/kgo"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials" "golang.org/x/oauth2/clientcredentials"

View File

@@ -471,7 +471,6 @@ func TestUndoArrayUInt32(t *testing.T) {
t.Errorf("DstASPath column after undo (-got, +want):\n%s", diff) t.Errorf("DstASPath column after undo (-got, +want):\n%s", diff)
} }
}) })
} }
func TestUndoArrayUInt128(t *testing.T) { func TestUndoArrayUInt128(t *testing.T) {

View File

@@ -193,5 +193,4 @@ func TestInsertMemory(t *testing.T) {
t.Errorf("Insert (-got, +want):\n%s", diff) t.Errorf("Insert (-got, +want):\n%s", diff)
} }
} }
} }

View File

@@ -108,7 +108,6 @@ func TestCustomDictionaries(t *testing.T) {
if !dstRoleFound { if !dstRoleFound {
t.Fatal("DstAddrRole not found") t.Fatal("DstAddrRole not found")
} }
} }
func TestCustomDictionariesMatcher(t *testing.T) { func TestCustomDictionariesMatcher(t *testing.T) {

View File

@@ -154,7 +154,8 @@ func (c *current) parsePrefix(direction string) ([]any, error) {
if col.ClickHouseMaterialized { if col.ClickHouseMaterialized {
return []any{ return []any{
fmt.Sprintf("%sNetPrefix", direction), "=", fmt.Sprintf("%sNetPrefix", direction), "=",
fmt.Sprintf("'%s'", net.String())}, nil fmt.Sprintf("'%s'", net.String()),
}, nil
} }
// If the prefix is not materialized, we use the "between" operator // If the prefix is not materialized, we use the "between" operator
c.globalStore["meta"].(*Meta).MainTableRequired = true c.globalStore["meta"].(*Meta).MainTableRequired = true

View File

@@ -57,7 +57,8 @@ func (input graphSankeyHandlerInput) toSQL() (string, error) {
// With // With
with := []string{ with := []string{
fmt.Sprintf("source AS (%s)", input.sourceSelect()), fmt.Sprintf("source AS (%s)", input.sourceSelect()),
fmt.Sprintf(`(SELECT MAX(TimeReceived) - MIN(TimeReceived) FROM source WHERE %s) AS range`, where)} fmt.Sprintf(`(SELECT MAX(TimeReceived) - MIN(TimeReceived) FROM source WHERE %s) AS range`, where),
}
with = append(with, selectSankeyRowsByLimitType(input, dimensions, where)) with = append(with, selectSankeyRowsByLimitType(input, dimensions, where))
sqlQuery := fmt.Sprintf(` sqlQuery := fmt.Sprintf(`

View File

@@ -59,7 +59,8 @@ func TestDecodeConfiguration(t *testing.T) {
UseSrcAddrForExporterAddr: false, UseSrcAddrForExporterAddr: false,
}}, }},
}, },
}, { },
{
Description: "from existing configuration", Description: "from existing configuration",
Initial: func() any { Initial: func() any {
return Configuration{ return Configuration{
@@ -106,7 +107,8 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}}, }},
}, },
}, { },
{
Description: "change type", Description: "change type",
Initial: func() any { Initial: func() any {
return Configuration{ return Configuration{
@@ -134,7 +136,8 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}}, }},
}, },
}, { },
{
Description: "only set one item", Description: "only set one item",
Initial: func() any { Initial: func() any {
return Configuration{ return Configuration{
@@ -168,7 +171,8 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}}, }},
}, },
}, { },
{
Description: "incorrect decoder", Description: "incorrect decoder",
Initial: func() any { Initial: func() any {
return Configuration{} return Configuration{}

View File

@@ -52,7 +52,6 @@ func TestUDPInput(t *testing.T) {
} }
close(done) close(done)
} }
in, err := configuration.New(r, daemon.NewMock(t), send) in, err := configuration.New(r, daemon.NewMock(t), send)

View File

@@ -15,14 +15,12 @@ import (
"time" "time"
) )
var ( //go:embed data/protocols.csv
//go:embed data/protocols.csv //go:embed data/icmp.csv
//go:embed data/icmp.csv //go:embed data/asns.csv
//go:embed data/asns.csv //go:embed data/tcp.csv
//go:embed data/tcp.csv //go:embed data/udp.csv
//go:embed data/udp.csv var data embed.FS
data embed.FS
)
func (c *Component) addHandlerEmbedded(url string, path string) { func (c *Component) addHandlerEmbedded(url string, path string) {
c.d.HTTP.AddHandler(url, c.d.HTTP.AddHandler(url,

View File

@@ -447,7 +447,6 @@ func TestCustomDictMigration(t *testing.T) {
Layout: "complex_key_hashed", Layout: "complex_key_hashed",
} }
sch, err := schema.New(schConfig) sch, err := schema.New(schConfig)
if err != nil { if err != nil {
t.Fatalf("schema.New() error:\n%+v", err) t.Fatalf("schema.New() error:\n%+v", err)
} }
@@ -521,7 +520,6 @@ SETTINGS(format_csv_allow_single_quotes = 0)`
// Next test: with the custom dict removed again, the cols should still exist, but the consumer should be gone // Next test: with the custom dict removed again, the cols should still exist, but the consumer should be gone
r := reporter.NewMock(t) r := reporter.NewMock(t)
sch, err := schema.New(schema.DefaultConfiguration()) sch, err := schema.New(schema.DefaultConfiguration())
if err != nil { if err != nil {
t.Fatalf("schema.New() error:\n%+v", err) t.Fatalf("schema.New() error:\n%+v", err)
} }

View File

@@ -162,5 +162,4 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
t.Fatalf("Temporary files (-got, +want):\n%s", diff) t.Fatalf("Temporary files (-got, +want):\n%s", diff)
} }
}) })
} }

View File

@@ -32,15 +32,18 @@ func TestIterDatabase(t *testing.T) {
ExpectedCountry: "JP", ExpectedCountry: "JP",
ExpectedState: "Shimane", ExpectedState: "Shimane",
ExpectedCity: "Matsue", ExpectedCity: "Matsue",
}, { },
{
IP: "2.19.4.138", IP: "2.19.4.138",
ExpectedASN: 32787, ExpectedASN: 32787,
ExpectedCountry: "SG", ExpectedCountry: "SG",
}, { },
{
IP: "2a09:bac1:14a0:fd0::a:1", IP: "2a09:bac1:14a0:fd0::a:1",
ExpectedASN: 13335, ExpectedASN: 13335,
ExpectedCountry: "CA", ExpectedCountry: "CA",
}, { },
{
IP: "213.248.218.137", IP: "213.248.218.137",
ExpectedASN: 43519, ExpectedASN: 43519,
ExpectedCountry: "HK", ExpectedCountry: "HK",
@@ -49,15 +52,18 @@ func TestIterDatabase(t *testing.T) {
{ {
IP: "1.0.0.0", IP: "1.0.0.0",
ExpectedASN: 15169, ExpectedASN: 15169,
}, { },
{
IP: "2.125.160.216", IP: "2.125.160.216",
ExpectedCountry: "GB", ExpectedCountry: "GB",
ExpectedState: "ENG", ExpectedState: "ENG",
ExpectedCity: "Boxford", ExpectedCity: "Boxford",
}, { },
{
IP: "2a02:ff00::1:1", IP: "2a02:ff00::1:1",
ExpectedCountry: "IT", ExpectedCountry: "IT",
}, { },
{
IP: "67.43.156.77", IP: "67.43.156.77",
ExpectedASN: 35908, ExpectedASN: 35908,
ExpectedCountry: "BT", ExpectedCountry: "BT",

View File

@@ -62,7 +62,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "no rule, override sampling rate", Name: "no rule, override sampling rate",
Configuration: gin.H{"overridesamplingrate": gin.H{ Configuration: gin.H{"overridesamplingrate": gin.H{
"192.0.2.0/24": 100, "192.0.2.0/24": 100,
@@ -92,7 +93,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "no rule, no sampling rate, default is one value", Name: "no rule, no sampling rate, default is one value",
Configuration: gin.H{"defaultsamplingrate": 500}, Configuration: gin.H{"defaultsamplingrate": 500},
InputFlow: func() *schema.FlowMessage { InputFlow: func() *schema.FlowMessage {
@@ -117,7 +119,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "no rule, no sampling rate, default is map", Name: "no rule, no sampling rate, default is map",
Configuration: gin.H{"defaultsamplingrate": gin.H{ Configuration: gin.H{"defaultsamplingrate": gin.H{
"192.0.2.0/24": 100, "192.0.2.0/24": 100,
@@ -146,7 +149,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "exporter rule", Name: "exporter rule",
Configuration: gin.H{ Configuration: gin.H{
"exporterclassifiers": []string{ "exporterclassifiers": []string{
@@ -181,7 +185,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "exporter rule with an error", Name: "exporter rule with an error",
Configuration: gin.H{ Configuration: gin.H{
"exporterclassifiers": []string{ "exporterclassifiers": []string{
@@ -213,7 +218,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "exporter rule with reject", Name: "exporter rule with reject",
Configuration: gin.H{ Configuration: gin.H{
"exporterclassifiers": []string{ "exporterclassifiers": []string{
@@ -229,7 +235,8 @@ func TestEnrich(t *testing.T) {
} }
}, },
OutputFlow: nil, OutputFlow: nil,
}, { },
{
Name: "interface rule with reject", Name: "interface rule with reject",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -245,7 +252,8 @@ func TestEnrich(t *testing.T) {
} }
}, },
OutputFlow: nil, OutputFlow: nil,
}, { },
{
Name: "interface rule with index", Name: "interface rule with index",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -278,7 +286,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "interface rule with rename", Name: "interface rule with rename",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -309,7 +318,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "interface rule with VLAN", Name: "interface rule with VLAN",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -343,7 +353,8 @@ func TestEnrich(t *testing.T) {
schema.ColumnOutIfSpeed: 1000, schema.ColumnOutIfSpeed: 1000,
}, },
}, },
}, { },
{
Name: "interface rule", Name: "interface rule",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -380,7 +391,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
schema.ColumnOutIfBoundary: schema.InterfaceBoundaryInternal, schema.ColumnOutIfBoundary: schema.InterfaceBoundaryInternal,
}, },
}, },
}, { },
{
Name: "configure twice boundary", Name: "configure twice boundary",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -413,7 +425,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
schema.ColumnOutIfBoundary: 2, schema.ColumnOutIfBoundary: 2,
}, },
}, },
}, { },
{
Name: "configure twice provider", Name: "configure twice provider",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{
@@ -446,7 +459,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
schema.ColumnOutIfProvider: "telia", schema.ColumnOutIfProvider: "telia",
}, },
}, },
}, { },
{
Name: "classify depending on description", Name: "classify depending on description",
Configuration: gin.H{ Configuration: gin.H{
"interfaceclassifiers": []string{ "interfaceclassifiers": []string{

View File

@@ -356,5 +356,4 @@ func TestCore(t *testing.T) {
t.Fatalf("GET /api/v0/outlet/flows got less than 4 flows (%d)", count) t.Fatalf("GET /api/v0/outlet/flows got less than 4 flows (%d)", count)
} }
}) })
} }

View File

@@ -97,5 +97,4 @@ func (w *worker) processIncomingFlow(ctx context.Context, data []byte) error {
} }
return nil return nil
} }

View File

@@ -472,7 +472,6 @@ func TestDecodeICMP(t *testing.T) {
if diff := helpers.Diff(got, expectedFlows); diff != "" { if diff := helpers.Diff(got, expectedFlows); diff != "" {
t.Fatalf("Decode() (-got, +want):\n%s", diff) t.Fatalf("Decode() (-got, +want):\n%s", diff)
} }
} }
func TestDecodeDataLink(t *testing.T) { func TestDecodeDataLink(t *testing.T) {

View File

@@ -273,7 +273,6 @@ func TestFlowDecode(t *testing.T) {
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" { if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
t.Fatalf("Metrics (-got, +want):\n%s", diff) t.Fatalf("Metrics (-got, +want):\n%s", diff)
} }
}) })
} }

View File

@@ -85,7 +85,8 @@ func (c *Consumer) ProcessFetches(ctx context.Context, client *kgo.Client, fetch
client.MarkCommitOffsets(map[string]map[int32]kgo.EpochOffset{ client.MarkCommitOffsets(map[string]map[int32]kgo.EpochOffset{
topic.Topic: { topic.Topic: {
partition.Partition: kgo.EpochOffset{Epoch: epoch, Offset: offset}, partition.Partition: kgo.EpochOffset{Epoch: epoch, Offset: offset},
}}) },
})
}() }()
for _, record := range partition.Records { for _, record := range partition.Records {
epoch = record.LeaderEpoch epoch = record.LeaderEpoch

View File

@@ -72,7 +72,6 @@ func TestSimpleLookup(t *testing.T) {
IfIndex: 676, IfIndex: 676,
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000}, Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000},
}) })
@@ -105,7 +104,8 @@ func TestExpire(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -114,7 +114,8 @@ func TestExpire(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -123,32 +124,39 @@ func TestExpire(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost3"}, Exporter: provider.Exporter{Name: "localhost3"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Expire(now.Add(-time.Hour)) sc.Expire(now.Add(-time.Hour))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost3"}, Exporter: provider.Exporter{Name: "localhost3"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
sc.Expire(now.Add(-29 * time.Minute)) sc.Expire(now.Add(-29 * time.Minute))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost3"}, Exporter: provider.Exporter{Name: "localhost3"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
sc.Expire(now.Add(-19 * time.Minute)) sc.Expire(now.Add(-19 * time.Minute))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost3"}, Exporter: provider.Exporter{Name: "localhost3"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
sc.Expire(now.Add(-9 * time.Minute)) sc.Expire(now.Add(-9 * time.Minute))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{})
@@ -160,12 +168,14 @@ func TestExpire(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Expire(now.Add(-19 * time.Minute)) sc.Expire(now.Add(-19 * time.Minute))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
gotMetrics := r.GetMetrics("akvorado_outlet_metadata_cache_") gotMetrics := r.GetMetrics("akvorado_outlet_metadata_cache_")
expectedMetrics := map[string]string{ expectedMetrics := map[string]string{
@@ -189,7 +199,8 @@ func TestExpireRefresh(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -198,7 +209,8 @@ func TestExpireRefresh(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -207,7 +219,8 @@ func TestExpireRefresh(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
// Refresh first entry // Refresh first entry
@@ -220,11 +233,13 @@ func TestExpireRefresh(t *testing.T) {
sc.Expire(now.Add(-29 * time.Minute)) sc.Expire(now.Add(-29 * time.Minute))
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
} }
func TestNeedUpdates(t *testing.T) { func TestNeedUpdates(t *testing.T) {
@@ -237,7 +252,8 @@ func TestNeedUpdates(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -246,7 +262,8 @@ func TestNeedUpdates(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -255,7 +272,8 @@ func TestNeedUpdates(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
// Refresh // Refresh
sc.Put(now, sc.Put(now,
@@ -265,7 +283,8 @@ func TestNeedUpdates(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost1"}, Exporter: provider.Exporter{Name: "localhost1"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
cases := []struct { cases := []struct {
@@ -328,7 +347,8 @@ func TestSaveLoad(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -337,7 +357,8 @@ func TestSaveLoad(t *testing.T) {
}, },
provider.Answer{ provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
now = now.Add(10 * time.Minute) now = now.Add(10 * time.Minute)
sc.Put(now, sc.Put(now,
provider.Query{ provider.Query{
@@ -364,7 +385,8 @@ func TestSaveLoad(t *testing.T) {
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{}) expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost"}, Exporter: provider.Exporter{Name: "localhost"},
Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"}}) Interface: provider.Interface{Name: "Gi0/0/0/2", Description: "Peering"},
})
expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{ expectCacheLookup(t, sc, "127.0.0.2", 678, provider.Answer{
Exporter: provider.Exporter{Name: "localhost2"}, Exporter: provider.Exporter{Name: "localhost2"},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX", Speed: 1000}, Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX", Speed: 1000},
@@ -408,7 +430,8 @@ func TestConcurrentOperations(t *testing.T) {
IfIndex: uint(iface), IfIndex: uint(iface),
}, provider.Answer{ }, provider.Answer{
Exporter: provider.Exporter{Name: fmt.Sprintf("localhost%d", ip)}, Exporter: provider.Exporter{Name: fmt.Sprintf("localhost%d", ip)},
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"}}) Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit"},
})
select { select {
case <-done: case <-done:
return return

View File

@@ -768,8 +768,10 @@ commit now
got = append(got, formatUpdate(lo, "ethernet-1/3", answer)) got = append(got, formatUpdate(lo, "ethernet-1/3", answer))
answer, _ = p.Query(context.Background(), provider.Query{ExporterIP: lo, IfIndex: 5}) answer, _ = p.Query(context.Background(), provider.Query{ExporterIP: lo, IfIndex: 5})
got = append(got, formatUpdate(lo, "idx5", answer)) got = append(got, formatUpdate(lo, "idx5", answer))
answer, _ = p.Query(context.Background(), provider.Query{ExporterIP: lo, answer, _ = p.Query(context.Background(), provider.Query{
IfIndex: indexes["name=ethernet-1/4,index=1"]}) ExporterIP: lo,
IfIndex: indexes["name=ethernet-1/4,index=1"],
})
got = append(got, formatUpdate(lo, "ethernet-1/4,index=1", answer)) got = append(got, formatUpdate(lo, "ethernet-1/4,index=1", answer))
if diff := helpers.Diff(got, []string{ if diff := helpers.Diff(got, []string{
@@ -843,6 +845,5 @@ commit now
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" { if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
t.Errorf("Metrics (-got, +want):\n%s", diff) t.Errorf("Metrics (-got, +want):\n%s", diff)
} }
}) })
} }

View File

@@ -116,5 +116,4 @@ func TestConvertSpeed(t *testing.T) {
t.Errorf("convertSpeed(%q, %s) (-got, +want):\n%s", tc.Value, tc.Unit, diff) t.Errorf("convertSpeed(%q, %s) (-got, +want):\n%s", tc.Value, tc.Unit, diff)
} }
} }
} }

View File

@@ -13,11 +13,9 @@ import (
"akvorado/common/schema" "akvorado/common/schema"
) )
var ( // ErrSkipProvider is the error returned on lookup for providers unwilling to
// ErrSkipProvider is the error returned on lookup for providers unwilling to // handle a request.
// handle a request. var ErrSkipProvider = errors.New("provider skips query")
ErrSkipProvider = errors.New("provider skips query")
)
// Interface contains the information about an interface. // Interface contains the information about an interface.
type Interface struct { type Interface struct {

View File

@@ -146,85 +146,99 @@ func TestPoller(t *testing.T) {
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "exporter62", nil return "exporter62", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.2.2.1.2.641", OID: "1.3.6.1.2.1.2.2.1.2.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/0", nil return "Gi0/0/0/0", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.2.2.1.2.642", OID: "1.3.6.1.2.1.2.2.1.2.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/1", nil return "Gi0/0/0/1", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.2.2.1.2.643", OID: "1.3.6.1.2.1.2.2.1.2.643",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/2", nil return "Gi0/0/0/2", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.2.2.1.2.645", OID: "1.3.6.1.2.1.2.2.1.2.645",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Correct description", nil return "Correct description", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.1.641", OID: "1.3.6.1.2.1.31.1.1.1.1.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/0", nil return "Gi0/0/0/0", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.1.642", OID: "1.3.6.1.2.1.31.1.1.1.1.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/1", nil return "Gi0/0/0/1", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.1.643", OID: "1.3.6.1.2.1.31.1.1.1.1.643",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/2", nil return "Gi0/0/0/2", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.1.645", OID: "1.3.6.1.2.1.31.1.1.1.1.645",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Gi0/0/0/5", nil return "Gi0/0/0/5", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.15.641", OID: "1.3.6.1.2.1.31.1.1.1.15.641",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return uint(10000), nil return uint(10000), nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.15.642", OID: "1.3.6.1.2.1.31.1.1.1.15.642",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return uint(20000), nil return uint(20000), nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.15.643", OID: "1.3.6.1.2.1.31.1.1.1.15.643",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return uint(10000), nil return uint(10000), nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.15.645", OID: "1.3.6.1.2.1.31.1.1.1.15.645",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return uint(1000), nil return uint(1000), nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.18.641", OID: "1.3.6.1.2.1.31.1.1.1.18.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {
return "Transit", nil return "Transit", nil
}, },
}, { },
{
OID: "1.3.6.1.2.1.31.1.1.1.18.642", OID: "1.3.6.1.2.1.31.1.1.1.18.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (any, error) { OnGet: func() (any, error) {

View File

@@ -6,17 +6,16 @@
package static package static
import ( import (
"context"
"fmt"
"sync"
"sync/atomic"
"time" "time"
"akvorado/common/helpers" "akvorado/common/helpers"
"akvorado/common/remotedatasource" "akvorado/common/remotedatasource"
"akvorado/common/reporter" "akvorado/common/reporter"
"akvorado/outlet/metadata/provider" "akvorado/outlet/metadata/provider"
"context"
"fmt"
"sync"
"sync/atomic"
) )
// Provider represents the static provider. // Provider represents the static provider.

View File

@@ -188,7 +188,8 @@ func TestStaticProvider(t *testing.T) {
Description: "Default interface", Description: "Default interface",
Speed: 1000, Speed: 1000,
}, },
}, { },
{
Found: true, Found: true,
Exporter: provider.Exporter{ Exporter: provider.Exporter{
Name: "default", Name: "default",
@@ -198,7 +199,8 @@ func TestStaticProvider(t *testing.T) {
Description: "10th interface", Description: "10th interface",
Speed: 1000, Speed: 1000,
}, },
}, { },
{
Found: true, Found: true,
Exporter: provider.Exporter{ Exporter: provider.Exporter{
Name: "default", Name: "default",
@@ -208,7 +210,8 @@ func TestStaticProvider(t *testing.T) {
Description: "Default interface", Description: "Default interface",
Speed: 1000, Speed: 1000,
}, },
}, { },
{
Found: true, Found: true,
Exporter: provider.Exporter{ Exporter: provider.Exporter{
Name: "default with metadata", Name: "default with metadata",
@@ -226,7 +229,8 @@ func TestStaticProvider(t *testing.T) {
Connectivity: "transit", Connectivity: "transit",
Boundary: schema.InterfaceBoundaryExternal, Boundary: schema.InterfaceBoundaryExternal,
}, },
}, { },
{
Found: true, Found: true,
Exporter: provider.Exporter{ Exporter: provider.Exporter{
Name: "nodefault skip", Name: "nodefault skip",

View File

@@ -70,7 +70,6 @@ func TestInitStaticExporters(t *testing.T) {
} }
func TestRemoteExporterSources(t *testing.T) { func TestRemoteExporterSources(t *testing.T) {
// Mux to answer requests // Mux to answer requests
ready := make(chan bool) ready := make(chan bool)
mux := http.NewServeMux() mux := http.NewServeMux()

View File

@@ -55,10 +55,8 @@ type Dependencies struct {
Clock clock.Clock Clock clock.Clock
} }
var ( // ErrQueryTimeout is the error returned when a query timeout.
// ErrQueryTimeout is the error returned when a query timeout. var ErrQueryTimeout = errors.New("provider query timeout")
ErrQueryTimeout = errors.New("provider query timeout")
)
// New creates a new metadata component. // New creates a new metadata component.
func New(r *reporter.Reporter, configuration Configuration, dependencies Dependencies) (*Component, error) { func New(r *reporter.Reporter, configuration Configuration, dependencies Dependencies) (*Component, error) {
@@ -242,7 +240,6 @@ func (c *Component) queryProviders(query provider.Query) (provider.Answer, error
} }
return nil return nil
}) })
if err != nil { if err != nil {
c.metrics.providerErrors.Inc() c.metrics.providerErrors.Inc()
if err == breaker.ErrBreakerOpen { if err == breaker.ErrBreakerOpen {

View File

@@ -38,7 +38,8 @@ func TestLookup(t *testing.T) {
Exporter: provider.Exporter{ Exporter: provider.Exporter{
Name: "127_0_0_1", Name: "127_0_0_1",
}, },
Interface: provider.Interface{Name: "Gi0/0/765", Interface: provider.Interface{
Name: "Gi0/0/765",
Description: "Interface 765", Description: "Interface 765",
Speed: 1000, Speed: 1000,
}, },
@@ -53,7 +54,8 @@ func TestLookup(t *testing.T) {
Site: "metadata site", Site: "metadata site",
Tenant: "metadata tenant", Tenant: "metadata tenant",
}, },
Interface: provider.Interface{Name: "Gi0/0/1010", Interface: provider.Interface{
Name: "Gi0/0/1010",
Description: "Interface 1010", Description: "Interface 1010",
Speed: 1000, Speed: 1000,
}, },
@@ -68,7 +70,8 @@ func TestLookup(t *testing.T) {
Site: "metadata site", Site: "metadata site",
Tenant: "metadata tenant", Tenant: "metadata tenant",
}, },
Interface: provider.Interface{Name: "Gi0/0/2010", Interface: provider.Interface{
Name: "Gi0/0/2010",
Description: "Interface 2010", Description: "Interface 2010",
Speed: 1000, Speed: 1000,
Boundary: schema.InterfaceBoundaryExternal, Boundary: schema.InterfaceBoundaryExternal,
@@ -95,7 +98,8 @@ func TestComponentSaveLoad(t *testing.T) {
Name: "127_0_0_1", Name: "127_0_0_1",
}, },
Interface: provider.Interface{Name: "Gi0/0/765", Interface: provider.Interface{
Name: "Gi0/0/765",
Description: "Interface 765", Description: "Interface 765",
Speed: 1000, Speed: 1000,
}, },
@@ -154,7 +158,8 @@ func TestAutoRefresh(t *testing.T) {
Name: "127_0_0_1", Name: "127_0_0_1",
}, },
Interface: provider.Interface{Name: "Gi0/0/765", Interface: provider.Interface{
Name: "Gi0/0/765",
Description: "Interface 765", Description: "Interface 765",
Speed: 1000, Speed: 1000,
}, },