chore: Lint whole codebase both in PR and master branch (#12590)
This commit is contained in:
parent
6e2d8137e4
commit
473aa0de17
|
|
@ -14,9 +14,8 @@ permissions:
|
||||||
pull-requests: read # to fetch pull requests (golangci/golangci-lint-action)
|
pull-requests: read # to fetch pull requests (golangci/golangci-lint-action)
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
golangci-pr:
|
golangci:
|
||||||
if: github.ref != 'refs/heads/master'
|
name: lint-codebase
|
||||||
name: lint-pr-changes
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
|
|
@ -26,21 +25,5 @@ jobs:
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.50.0
|
version: v1.50.1
|
||||||
only-new-issues: true
|
|
||||||
args: --timeout 15m0s --verbose
|
args: --timeout 15m0s --verbose
|
||||||
golangci-master:
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
name: lint-master-all
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: 1.19
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: golangci-lint
|
|
||||||
uses: golangci/golangci-lint-action@v3
|
|
||||||
with:
|
|
||||||
version: v1.50.0
|
|
||||||
only-new-issues: true
|
|
||||||
args: --timeout 15m0s --issues-exit-code=0 --verbose
|
|
||||||
|
|
|
||||||
|
|
@ -183,5 +183,19 @@ issues:
|
||||||
- path: cmd/telegraf/(main|printer).go
|
- path: cmd/telegraf/(main|printer).go
|
||||||
text: "Error return value of `outputBuffer.Write` is not checked"
|
text: "Error return value of `outputBuffer.Write` is not checked"
|
||||||
|
|
||||||
|
# output configuration options
|
||||||
output:
|
output:
|
||||||
|
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
|
||||||
|
#
|
||||||
|
# Multiple can be specified by separating them by comma, output can be provided
|
||||||
|
# for each of them by separating format name and path by colon symbol.
|
||||||
|
# Output path can be either `stdout`, `stderr` or path to the file to write to.
|
||||||
|
# Example: "checkstyle:report.json,colored-line-number"
|
||||||
|
#
|
||||||
|
# Default: colored-line-number
|
||||||
format: tab
|
format: tab
|
||||||
|
# Make issues output unique by line.
|
||||||
|
# Default: true
|
||||||
|
uniq-by-line: false
|
||||||
|
# Sort results by: filepath, line and column.
|
||||||
|
sort-results: true
|
||||||
|
|
|
||||||
5
Makefile
5
Makefile
|
|
@ -168,7 +168,7 @@ vet:
|
||||||
.PHONY: lint-install
|
.PHONY: lint-install
|
||||||
lint-install:
|
lint-install:
|
||||||
@echo "Installing golangci-lint"
|
@echo "Installing golangci-lint"
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
|
||||||
|
|
||||||
@echo "Installing markdownlint"
|
@echo "Installing markdownlint"
|
||||||
npm install -g markdownlint-cli
|
npm install -g markdownlint-cli
|
||||||
|
|
@ -193,8 +193,7 @@ lint-branch:
|
||||||
echo "golangci-lint not found, please run: make lint-install"; \
|
echo "golangci-lint not found, please run: make lint-install"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
}
|
}
|
||||||
|
golangci-lint run
|
||||||
golangci-lint run --new-from-rev master
|
|
||||||
|
|
||||||
.PHONY: tidy
|
.PHONY: tidy
|
||||||
tidy:
|
tidy:
|
||||||
|
|
|
||||||
|
|
@ -103,11 +103,7 @@ func (h *HTTP) gatherURL(
|
||||||
acc telegraf.Accumulator,
|
acc telegraf.Accumulator,
|
||||||
url string,
|
url string,
|
||||||
) error {
|
) error {
|
||||||
body, err := makeRequestBodyReader(h.ContentEncoding, h.Body)
|
body := makeRequestBodyReader(h.ContentEncoding, h.Body)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
request, err := http.NewRequest(h.Method, url, body)
|
request, err := http.NewRequest(h.Method, url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -206,17 +202,17 @@ func (h *HTTP) setRequestAuth(request *http.Request) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeRequestBodyReader(contentEncoding, body string) (io.Reader, error) {
|
func makeRequestBodyReader(contentEncoding, body string) io.Reader {
|
||||||
if body == "" {
|
if body == "" {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader io.Reader = strings.NewReader(body)
|
var reader io.Reader = strings.NewReader(body)
|
||||||
if contentEncoding == "gzip" {
|
if contentEncoding == "gzip" {
|
||||||
return internal.CompressWithGzip(reader), nil
|
return internal.CompressWithGzip(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
return reader, nil
|
return reader
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
||||||
|
|
@ -333,10 +333,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db, rp string, metrics []te
|
||||||
return fmt.Errorf("failed making write url: %s", err.Error())
|
return fmt.Errorf("failed making write url: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, err := c.requestBodyReader(metrics)
|
reader := c.requestBodyReader(metrics)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
req, err := c.makeWriteRequest(loc, reader)
|
req, err := c.makeWriteRequest(loc, reader)
|
||||||
|
|
@ -481,14 +478,14 @@ func (c *httpClient) makeWriteRequest(address string, body io.Reader) (*http.Req
|
||||||
|
|
||||||
// requestBodyReader warp io.Reader from influx.NewReader to io.ReadCloser, which is usefully to fast close the write
|
// requestBodyReader warp io.Reader from influx.NewReader to io.ReadCloser, which is usefully to fast close the write
|
||||||
// side of the connection in case of error
|
// side of the connection in case of error
|
||||||
func (c *httpClient) requestBodyReader(metrics []telegraf.Metric) (io.ReadCloser, error) {
|
func (c *httpClient) requestBodyReader(metrics []telegraf.Metric) io.ReadCloser {
|
||||||
reader := influx.NewReader(metrics, c.config.Serializer)
|
reader := influx.NewReader(metrics, c.config.Serializer)
|
||||||
|
|
||||||
if c.config.ContentEncoding == "gzip" {
|
if c.config.ContentEncoding == "gzip" {
|
||||||
return internal.CompressWithGzip(reader), nil
|
return internal.CompressWithGzip(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
return io.NopCloser(reader), nil
|
return io.NopCloser(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClient) addHeaders(req *http.Request) error {
|
func (c *httpClient) addHeaders(req *http.Request) error {
|
||||||
|
|
|
||||||
|
|
@ -249,10 +249,7 @@ func (c *httpClient) writeBatch(ctx context.Context, bucket string, metrics []te
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, err := c.requestBodyReader(metrics)
|
reader := c.requestBodyReader(metrics)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
req, err := c.makeWriteRequest(loc, reader)
|
req, err := c.makeWriteRequest(loc, reader)
|
||||||
|
|
@ -387,14 +384,14 @@ func (c *httpClient) makeWriteRequest(address string, body io.Reader) (*http.Req
|
||||||
|
|
||||||
// requestBodyReader warp io.Reader from influx.NewReader to io.ReadCloser, which is usefully to fast close the write
|
// requestBodyReader warp io.Reader from influx.NewReader to io.ReadCloser, which is usefully to fast close the write
|
||||||
// side of the connection in case of error
|
// side of the connection in case of error
|
||||||
func (c *httpClient) requestBodyReader(metrics []telegraf.Metric) (io.ReadCloser, error) {
|
func (c *httpClient) requestBodyReader(metrics []telegraf.Metric) io.ReadCloser {
|
||||||
reader := influx.NewReader(metrics, c.serializer)
|
reader := influx.NewReader(metrics, c.serializer)
|
||||||
|
|
||||||
if c.ContentEncoding == "gzip" {
|
if c.ContentEncoding == "gzip" {
|
||||||
return internal.CompressWithGzip(reader), nil
|
return internal.CompressWithGzip(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
return io.NopCloser(reader), nil
|
return io.NopCloser(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClient) addHeaders(req *http.Request) {
|
func (c *httpClient) addHeaders(req *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue