Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add golangci-lint to Makefile #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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..."
@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 in $(promremote_package_path)"
cd $(src_relative_path) && golangci-lint run
2 changes: 1 addition & 1 deletion src/cmd/promremotebench/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/promremotebench/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/promremotebench/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}()
Expand Down
6 changes: 2 additions & 4 deletions src/cmd/promremotebench/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down