diff --git a/Makefile b/Makefile index 6c05b599..415875d4 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort ALL_SRC := $(shell find . -name '*.go' -type f | sort) ADDLICENSE=addlicense ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./internal/tools' | sort) +FIELDALIGNMENT_DIRS := ./agent/ ./pipeline/ TOOLS_MOD_DIR := ./internal/tools .PHONY: install-tools @@ -16,6 +17,7 @@ install-tools: cd $(TOOLS_MOD_DIR) && go install github.com/vektra/mockery/cmd/mockery cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense cd $(TOOLS_MOD_DIR) && go install github.com/securego/gosec/v2/cmd/gosec + cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment .PHONY: test test: vet test-only @@ -65,6 +67,14 @@ lint: lint-fix: golangci-lint run --fix --allow-parallel-runners ./... +.PHONY: fieldalignment +fieldalignment: + fieldalignment $(FIELDALIGNMENT_DIRS) + +.PHONY: fieldalignment-fix +fieldalignment-fix: + fieldalignment -fix $(FIELDALIGNMENT_DIRS) + .PHONY: vet vet: GOOS=darwin $(MAKE) for-all CMD="go vet ./..." @@ -109,4 +119,4 @@ for-all: done .PHONY: ci-check -ci-check: vet lint check-license secure +ci-check: vet lint check-license secure fieldalignment diff --git a/agent/agent.go b/agent/agent.go index 46bac1e6..140caf86 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -26,11 +26,9 @@ import ( // LogAgent is an entity that handles log monitoring. type LogAgent struct { pipeline pipeline.Pipeline - + *zap.SugaredLogger startOnce sync.Once stopOnce sync.Once - - *zap.SugaredLogger } // Start will start the log monitoring process diff --git a/agent/builder.go b/agent/builder.go index fa9a8e17..bd0cb8e7 100644 --- a/agent/builder.go +++ b/agent/builder.go @@ -27,11 +27,11 @@ import ( // LogAgentBuilder is a construct used to build a log agent type LogAgentBuilder struct { - configFiles []string + defaultOutput operator.Operator config *Config logger *zap.SugaredLogger pluginDir string - defaultOutput operator.Operator + configFiles []string } // NewBuilder creates a new LogAgentBuilder diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 7c42f1cd..b2bb4bf9 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -5,5 +5,7 @@ go 1.15 require ( github.com/golangci/golangci-lint v1.41.1 github.com/google/addlicense v0.0.0-20200906110928-a0294312aa76 + github.com/securego/gosec/v2 v2.8.0 // indirect github.com/tcnksm/ghr v0.14.0 + github.com/vektra/mockery v1.1.2 // indirect ) diff --git a/internal/tools/go.sum b/internal/tools/go.sum index a7304ba1..7b2c4cf2 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -282,9 +282,11 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 github.com/google/trillian v1.3.11/go.mod h1:0tPraVHrSDkA3BO6vKX67zgLXs6SsOAbHEivX+9mPgw= github.com/google/uuid v0.0.0-20161128191214-064e2069ce9c/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -665,8 +667,11 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/vektra/mockery v1.1.2 h1:uc0Yn67rJpjt8U/mAZimdCKn9AeA97BOkjpmtBSlfP4= +github.com/vektra/mockery v1.1.2/go.mod h1:VcfZjKaFOPO+MpN4ZvwPjs4c48lkq1o3Ym8yHZJu0jU= github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yeya24/promlinter v0.1.0 h1:goWULN0jH5Yajmu/K+v1xCqIREeB+48OiJ2uu2ssc7U= @@ -928,6 +933,7 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200324003944-a576cf524670/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200329025819-fd4102a86c65/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= diff --git a/pipeline/node.go b/pipeline/node.go index be353f59..18cb3863 100644 --- a/pipeline/node.go +++ b/pipeline/node.go @@ -23,8 +23,8 @@ import ( // OperatorNode is a basic node that represents an operator in a pipeline. type OperatorNode struct { operator operator.Operator - id int64 outputIDs map[string]int64 + id int64 } // Operator returns the operator of the node. @@ -56,7 +56,11 @@ func createOperatorNode(operator operator.Operator) OperatorNode { outputIDs[output.ID()] = createNodeID(output.ID()) } } - return OperatorNode{operator, id, outputIDs} + return OperatorNode{ + operator: operator, + outputIDs: outputIDs, + id: id, + } } // createNodeID generates a node id from an operator id.