From c0c2034793a4bf20a2b4f4d57eb0cb27248d96aa Mon Sep 17 00:00:00 2001 From: Benjamin Raskin Date: Sun, 1 Sep 2019 17:17:22 -0400 Subject: [PATCH 1/4] Add golangci-lint to Makefile --- Makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ebd6449 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +golangci-lint_version := v1.17.1 +gopath_prefix := $(HOME)/src +promremote_package := github.com/m3db/promremotebench # change this to m3dbx +promremote_package_path := $(gopath_prefix)/$(promremote_package)/src/cmd/promremotebench + +.PHONY: validate-gopath  +validate-gopath: + @stat $(GOPATH) > /dev/null + +install-linter: + echo "Installing golangci-lint..." + @PATH=$(GOPATH)/bin:$(PATH) which golangci-lint > /dev/null || "(curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin golangci-lint_version" + @PATH=$(GOPATH)/bin:$(PATH) which golangci-lint > /dev/null || (echo "golangci-lint install failed" && exit 1) + +linter: + make install-linter + @echo "--- linting promremotebench" + golangci-lint run $(promremote_package_path) From ce25ecfe628669939754f84f99ba4e884517fa8a Mon Sep 17 00:00:00 2001 From: Benjamin Raskin Date: Tue, 3 Sep 2019 15:21:36 -0400 Subject: [PATCH 2/4] Fix lint errors --- Makefile | 8 +++++--- src/cmd/promremotebench/checker.go | 2 +- src/cmd/promremotebench/query.go | 2 +- src/cmd/promremotebench/write.go | 2 +- src/cmd/promremotebench/write_test.go | 6 ++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index ebd6449..a3c52e4 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ golangci-lint_version := v1.17.1 gopath_prefix := $(HOME)/src -promremote_package := github.com/m3db/promremotebench # change this to m3dbx +promremote_package := github.com/m3db/promremotebench# change this to m3dbx promremote_package_path := $(gopath_prefix)/$(promremote_package)/src/cmd/promremotebench +relative_path := ./src/cmd/promremotebench .PHONY: validate-gopath  validate-gopath: @@ -14,5 +15,6 @@ install-linter: linter: make install-linter - @echo "--- linting promremotebench" - golangci-lint run $(promremote_package_path) + @echo "--- linting promremotebench in $(promremote_package_path)" + go mod download -json { Path: /Users/braskin/src/github.com/m3db/promremotebench/src/go.mod } + cd $(relative_path) && golangci-lint run diff --git a/src/cmd/promremotebench/checker.go b/src/cmd/promremotebench/checker.go index aac01d2..3e3d8b3 100644 --- a/src/cmd/promremotebench/checker.go +++ b/src/cmd/promremotebench/checker.go @@ -95,7 +95,7 @@ func (c *checker) GetHostNames() []string { c.RLock() results := make([]string, len(c.values)) i := 0 - for host, _ := range c.values { + for host := range c.values { results[i] = host i++ } diff --git a/src/cmd/promremotebench/query.go b/src/cmd/promremotebench/query.go index 5effe7a..1c3f12e 100644 --- a/src/cmd/promremotebench/query.go +++ b/src/cmd/promremotebench/query.go @@ -278,6 +278,7 @@ func (q *queryExecutor) executeQuery(query *strings.Builder, retResult bool, que } defer func() { + //nolint:errcheck io.Copy(ioutil.Discard, resp.Body) resp.Body.Close() }() @@ -352,7 +353,6 @@ func (q *queryExecutor) validateQuery(dps Datapoints, data []byte) bool { for _, value := range matrix[0].Values { for i < len(dps) { if float64(value.Value) == dps[i].Value { - i++ matches++ break } diff --git a/src/cmd/promremotebench/write.go b/src/cmd/promremotebench/write.go index 29d068b..c67958e 100644 --- a/src/cmd/promremotebench/write.go +++ b/src/cmd/promremotebench/write.go @@ -131,7 +131,6 @@ var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) // Client allows reading and writing from/to a remote HTTP endpoint. type Client struct { - index int // Used to differentiate clients in metrics. url string client *http.Client timeout time.Duration @@ -180,6 +179,7 @@ func (c *Client) Store(ctx context.Context, req []byte) error { return recoverableError{err} } defer func() { + //nolint:errcheck io.Copy(ioutil.Discard, httpResp.Body) httpResp.Body.Close() }() diff --git a/src/cmd/promremotebench/write_test.go b/src/cmd/promremotebench/write_test.go index b24fa83..82ae5ba 100644 --- a/src/cmd/promremotebench/write_test.go +++ b/src/cmd/promremotebench/write_test.go @@ -44,10 +44,8 @@ import ( func TestRemoteWrite(t *testing.T) { logger := instrument.NewOptions().Logger() tests := []struct { - name string - numHosts int - expectedBatches int - expectedSeries int + name string + numHosts int }{ { name: "one host", From 75af0099c1f95444eb791841d5af5b45bcb27baf Mon Sep 17 00:00:00 2001 From: Benjamin Raskin Date: Tue, 3 Sep 2019 15:32:45 -0400 Subject: [PATCH 3/4] Updates --- Makefile | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a3c52e4..b798be7 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,8 @@ -golangci-lint_version := v1.17.1 -gopath_prefix := $(HOME)/src -promremote_package := github.com/m3db/promremotebench# change this to m3dbx -promremote_package_path := $(gopath_prefix)/$(promremote_package)/src/cmd/promremotebench -relative_path := ./src/cmd/promremotebench - -.PHONY: validate-gopath  -validate-gopath: - @stat $(GOPATH) > /dev/null +golangci-lint_version := v1.17.1 +gopath_prefix := $(HOME)/src +promremote_package := github.com/m3db/promremotebench# change this to m3dbx +promremote_package_path := $(gopath_prefix)/$(promremote_package)/src/cmd/promremotebench +src_relative_path := ./src/ install-linter: echo "Installing golangci-lint..." @@ -17,4 +13,4 @@ linter: make install-linter @echo "--- linting promremotebench in $(promremote_package_path)" go mod download -json { Path: /Users/braskin/src/github.com/m3db/promremotebench/src/go.mod } - cd $(relative_path) && golangci-lint run + cd $(src_relative_path) && golangci-lint run From 5631c9bb0d34b02870369fab05d6092545c06e55 Mon Sep 17 00:00:00 2001 From: Benjamin Raskin Date: Tue, 3 Sep 2019 15:33:56 -0400 Subject: [PATCH 4/4] Updates --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index b798be7..61d129a 100644 --- a/Makefile +++ b/Makefile @@ -12,5 +12,4 @@ install-linter: linter: make install-linter @echo "--- linting promremotebench in $(promremote_package_path)" - go mod download -json { Path: /Users/braskin/src/github.com/m3db/promremotebench/src/go.mod } cd $(src_relative_path) && golangci-lint run