mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
chore: make a run of gofumpt
This commit is contained in:
@@ -42,5 +42,4 @@ func TestDemoExporter(t *testing.T) {
|
||||
if diff := helpers.Diff(got, want); diff != "" {
|
||||
t.Fatalf("`demo-exporter` (-got, +want):\n%s", diff)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -216,9 +216,7 @@ func orchestratorGeoIPMigrationHook() mapstructure.DecodeHookFunc {
|
||||
return from.Interface(), nil
|
||||
}
|
||||
|
||||
var (
|
||||
inletKey, geoIPKey, inletGeoIPValue *reflect.Value
|
||||
)
|
||||
var inletKey, geoIPKey, inletGeoIPValue *reflect.Value
|
||||
|
||||
fromKeys := from.MapKeys()
|
||||
for i, k := range fromKeys {
|
||||
|
||||
@@ -35,7 +35,6 @@ type Dependencies struct {
|
||||
// New creates a new ClickHouse wrapper
|
||||
func New(r *reporter.Reporter, config Configuration, dependencies Dependencies) (*Component, error) {
|
||||
tlsConfig, err := config.TLS.MakeTLSConfig()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
{
|
||||
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(),
|
||||
`CREATE DICTIONARY default.asns
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
package kafka
|
||||
|
||||
import (
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
|
||||
"github.com/twmb/franz-go/pkg/kgo"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/clientcredentials"
|
||||
|
||||
@@ -471,7 +471,6 @@ func TestUndoArrayUInt32(t *testing.T) {
|
||||
t.Errorf("DstASPath column after undo (-got, +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestUndoArrayUInt128(t *testing.T) {
|
||||
|
||||
@@ -193,5 +193,4 @@ func TestInsertMemory(t *testing.T) {
|
||||
t.Errorf("Insert (-got, +want):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,6 @@ func TestCustomDictionaries(t *testing.T) {
|
||||
if !dstRoleFound {
|
||||
t.Fatal("DstAddrRole not found")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCustomDictionariesMatcher(t *testing.T) {
|
||||
|
||||
@@ -154,7 +154,8 @@ func (c *current) parsePrefix(direction string) ([]any, error) {
|
||||
if col.ClickHouseMaterialized {
|
||||
return []any{
|
||||
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
|
||||
c.globalStore["meta"].(*Meta).MainTableRequired = true
|
||||
|
||||
@@ -57,7 +57,8 @@ func (input graphSankeyHandlerInput) toSQL() (string, error) {
|
||||
// With
|
||||
with := []string{
|
||||
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))
|
||||
|
||||
sqlQuery := fmt.Sprintf(`
|
||||
|
||||
@@ -59,7 +59,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
UseSrcAddrForExporterAddr: false,
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Description: "from existing configuration",
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
@@ -106,7 +107,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Description: "change type",
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
@@ -134,7 +136,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Description: "only set one item",
|
||||
Initial: func() any {
|
||||
return Configuration{
|
||||
@@ -168,7 +171,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||
},
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Description: "incorrect decoder",
|
||||
Initial: func() any {
|
||||
return Configuration{}
|
||||
|
||||
@@ -52,7 +52,6 @@ func TestUDPInput(t *testing.T) {
|
||||
}
|
||||
|
||||
close(done)
|
||||
|
||||
}
|
||||
|
||||
in, err := configuration.New(r, daemon.NewMock(t), send)
|
||||
|
||||
@@ -15,14 +15,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed data/protocols.csv
|
||||
//go:embed data/icmp.csv
|
||||
//go:embed data/asns.csv
|
||||
//go:embed data/tcp.csv
|
||||
//go:embed data/udp.csv
|
||||
data embed.FS
|
||||
)
|
||||
//go:embed data/protocols.csv
|
||||
//go:embed data/icmp.csv
|
||||
//go:embed data/asns.csv
|
||||
//go:embed data/tcp.csv
|
||||
//go:embed data/udp.csv
|
||||
var data embed.FS
|
||||
|
||||
func (c *Component) addHandlerEmbedded(url string, path string) {
|
||||
c.d.HTTP.AddHandler(url,
|
||||
|
||||
@@ -447,7 +447,6 @@ func TestCustomDictMigration(t *testing.T) {
|
||||
Layout: "complex_key_hashed",
|
||||
}
|
||||
sch, err := schema.New(schConfig)
|
||||
|
||||
if err != nil {
|
||||
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
|
||||
r := reporter.NewMock(t)
|
||||
sch, err := schema.New(schema.DefaultConfiguration())
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("schema.New() error:\n%+v", err)
|
||||
}
|
||||
|
||||
@@ -162,5 +162,4 @@ func TestNetworksCSVWithGeoip(t *testing.T) {
|
||||
t.Fatalf("Temporary files (-got, +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -32,15 +32,18 @@ func TestIterDatabase(t *testing.T) {
|
||||
ExpectedCountry: "JP",
|
||||
ExpectedState: "Shimane",
|
||||
ExpectedCity: "Matsue",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "2.19.4.138",
|
||||
ExpectedASN: 32787,
|
||||
ExpectedCountry: "SG",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "2a09:bac1:14a0:fd0::a:1",
|
||||
ExpectedASN: 13335,
|
||||
ExpectedCountry: "CA",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "213.248.218.137",
|
||||
ExpectedASN: 43519,
|
||||
ExpectedCountry: "HK",
|
||||
@@ -49,15 +52,18 @@ func TestIterDatabase(t *testing.T) {
|
||||
{
|
||||
IP: "1.0.0.0",
|
||||
ExpectedASN: 15169,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "2.125.160.216",
|
||||
ExpectedCountry: "GB",
|
||||
ExpectedState: "ENG",
|
||||
ExpectedCity: "Boxford",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "2a02:ff00::1:1",
|
||||
ExpectedCountry: "IT",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
IP: "67.43.156.77",
|
||||
ExpectedASN: 35908,
|
||||
ExpectedCountry: "BT",
|
||||
|
||||
@@ -62,7 +62,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "no rule, override sampling rate",
|
||||
Configuration: gin.H{"overridesamplingrate": gin.H{
|
||||
"192.0.2.0/24": 100,
|
||||
@@ -92,7 +93,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "no rule, no sampling rate, default is one value",
|
||||
Configuration: gin.H{"defaultsamplingrate": 500},
|
||||
InputFlow: func() *schema.FlowMessage {
|
||||
@@ -117,7 +119,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "no rule, no sampling rate, default is map",
|
||||
Configuration: gin.H{"defaultsamplingrate": gin.H{
|
||||
"192.0.2.0/24": 100,
|
||||
@@ -146,7 +149,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "exporter rule",
|
||||
Configuration: gin.H{
|
||||
"exporterclassifiers": []string{
|
||||
@@ -181,7 +185,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "exporter rule with an error",
|
||||
Configuration: gin.H{
|
||||
"exporterclassifiers": []string{
|
||||
@@ -213,7 +218,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "exporter rule with reject",
|
||||
Configuration: gin.H{
|
||||
"exporterclassifiers": []string{
|
||||
@@ -229,7 +235,8 @@ func TestEnrich(t *testing.T) {
|
||||
}
|
||||
},
|
||||
OutputFlow: nil,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "interface rule with reject",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -245,7 +252,8 @@ func TestEnrich(t *testing.T) {
|
||||
}
|
||||
},
|
||||
OutputFlow: nil,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "interface rule with index",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -278,7 +286,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "interface rule with rename",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -309,7 +318,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "interface rule with VLAN",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -343,7 +353,8 @@ func TestEnrich(t *testing.T) {
|
||||
schema.ColumnOutIfSpeed: 1000,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "interface rule",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -380,7 +391,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
schema.ColumnOutIfBoundary: schema.InterfaceBoundaryInternal,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "configure twice boundary",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -413,7 +425,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
schema.ColumnOutIfBoundary: 2,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "configure twice provider",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
@@ -446,7 +459,8 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
|
||||
schema.ColumnOutIfProvider: "telia",
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Name: "classify depending on description",
|
||||
Configuration: gin.H{
|
||||
"interfaceclassifiers": []string{
|
||||
|
||||
@@ -356,5 +356,4 @@ func TestCore(t *testing.T) {
|
||||
t.Fatalf("GET /api/v0/outlet/flows got less than 4 flows (%d)", count)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -97,5 +97,4 @@ func (w *worker) processIncomingFlow(ctx context.Context, data []byte) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
@@ -472,7 +472,6 @@ func TestDecodeICMP(t *testing.T) {
|
||||
if diff := helpers.Diff(got, expectedFlows); diff != "" {
|
||||
t.Fatalf("Decode() (-got, +want):\n%s", diff)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDecodeDataLink(t *testing.T) {
|
||||
|
||||
@@ -273,7 +273,6 @@ func TestFlowDecode(t *testing.T) {
|
||||
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
|
||||
t.Fatalf("Metrics (-got, +want):\n%s", diff)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,8 @@ func (c *Consumer) ProcessFetches(ctx context.Context, client *kgo.Client, fetch
|
||||
client.MarkCommitOffsets(map[string]map[int32]kgo.EpochOffset{
|
||||
topic.Topic: {
|
||||
partition.Partition: kgo.EpochOffset{Epoch: epoch, Offset: offset},
|
||||
}})
|
||||
},
|
||||
})
|
||||
}()
|
||||
for _, record := range partition.Records {
|
||||
epoch = record.LeaderEpoch
|
||||
|
||||
@@ -72,7 +72,6 @@ func TestSimpleLookup(t *testing.T) {
|
||||
IfIndex: 676,
|
||||
},
|
||||
provider.Answer{
|
||||
|
||||
Exporter: provider.Exporter{Name: "localhost"},
|
||||
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "Transit", Speed: 1000},
|
||||
})
|
||||
@@ -105,7 +104,8 @@ func TestExpire(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -114,7 +114,8 @@ func TestExpire(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -123,32 +124,39 @@ func TestExpire(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Expire(now.Add(-time.Hour))
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
|
||||
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{
|
||||
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{
|
||||
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))
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{
|
||||
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{
|
||||
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))
|
||||
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.2", 678, provider.Answer{
|
||||
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))
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{})
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 678, provider.Answer{})
|
||||
@@ -160,12 +168,14 @@ func TestExpire(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Expire(now.Add(-19 * time.Minute))
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
|
||||
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_")
|
||||
expectedMetrics := map[string]string{
|
||||
@@ -189,7 +199,8 @@ func TestExpireRefresh(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -198,7 +209,8 @@ func TestExpireRefresh(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -207,7 +219,8 @@ func TestExpireRefresh(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
|
||||
// Refresh first entry
|
||||
@@ -220,11 +233,13 @@ func TestExpireRefresh(t *testing.T) {
|
||||
sc.Expire(now.Add(-29 * time.Minute))
|
||||
expectCacheLookup(t, sc, "127.0.0.1", 676, provider.Answer{
|
||||
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.2", 678, provider.Answer{
|
||||
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) {
|
||||
@@ -237,7 +252,8 @@ func TestNeedUpdates(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -246,7 +262,8 @@ func TestNeedUpdates(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -255,7 +272,8 @@ func TestNeedUpdates(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
// Refresh
|
||||
sc.Put(now,
|
||||
@@ -265,7 +283,8 @@ func TestNeedUpdates(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
|
||||
cases := []struct {
|
||||
@@ -328,7 +347,8 @@ func TestSaveLoad(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
provider.Query{
|
||||
@@ -337,7 +357,8 @@ func TestSaveLoad(t *testing.T) {
|
||||
},
|
||||
provider.Answer{
|
||||
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)
|
||||
sc.Put(now,
|
||||
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", 678, provider.Answer{
|
||||
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{
|
||||
Exporter: provider.Exporter{Name: "localhost2"},
|
||||
Interface: provider.Interface{Name: "Gi0/0/0/1", Description: "IX", Speed: 1000},
|
||||
@@ -408,7 +430,8 @@ func TestConcurrentOperations(t *testing.T) {
|
||||
IfIndex: uint(iface),
|
||||
}, provider.Answer{
|
||||
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 {
|
||||
case <-done:
|
||||
return
|
||||
|
||||
@@ -768,8 +768,10 @@ commit now
|
||||
got = append(got, formatUpdate(lo, "ethernet-1/3", answer))
|
||||
answer, _ = p.Query(context.Background(), provider.Query{ExporterIP: lo, IfIndex: 5})
|
||||
got = append(got, formatUpdate(lo, "idx5", answer))
|
||||
answer, _ = p.Query(context.Background(), provider.Query{ExporterIP: lo,
|
||||
IfIndex: indexes["name=ethernet-1/4,index=1"]})
|
||||
answer, _ = p.Query(context.Background(), provider.Query{
|
||||
ExporterIP: lo,
|
||||
IfIndex: indexes["name=ethernet-1/4,index=1"],
|
||||
})
|
||||
got = append(got, formatUpdate(lo, "ethernet-1/4,index=1", answer))
|
||||
|
||||
if diff := helpers.Diff(got, []string{
|
||||
@@ -843,6 +845,5 @@ commit now
|
||||
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
|
||||
t.Errorf("Metrics (-got, +want):\n%s", diff)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -116,5 +116,4 @@ func TestConvertSpeed(t *testing.T) {
|
||||
t.Errorf("convertSpeed(%q, %s) (-got, +want):\n%s", tc.Value, tc.Unit, diff)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,11 +13,9 @@ import (
|
||||
"akvorado/common/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrSkipProvider is the error returned on lookup for providers unwilling to
|
||||
// handle a request.
|
||||
ErrSkipProvider = errors.New("provider skips query")
|
||||
)
|
||||
// ErrSkipProvider is the error returned on lookup for providers unwilling to
|
||||
// handle a request.
|
||||
var ErrSkipProvider = errors.New("provider skips query")
|
||||
|
||||
// Interface contains the information about an interface.
|
||||
type Interface struct {
|
||||
|
||||
@@ -146,85 +146,99 @@ func TestPoller(t *testing.T) {
|
||||
OnGet: func() (any, error) {
|
||||
return "exporter62", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/0", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/1", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.643",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/2", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.2.2.1.2.645",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Correct description", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/0", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/1", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.643",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/2", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.1.645",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Gi0/0/0/5", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.641",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (any, error) {
|
||||
return uint(10000), nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.642",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (any, error) {
|
||||
return uint(20000), nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.643",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (any, error) {
|
||||
return uint(10000), nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.15.645",
|
||||
Type: gosnmp.Gauge32,
|
||||
OnGet: func() (any, error) {
|
||||
return uint(1000), nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.18.641",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
return "Transit", nil
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
OID: "1.3.6.1.2.1.31.1.1.1.18.642",
|
||||
Type: gosnmp.OctetString,
|
||||
OnGet: func() (any, error) {
|
||||
|
||||
@@ -6,17 +6,16 @@
|
||||
package static
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/remotedatasource"
|
||||
"akvorado/common/reporter"
|
||||
"akvorado/outlet/metadata/provider"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// Provider represents the static provider.
|
||||
|
||||
@@ -188,7 +188,8 @@ func TestStaticProvider(t *testing.T) {
|
||||
Description: "Default interface",
|
||||
Speed: 1000,
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Found: true,
|
||||
Exporter: provider.Exporter{
|
||||
Name: "default",
|
||||
@@ -198,7 +199,8 @@ func TestStaticProvider(t *testing.T) {
|
||||
Description: "10th interface",
|
||||
Speed: 1000,
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Found: true,
|
||||
Exporter: provider.Exporter{
|
||||
Name: "default",
|
||||
@@ -208,7 +210,8 @@ func TestStaticProvider(t *testing.T) {
|
||||
Description: "Default interface",
|
||||
Speed: 1000,
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Found: true,
|
||||
Exporter: provider.Exporter{
|
||||
Name: "default with metadata",
|
||||
@@ -226,7 +229,8 @@ func TestStaticProvider(t *testing.T) {
|
||||
Connectivity: "transit",
|
||||
Boundary: schema.InterfaceBoundaryExternal,
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
Found: true,
|
||||
Exporter: provider.Exporter{
|
||||
Name: "nodefault skip",
|
||||
|
||||
@@ -70,7 +70,6 @@ func TestInitStaticExporters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoteExporterSources(t *testing.T) {
|
||||
|
||||
// Mux to answer requests
|
||||
ready := make(chan bool)
|
||||
mux := http.NewServeMux()
|
||||
|
||||
@@ -55,10 +55,8 @@ type Dependencies struct {
|
||||
Clock clock.Clock
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrQueryTimeout is the error returned when a query timeout.
|
||||
ErrQueryTimeout = errors.New("provider query timeout")
|
||||
)
|
||||
// ErrQueryTimeout is the error returned when a query timeout.
|
||||
var ErrQueryTimeout = errors.New("provider query timeout")
|
||||
|
||||
// New creates a new metadata component.
|
||||
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
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.metrics.providerErrors.Inc()
|
||||
if err == breaker.ErrBreakerOpen {
|
||||
|
||||
@@ -38,7 +38,8 @@ func TestLookup(t *testing.T) {
|
||||
Exporter: provider.Exporter{
|
||||
Name: "127_0_0_1",
|
||||
},
|
||||
Interface: provider.Interface{Name: "Gi0/0/765",
|
||||
Interface: provider.Interface{
|
||||
Name: "Gi0/0/765",
|
||||
Description: "Interface 765",
|
||||
Speed: 1000,
|
||||
},
|
||||
@@ -53,7 +54,8 @@ func TestLookup(t *testing.T) {
|
||||
Site: "metadata site",
|
||||
Tenant: "metadata tenant",
|
||||
},
|
||||
Interface: provider.Interface{Name: "Gi0/0/1010",
|
||||
Interface: provider.Interface{
|
||||
Name: "Gi0/0/1010",
|
||||
Description: "Interface 1010",
|
||||
Speed: 1000,
|
||||
},
|
||||
@@ -68,7 +70,8 @@ func TestLookup(t *testing.T) {
|
||||
Site: "metadata site",
|
||||
Tenant: "metadata tenant",
|
||||
},
|
||||
Interface: provider.Interface{Name: "Gi0/0/2010",
|
||||
Interface: provider.Interface{
|
||||
Name: "Gi0/0/2010",
|
||||
Description: "Interface 2010",
|
||||
Speed: 1000,
|
||||
Boundary: schema.InterfaceBoundaryExternal,
|
||||
@@ -95,7 +98,8 @@ func TestComponentSaveLoad(t *testing.T) {
|
||||
Name: "127_0_0_1",
|
||||
},
|
||||
|
||||
Interface: provider.Interface{Name: "Gi0/0/765",
|
||||
Interface: provider.Interface{
|
||||
Name: "Gi0/0/765",
|
||||
Description: "Interface 765",
|
||||
Speed: 1000,
|
||||
},
|
||||
@@ -154,7 +158,8 @@ func TestAutoRefresh(t *testing.T) {
|
||||
Name: "127_0_0_1",
|
||||
},
|
||||
|
||||
Interface: provider.Interface{Name: "Gi0/0/765",
|
||||
Interface: provider.Interface{
|
||||
Name: "Gi0/0/765",
|
||||
Description: "Interface 765",
|
||||
Speed: 1000,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user