mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
build: add even more linting rules
Notably, shorten function signatures by not repeating types.
This commit is contained in:
@@ -43,7 +43,7 @@ var (
|
|||||||
|
|
||||||
// TransformQueryOnCluster turns a ClickHouse query into its equivalent to be
|
// TransformQueryOnCluster turns a ClickHouse query into its equivalent to be
|
||||||
// run on a cluster by adding the ON CLUSTER directive.
|
// run on a cluster by adding the ON CLUSTER directive.
|
||||||
func TransformQueryOnCluster(query string, cluster string) string {
|
func TransformQueryOnCluster(query, cluster string) string {
|
||||||
// From utils/antlr/ClickHouseParser.g4:
|
// From utils/antlr/ClickHouseParser.g4:
|
||||||
//
|
//
|
||||||
// ALTER TABLE tableIdentifier clusterClause? alterTableClause (COMMA alterTableClause)*
|
// ALTER TABLE tableIdentifier clusterClause? alterTableClause (COMMA alterTableClause)*
|
||||||
|
|||||||
2
common/helpers/cache/cache_test.go
vendored
2
common/helpers/cache/cache_test.go
vendored
@@ -12,7 +12,7 @@ import (
|
|||||||
"akvorado/common/helpers/cache"
|
"akvorado/common/helpers/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expectCacheGet(t *testing.T, c *cache.Cache[netip.Addr, string], key string, expectedResult string, expectedOk bool) {
|
func expectCacheGet(t *testing.T, c *cache.Cache[netip.Addr, string], key, expectedResult string, expectedOk bool) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ip := netip.MustParseAddr(key)
|
ip := netip.MustParseAddr(key)
|
||||||
ip = helpers.AddrTo6(ip)
|
ip = helpers.AddrTo6(ip)
|
||||||
|
|||||||
@@ -152,9 +152,6 @@ func (c *Component) widgetTopHandlerFunc(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch uriParams.WidgetName {
|
switch uriParams.WidgetName {
|
||||||
default:
|
|
||||||
gc.JSON(http.StatusNotFound, gin.H{"message": "Unknown top request."})
|
|
||||||
return
|
|
||||||
case HomepageTopWidgetSrcAS:
|
case HomepageTopWidgetSrcAS:
|
||||||
selector = fmt.Sprintf(`concat(toString(SrcAS), ': ', dictGetOrDefault('%s', 'name', SrcAS, '???'))`, schema.DictionaryASNs)
|
selector = fmt.Sprintf(`concat(toString(SrcAS), ': ', dictGetOrDefault('%s', 'name', SrcAS, '???'))`, schema.DictionaryASNs)
|
||||||
groupby = `SrcAS`
|
groupby = `SrcAS`
|
||||||
@@ -181,6 +178,9 @@ func (c *Component) widgetTopHandlerFunc(gc *gin.Context) {
|
|||||||
selector = fmt.Sprintf(`concat(dictGetOrDefault('%s', 'name', Proto, '???'), '/', toString(DstPort))`, schema.DictionaryProtocols)
|
selector = fmt.Sprintf(`concat(dictGetOrDefault('%s', 'name', Proto, '???'), '/', toString(DstPort))`, schema.DictionaryProtocols)
|
||||||
groupby = `Proto, DstPort`
|
groupby = `Proto, DstPort`
|
||||||
mainTableRequired = true
|
mainTableRequired = true
|
||||||
|
default:
|
||||||
|
gc.JSON(http.StatusNotFound, gin.H{"message": "Unknown top request."})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(gc.Param("name"), "src-") {
|
if strings.HasPrefix(gc.Param("name"), "src-") {
|
||||||
filter = "AND InIfBoundary = 'external'"
|
filter = "AND InIfBoundary = 'external'"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
"akvorado/common/embed"
|
"akvorado/common/embed"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Component) addHandlerEmbedded(url string, path string) {
|
func (c *Component) addHandlerEmbedded(url, path string) {
|
||||||
data, _ := fs.Sub(embed.Data(), "orchestrator/clickhouse")
|
data, _ := fs.Sub(embed.Data(), "orchestrator/clickhouse")
|
||||||
c.d.HTTP.AddHandler(url,
|
c.d.HTTP.AddHandler(url,
|
||||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (c *Component) tableAlreadyExists(ctx context.Context, table, column, targe
|
|||||||
|
|
||||||
// mergeTreeEngine returns a MergeTree engine definition, either plain or using
|
// mergeTreeEngine returns a MergeTree engine definition, either plain or using
|
||||||
// Replicated if we are on a cluster.
|
// Replicated if we are on a cluster.
|
||||||
func (c *Component) mergeTreeEngine(table string, variant string, args ...string) string {
|
func (c *Component) mergeTreeEngine(table, variant string, args ...string) string {
|
||||||
if c.d.ClickHouse.ClusterName() != "" {
|
if c.d.ClickHouse.ClusterName() != "" {
|
||||||
return fmt.Sprintf(`Replicated%sMergeTree(%s)`, variant, strings.Join(
|
return fmt.Sprintf(`Replicated%sMergeTree(%s)`, variant, strings.Join(
|
||||||
append([]string{
|
append([]string{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type geoDatabase interface {
|
|||||||
|
|
||||||
// openDatabase opens the provided database and closes the current
|
// openDatabase opens the provided database and closes the current
|
||||||
// one. Do nothing if the path is empty.
|
// one. Do nothing if the path is empty.
|
||||||
func (c *Component) openDatabase(which string, path string, notifySubscribers bool) error {
|
func (c *Component) openDatabase(which, path string, notifySubscribers bool) error {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func copyFile(t *testing.T, src string, dst string) {
|
func copyFile(t *testing.T, src, dst string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
source, err := os.Open(src)
|
source, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ func (c *Component) getNetMask(flowMask, bmpMask uint8) (mask uint8) {
|
|||||||
return mask
|
return mask
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Component) getNextHop(flowNextHop netip.Addr, bmpNextHop netip.Addr) (nextHop netip.Addr) {
|
func (c *Component) getNextHop(flowNextHop, bmpNextHop netip.Addr) (nextHop netip.Addr) {
|
||||||
nextHop = netip.IPv6Unspecified()
|
nextHop = netip.IPv6Unspecified()
|
||||||
for _, provider := range c.config.NetProviders {
|
for _, provider := range c.config.NetProviders {
|
||||||
if !nextHop.IsUnspecified() {
|
if !nextHop.IsUnspecified() {
|
||||||
@@ -227,7 +227,7 @@ func (c *Component) writeExporter(flow *schema.FlowMessage, classification expor
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Component) classifyExporter(t time.Time, ip string, name string, flow *schema.FlowMessage, classification exporterClassification) bool {
|
func (c *Component) classifyExporter(t time.Time, ip, name string, flow *schema.FlowMessage, classification exporterClassification) bool {
|
||||||
// we already have the info provided by the metadata component
|
// we already have the info provided by the metadata component
|
||||||
if (classification != exporterClassification{}) {
|
if (classification != exporterClassification{}) {
|
||||||
return c.writeExporter(flow, classification)
|
return c.writeExporter(flow, classification)
|
||||||
@@ -281,8 +281,7 @@ func (c *Component) writeInterface(flow *schema.FlowMessage, classification inte
|
|||||||
|
|
||||||
func (c *Component) classifyInterface(
|
func (c *Component) classifyInterface(
|
||||||
t time.Time,
|
t time.Time,
|
||||||
ip string,
|
ip, exporterName string,
|
||||||
exporterName string,
|
|
||||||
fl *schema.FlowMessage,
|
fl *schema.FlowMessage,
|
||||||
ifIndex uint32,
|
ifIndex uint32,
|
||||||
ifName,
|
ifName,
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ func (p *Provider) Refresh(ctx context.Context) {
|
|||||||
// Lookup does an lookup on one of the specified RIS Instances and returns the
|
// Lookup does an lookup on one of the specified RIS Instances and returns the
|
||||||
// well known bmp lookup result. NextHopIP is ignored, but maintained for
|
// well known bmp lookup result. NextHopIP is ignored, but maintained for
|
||||||
// compatibility to the internal bmp
|
// compatibility to the internal bmp
|
||||||
func (p *Provider) Lookup(ctx context.Context, ip netip.Addr, _ netip.Addr, agent netip.Addr) (provider.LookupResult, error) {
|
func (p *Provider) Lookup(ctx context.Context, ip, _, agent netip.Addr) (provider.LookupResult, error) {
|
||||||
p.mu.RLock()
|
p.mu.RLock()
|
||||||
defer p.mu.RUnlock()
|
defer p.mu.RUnlock()
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ func (p *Provider) lpmResponseToLookupResult(lpm *pb.LPMResponse) (bmp.LookupRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lookupLPM does an lookupLPM GRPC call to a BioRis instance
|
// lookupLPM does an lookupLPM GRPC call to a BioRis instance
|
||||||
func (p *Provider) lookupLPM(ctx context.Context, ip netip.Addr, agent netip.Addr) (*pb.LPMResponse, error) {
|
func (p *Provider) lookupLPM(ctx context.Context, ip, agent netip.Addr) (*pb.LPMResponse, error) {
|
||||||
// Choose router id and ris
|
// Choose router id and ris
|
||||||
chosenRouterID, chosenRis, err := p.chooseRouter(agent)
|
chosenRouterID, chosenRis, err := p.chooseRouter(agent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var errNoRouteFound = errors.New("no route found")
|
|||||||
// we use the best route we have, while the exporter may not have this
|
// we use the best route we have, while the exporter may not have this
|
||||||
// best route available. The returned result should not be modified!
|
// best route available. The returned result should not be modified!
|
||||||
// The last parameter, the agent, is ignored by this provider.
|
// The last parameter, the agent, is ignored by this provider.
|
||||||
func (p *Provider) Lookup(_ context.Context, ip netip.Addr, nh netip.Addr, _ netip.Addr) (LookupResult, error) {
|
func (p *Provider) Lookup(_ context.Context, ip, nh, _ netip.Addr) (LookupResult, error) {
|
||||||
if !p.config.CollectASNs && !p.config.CollectASPaths && !p.config.CollectCommunities {
|
if !p.config.CollectASNs && !p.config.CollectASPaths && !p.config.CollectCommunities {
|
||||||
return LookupResult{}, nil
|
return LookupResult{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ type stopper interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lookup uses the selected provider to get an answer.
|
// Lookup uses the selected provider to get an answer.
|
||||||
func (c *Component) Lookup(ctx context.Context, ip netip.Addr, nh netip.Addr, agent netip.Addr) provider.LookupResult {
|
func (c *Component) Lookup(ctx context.Context, ip, nh, agent netip.Addr) provider.LookupResult {
|
||||||
c.metrics.routingLookups.Inc()
|
c.metrics.routingLookups.Inc()
|
||||||
result, err := c.provider.Lookup(ctx, ip, nh, agent)
|
result, err := c.provider.Lookup(ctx, ip, nh, agent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ confidence = 0.8
|
|||||||
[rule.defer]
|
[rule.defer]
|
||||||
[rule.dot-imports]
|
[rule.dot-imports]
|
||||||
[rule.empty-block]
|
[rule.empty-block]
|
||||||
|
[rule.enforce-repeated-arg-type-style]
|
||||||
|
arguments = ["short"]
|
||||||
|
[rule.enforce-switch-style]
|
||||||
|
arguments = ["allowNoDefault"]
|
||||||
[rule.error-naming]
|
[rule.error-naming]
|
||||||
[rule.error-return]
|
[rule.error-return]
|
||||||
[rule.error-strings]
|
[rule.error-strings]
|
||||||
|
|||||||
Reference in New Issue
Block a user