Skip to content

Commit

Permalink
update golang-ci and fix linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Jan 8, 2025
1 parent 75a7e7b commit a9fb2db
Show file tree
Hide file tree
Showing 52 changed files with 55 additions and 154 deletions.
18 changes: 4 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.55.2
# v1.63.2
# Please don't remove the first line. It is used in CI to determine the golangci version
run:
deadline: 5m
Expand Down Expand Up @@ -69,24 +69,19 @@ linters-settings:
linters:
enable-all: true
disable:
- mnd # disabled because it's too strict and doesn't provide much value
- noctx # too many false positives when making simple http requests in tests
- exhaustivestruct
- exhaustruct
- gci
- gochecknoinits
- gocyclo # replaced by cyclop since it also calculates the package complexity
- godot
- godox
- goerr113 # most of the errors here are meant for humans
- err113 # most of the errors here are meant for humans
- goheader
- golint # this linter is deprecated
- gomnd
- gomodguard
- interfacer # deprecated
- ireturn
- maligned # replaced by govet 'fieldalignment'
- nlreturn
- scopelint # deprecated, replaced by exportloopref
- tagliatelle
- testpackage
- thelper
Expand All @@ -97,14 +92,9 @@ linters:
- usestdlibvars
- nosprintfhostport
- nonamedreturns
# Deprecated linters as of 1.53.3
- structcheck
- varcheck
- deadcode
- ifshort
- nosnakecase
- depguard # Dependency whitelist, needs to be configured
- inamedparam # Fails if interfaces do not have named params. Not in our code style.
- perfsprint # Suggests using strconv.* instead of fmt.* for printing numbers. Not very practical.
- protogetter # Complains when code reads var.Something if var.GetSomething() exists. Not useful.
- exportloopref
fast: false
2 changes: 1 addition & 1 deletion cmd/agent/commands/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func BuiltCleanupCmd(env runtime.Environment) *cobra.Command {
cmd := &cobra.Command{
Use: "cleanup",
Short: "stops any ongoing fault injection and cleans resources",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive
runningProcess := env.Lock().Owner()
// no instance is currently running
if runningProcess == -1 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/commands/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func BuildGrpcCmd(env runtime.Environment, config *agent.Config) *cobra.Command
cmd.Flags().DurationVarP(&duration, "duration", "d", 0, "duration of the disruptions")
cmd.Flags().DurationVarP(&disruption.AverageDelay, "average-delay", "a", 0, "average request delay")
cmd.Flags().DurationVarP(&disruption.DelayVariation, "delay-variation", "v", 0, "variation in request delay")
cmd.Flags().Int32VarP(&disruption.StatusCode, "status", "s", 0, "status code")
cmd.Flags().Uint32VarP(&disruption.StatusCode, "status", "s", 0, "status code")
cmd.Flags().Float32VarP(&disruption.ErrorRate, "rate", "r", 0, "error rate")
cmd.Flags().StringVarP(&disruption.StatusMessage, "message", "m", "", "error message for injected faults")
cmd.Flags().UintVarP(&port, "port", "p", 8000, "port the proxy will listen to")
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/commands/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func BuildHTTPCmd(env runtime.Environment, config *agent.Config) *cobra.Command
cmd.Flags().DurationVarP(&duration, "duration", "d", 0, "duration of the disruptions")
cmd.Flags().DurationVarP(&disruption.AverageDelay, "average-delay", "a", 0, "average request delay")
cmd.Flags().DurationVarP(&disruption.DelayVariation, "delay-variation", "v", 0, "variation in request delay")
cmd.Flags().UintVarP(&disruption.ErrorCode, "error", "e", 0, "error code")
cmd.Flags().IntVarP(&disruption.ErrorCode, "error", "e", 0, "error code")
cmd.Flags().Float32VarP(&disruption.ErrorRate, "rate", "r", 0, "error rate")
cmd.Flags().StringVarP(&disruption.ErrorBody, "body", "b", "", "body for injected faults")
cmd.Flags().StringSliceVarP(&disruption.Excluded, "exclude", "x", []string{}, "comma-separated list of path(s)"+
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/commands/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func BuildStressCmd(env runtime.Environment, config *agent.Config) *cobra.Comman
Use: "stress",
Short: "resource stressor",
Long: "Stress CPU resource",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive
agent, err := agent.Start(env, config)
if err != nil {
return fmt.Errorf("initializing agent: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/e2e-cluster/commands/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func BuildCleanupCmd() *cobra.Command {
Use: "cleanup",
Short: "deletes an e2e test cluster ",
Long: "deletes an e2e test cluster",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive
if name == "" {
return fmt.Errorf("--name is required")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/e2e-cluster/commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func BuildSetupCmd() *cobra.Command {
Use: "setup",
Short: "creates and configures an e2e test cluster ",
Long: "creates and configures an e2e test cluster with default options.",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive
cluster, err := cluster.BuildE2eCluster(
cluster.DefaultE2eClusterConfig(),
cluster.WithEnvOverride(false),
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ require (
golang.org/x/sync v0.10.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func Test_CancelContext(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()
env := runtime.NewFakeRuntime(tc.args, tc.vars)
Expand Down Expand Up @@ -125,8 +123,6 @@ func Test_Signals(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()
env := runtime.NewFakeRuntime(tc.args, tc.vars)
Expand Down
3 changes: 0 additions & 3 deletions pkg/agent/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func Test_HTTPFaultInjection(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.test, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -267,7 +266,6 @@ func Test_GrpcFaultInjection(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.test, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -501,7 +499,6 @@ func Test_CPUStressor(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/protocol/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (h *handler) transparentForward(serverStream grpc.ServerStream) error {
s2cErrChan := h.forwardServerToClient(serverStream, clientStream)
c2sErrChan := h.forwardClientToServer(clientStream, serverStream)
// We don't know which side is going to stop sending first, so we need a select between the two.
for i := 0; i < 2; i++ {
for range 2 {
select {
case s2cErr := <-s2cErrChan:
if errors.Is(s2cErr, io.EOF) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/protocol/grpc/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Disruption struct {
// Fraction (in the range 0.0 to 1.0) of requests that will return an error
ErrorRate float32
// Status code to be returned by requests selected to return an error
StatusCode int32
StatusCode uint32
// Status message to be returned in requests selected to return an error
StatusMessage string
// List of grpc services to be excluded from disruptions
Expand Down
12 changes: 3 additions & 9 deletions pkg/agent/protocol/grpc/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Test_Validations(t *testing.T) {
AverageDelay: 0,
DelayVariation: 0,
ErrorRate: 0.1,
StatusCode: int32(codes.Internal),
StatusCode: uint32(codes.Internal),
StatusMessage: "",
},
upstream: ":8080",
Expand Down Expand Up @@ -111,8 +111,6 @@ func Test_Validations(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -174,7 +172,7 @@ func Test_ProxyHandler(t *testing.T) {
AverageDelay: 0,
DelayVariation: 0,
ErrorRate: 1.0,
StatusCode: int32(codes.Internal),
StatusCode: uint32(codes.Internal),
StatusMessage: "Internal server error",
},
request: &ping.PingRequest{
Expand Down Expand Up @@ -205,8 +203,6 @@ func Test_ProxyHandler(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -340,7 +336,7 @@ func Test_ProxyMetrics(t *testing.T) {
AverageDelay: 0,
DelayVariation: 0,
ErrorRate: 1.0,
StatusCode: int32(codes.Internal),
StatusCode: uint32(codes.Internal),
StatusMessage: "Internal server error",
},
expectedMetrics: map[string]uint{
Expand All @@ -352,8 +348,6 @@ func Test_ProxyMetrics(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/protocol/http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Disruption struct {
// Fraction (in the range 0.0 to 1.0) of requests that will return an error
ErrorRate float32
// Error code to be returned by requests selected in the error rate
ErrorCode uint
ErrorCode int
// Body to be returned when an error is injected
ErrorBody string
// List of url paths to be excluded from disruptions
Expand Down Expand Up @@ -142,7 +142,7 @@ func (h *httpHandler) forward(rw http.ResponseWriter, req *http.Request, delay t
func (h *httpHandler) injectError(rw http.ResponseWriter, delay time.Duration) {
time.Sleep(delay)

rw.WriteHeader(int(h.disruption.ErrorCode))
rw.WriteHeader(h.disruption.ErrorCode)
_, _ = rw.Write([]byte(h.disruption.ErrorBody))
}

Expand Down
15 changes: 5 additions & 10 deletions pkg/agent/protocol/http/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ func Test_Validations(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -279,12 +277,10 @@ func Test_ProxyHandler(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

upstreamServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
upstreamServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
for k, values := range tc.upstreamHeaders {
for _, v := range values {
rw.Header().Add(k, v)
Expand Down Expand Up @@ -326,9 +322,9 @@ func Test_ProxyHandler(t *testing.T) {
}

// Remove standard response headers so we don't need to specify them on every test case.
resp.Header.Del("content-length")
resp.Header.Del("content-type")
resp.Header.Del("date")
resp.Header.Del("Content-Length")
resp.Header.Del("Content-Type")
resp.Header.Del("Date")

// Compare headers only if either expected or returned have items.
// We have to check for length explicitly as otherwise a nil map would not be equal to an empty map.
Expand Down Expand Up @@ -381,11 +377,10 @@ func Test_Metrics(t *testing.T) {
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

upstreamServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
upstreamServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.WriteHeader(http.StatusOK)
}))

Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/protocol/redirector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func Test_validateTrafficRedirect(t *testing.T) {
}

for _, tc := range TestCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -147,8 +145,6 @@ func Test_Commands(t *testing.T) {
}

for _, tc := range TestCases {
tc := tc

t.Run(tc.title, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/stressors/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *ResourceStressor) Apply(ctx context.Context, duration time.Duration) er

doneCh := make(chan error, r.Disruption.CPUs)
// create a CPUStressor for each CPU
for i := 0; i < r.Disruption.CPUs; i++ {
for range r.Disruption.CPUs {
go func() {
s := CPUStressor{
Slice: r.Options.Slice,
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/tcpconn/disruptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type nfqConfig struct {
// can actually result in the number overflowing and becoming zero.
func randomNFQConfig() nfqConfig {
return nfqConfig{
queueID: uint16(rand.Int31()) | 0b1,
rejectMark: uint32(rand.Int31()) | 0b1,
queueID: uint16(rand.Int31()) | 0b1, //nolint:gosec //integer overflow is not a concern here
rejectMark: uint32(rand.Int31()) | 0b1, //nolint:gosec
}
}
2 changes: 1 addition & 1 deletion pkg/agent/tcpconn/integration_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Benchmark_DisruptorThroughput(b *testing.B) {
// TODO: b.Elapsed is a better way to do this, but it is not available in the Go version we are using.
start := time.Now()
// We run the iperf3 command as many times as b.N tells us to.
for i := 0; i < b.N; i++ {
for range b.N {
rc, outputReader, err := iperfClient.Exec(ctx, cmd)
if err != nil {
b.Fatalf("error running iperf client command: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func buildObject(rt *sobek.Runtime, value interface{}) (*sobek.Object, error) {

t := reflect.TypeOf(value)
v := reflect.ValueOf(value)
for i := 0; i < t.NumMethod(); i++ {
for i := range t.NumMethod() {
name := t.Method(i).Name
f := v.MethodByName(name)
err := obj.Set(toCamelCase(name), f.Interface())
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func Test_PodDisruptorConstructor(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -480,7 +479,6 @@ func Test_JsPodDisruptor(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -585,7 +583,6 @@ func Test_ServiceDisruptorConstructor(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()
env, err := testSetup()
Expand Down
1 change: 0 additions & 1 deletion pkg/api/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func Test_Conversions(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()
err := Convert(tc.value, tc.target)
Expand Down
1 change: 0 additions & 1 deletion pkg/api/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func Test_Validations(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit a9fb2db

Please sign in to comment.