Skip to content

Conversation

jlvoiseux
Copy link
Contributor

Resolves #153. The chosen linter is golangci-lint. For this third iteration, we install and run the linter as part of the Lint stage in the Jenkinsfile.

@jlvoiseux jlvoiseux changed the title Adding the golangci-lint linter to the repository (makefile) Adding the golangci-lint linter to the repository (jenkinsfile) Mar 23, 2022
@ghost
Copy link

ghost commented Mar 23, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-28T12:30:16.609+0000

  • Duration: 10 min 1 sec

Test stats 🧪

Test Results
Failed 0
Passed 240
Skipped 6
Total 246

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@github-actions github-actions bot added the aws-λ-extension AWS Lambda Extension label Mar 23, 2022
@jlvoiseux
Copy link
Contributor Author

Update on this PR : the linter was successfully implemented by commit 8907a3a.

Failing Linter output

11:54:39  + ./golangci-lint.sh
11:54:39  golangci/golangci-lint info checking GitHub for tag 'v1.45.0'
11:54:39  golangci/golangci-lint info found version: 1.45.0 for v1.45.0/linux/amd64
11:54:40  golangci/golangci-lint info installed /var/lib/jenkins/workspace/ibrary_apm-aws-lambda-mbp_PR-157/bin/golangci-lint
11:54:41  golangci-lint has version 1.45.0 built from 1f4c1ed9 on 2022-03-18T15:08:39Z
11:54:50  main.go:70:27: Error return value of `extension.StartHttpServer` is not checked (errcheck)
11:54:50  	extension.StartHttpServer(agentDataChannel, config)
11:54:50  	                         ^
11:54:50  main_test.go:168:12: Error return value of `client.Do` is not checked (errcheck)
11:54:50  		client.Do(reqData)
11:54:50  		         ^
11:54:50  main_test.go:189:14: Error return value of `client.Do` is not checked (errcheck)
11:54:50  				client.Do(reqData)
11:54:50  				         ^
11:54:50  e2e-testing/e2e_test.go:135:9: Error return value of `io.Copy` is not checked (errcheck)
11:54:50  	io.Copy(out, resp.Body)
11:54:50  	       ^
11:54:50  e2e-testing/e2e_test.go:150:11: Error return value of `os.Chmod` is not checked (errcheck)
11:54:50  		os.Chmod(filepath.Join(agentFolderPath, f.Name()), 0755)
11:54:50  		        ^
11:54:50  e2e-testing/e2e_util.go:38:9: Error return value of `e.Start` is not checked (errcheck)
11:54:50  	e.Start()
11:54:50  	       ^
11:54:50  e2e-testing/e2e_util.go:49:8: Error return value of `e.Wait` is not checked (errcheck)
11:54:50  	e.Wait()
11:54:50  	      ^
11:54:50  e2e-testing/e2e_util.go:78:13: Error return value of `os.MkdirAll` is not checked (errcheck)
11:54:50  	os.MkdirAll(destinationFolderPath, 0755)
11:54:50  	           ^
11:54:50  e2e-testing/e2e_util.go:100:15: Error return value of `os.MkdirAll` is not checked (errcheck)
11:54:50  			os.MkdirAll(path, f.Mode())
11:54:50  			           ^
11:54:50  e2e-testing/e2e_util.go:102:15: Error return value of `os.MkdirAll` is not checked (errcheck)
11:54:50  			os.MkdirAll(filepath.Dir(path), f.Mode())
11:54:50  			           ^
11:54:50  logsapi/subscribe.go:99:15: Error return value of `Server.Serve` is not checked (errcheck)
11:54:50  		Server.Serve(Listener)
11:54:50  		            ^
11:54:50  extension/apm_server_test.go:38:11: Error return value of `gw.Write` is not checked (errcheck)
11:54:50  		gw.Write([]byte(s))
11:54:50  		        ^
11:54:50  extension/apm_server_test.go:52:10: Error return value of `w.Write` is not checked (errcheck)
11:54:50  		w.Write([]byte(`{"foo": "bar"}`))
11:54:50  		       ^
11:54:50  extension/apm_server_test.go:74:11: Error return value of `gw.Write` is not checked (errcheck)
11:54:50  		gw.Write(body)
11:54:50  		        ^
11:54:50  extension/apm_server_test.go:85:10: Error return value of `w.Write` is not checked (errcheck)
11:54:50  		w.Write([]byte(`{"foo": "bar"}`))
11:54:50  		       ^
11:54:50  extension/apm_server_test.go:178:11: Error return value of `gw.Write` is not checked (errcheck)
11:54:50  		gw.Write([]byte(""))
11:54:50  		        ^
11:54:50  extension/apm_server_test.go:192:10: Error return value of `w.Write` is not checked (errcheck)
11:54:50  		w.Write([]byte(`{"foo": "bar"}`))
11:54:50  		       ^
11:54:50  extension/apm_server_test.go:201:17: Error return value is not checked (errcheck)
11:54:50  	PostToApmServer(apmServer.Client(), agentData, &config, context.Background())
11:54:50  	               ^
11:54:50  extension/apm_server_test.go:244:17: Error return value is not checked (errcheck)
11:54:50  	PostToApmServer(apmServer.Client(), agentData, &config, context.Background())
11:54:50  	               ^
11:54:50  extension/apm_server_test.go:285:17: Error return value is not checked (errcheck)
11:54:50  	PostToApmServer(apmServer.Client(), agentData, &config, context.Background())
11:54:50  	               ^
11:54:50  extension/apm_server_test.go:346:10: Error return value of `io.Copy` is not checked (errcheck)
11:54:50  		io.Copy(ioutil.Discard, r.Body)
11:54:50  		       ^
11:54:50  extension/http_server.go:48:24: Error return value of `agentDataServer.Serve` is not checked (errcheck)
11:54:50  		agentDataServer.Serve(ln)
11:54:50  		                     ^
11:54:50  e2e-testing/e2e_util.go:56:2: S1008: should use 'return err == nil' instead of 'if err == nil { return true }; return false' (gosimple)
11:54:50  	if err == nil {
11:54:50  	^
11:54:50  e2e-testing/e2e_test.go:46:16: S1028: should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (gosimple)
11:54:50  		ProcessError(errors.New(fmt.Sprintf("Unsupported language %s ! Supported languages are %v", languageName, supportedLanguages)))
11:54:50  		             ^
11:54:50  main_test.go:234:26: S1030: should use bufRecord.String() instead of string(bufRecord.Bytes()) (gosimple)
11:54:50  	logEvent.StringRecord = string(bufRecord.Bytes())
11:54:50  	                        ^

Corrections required for the linter to pass were done in ad51c2a.

Successful Linter output

14:56:58  + ./golangci-lint.sh
14:56:58  golangci/golangci-lint info checking GitHub for tag 'v1.45.0'
14:56:58  golangci/golangci-lint info found version: 1.45.0 for v1.45.0/linux/amd64
14:56:59  golangci/golangci-lint info installed /var/lib/jenkins/workspace/ibrary_apm-aws-lambda-mbp_PR-157/bin/golangci-lint
14:57:00  golangci-lint has version 1.45.0 built from 1f4c1ed9 on 2022-03-18T15:08:39Z

To run the linter on your own machine, just run the ./golangci-lint.sh script.

@jlvoiseux jlvoiseux marked this pull request as ready for review March 24, 2022 14:06
}

extension.Log.Info("If the end-to-end tests are failing unexpectedly, please verify that Docker is running on your machine.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you put this because of a first-hand experience :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly :D

Copy link
Contributor

@estolfo estolfo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a comment about using the shorthand ; err != nil {
That's not a necessary change, just up to you if you want to shave off some more lines of code.

assert.Equal(t, string(data), string(bytes))
assert.Equal(t, "gzip", r.Header.Get("Content-Encoding"))
w.Write([]byte(`{"foo": "bar"}`))
_, err := w.Write([]byte(`{"foo": "bar"}`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use this syntax in a few places in this PR, if you want:

if _, err := w.Write([]byte(`{"foo": "bar"}`)); err != nil {
  return
}

gw.Write([]byte(""))
gw.Close()
pw.Close()
_, err := gw.Write([]byte(""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example,

if _, err := gw.Write([]byte("")); err != nil {
  t.Fail()
  return
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice ! In a34cd53 and 1bdfc14, I have used the shorthand wherever I could use it.

@jlvoiseux jlvoiseux merged commit ffc7541 into elastic:main Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-λ-extension AWS Lambda Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add linter to the codebase

2 participants