diff options
author | Ben Kochie <superq@gmail.com> | 2019-01-04 16:58:53 +0100 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2019-01-04 15:58:53 +0000 |
commit | 070e4b2e17750941e38ebb4037d67da3a05a6788 (patch) | |
tree | 34ec9a52a095916551636381520ce7e3ae69f28f | |
parent | 085d872aafdca918069bb1fdf767cf52b15ee961 (diff) | |
download | prometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.tar.bz2 prometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.tar.xz prometheus_node_collector-070e4b2e17750941e38ebb4037d67da3a05a6788.zip |
Update Makefile.common (#1220)
* Update Makefile.common
Update to new staticcheck method[0].
[0]: https://github.com/prometheus/prometheus/pull/5057
Signed-off-by: Ben Kochie <superq@gmail.com>
* Fix staticcheck errors.
Signed-off-by: Ben Kochie <superq@gmail.com>
-rw-r--r-- | Makefile.common | 40 | ||||
-rw-r--r-- | collector/ntp.go | 2 | ||||
-rw-r--r-- | collector/supervisord.go | 10 | ||||
-rw-r--r-- | collector/textfile.go | 2 | ||||
-rw-r--r-- | collector/zfs_linux.go | 14 |
5 files changed, 35 insertions, 33 deletions
diff --git a/Makefile.common b/Makefile.common index f26a788..fff85f9 100644 --- a/Makefile.common +++ b/Makefile.common | |||
@@ -29,6 +29,8 @@ GO ?= go | |||
29 | GOFMT ?= $(GO)fmt | 29 | GOFMT ?= $(GO)fmt |
30 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) | 30 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) |
31 | GOOPTS ?= | 31 | GOOPTS ?= |
32 | GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) | ||
33 | GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) | ||
32 | 34 | ||
33 | GO_VERSION ?= $(shell $(GO) version) | 35 | GO_VERSION ?= $(shell $(GO) version) |
34 | GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) | 36 | GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) |
@@ -62,8 +64,6 @@ PROMU := $(FIRST_GOPATH)/bin/promu | |||
62 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck | 64 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck |
63 | pkgs = ./... | 65 | pkgs = ./... |
64 | 66 | ||
65 | GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) | ||
66 | GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) | ||
67 | ifeq (arm, $(GOHOSTARCH)) | 67 | ifeq (arm, $(GOHOSTARCH)) |
68 | GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM) | 68 | GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM) |
69 | GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM) | 69 | GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM) |
@@ -73,12 +73,21 @@ endif | |||
73 | 73 | ||
74 | PROMU_VERSION ?= 0.2.0 | 74 | PROMU_VERSION ?= 0.2.0 |
75 | PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz | 75 | PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz |
76 | STATICCHECK_VERSION ?= 2019.1 | ||
77 | STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH) | ||
76 | 78 | ||
77 | PREFIX ?= $(shell pwd) | 79 | PREFIX ?= $(shell pwd) |
78 | BIN_DIR ?= $(shell pwd) | 80 | BIN_DIR ?= $(shell pwd) |
79 | DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) | 81 | DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) |
80 | DOCKER_REPO ?= prom | 82 | DOCKER_REPO ?= prom |
81 | 83 | ||
84 | ifeq ($(GOHOSTARCH),amd64) | ||
85 | ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows)) | ||
86 | # Only supported on amd64 | ||
87 | test-flags := -race | ||
88 | endif | ||
89 | endif | ||
90 | |||
82 | .PHONY: all | 91 | .PHONY: all |
83 | all: precheck style staticcheck unused build test | 92 | all: precheck style staticcheck unused build test |
84 | 93 | ||
@@ -116,7 +125,7 @@ common-test-short: | |||
116 | .PHONY: common-test | 125 | .PHONY: common-test |
117 | common-test: | 126 | common-test: |
118 | @echo ">> running all tests" | 127 | @echo ">> running all tests" |
119 | GO111MODULE=$(GO111MODULE) $(GO) test -race $(GOOPTS) $(pkgs) | 128 | GO111MODULE=$(GO111MODULE) $(GO) test $(test-flags) $(GOOPTS) $(pkgs) |
120 | 129 | ||
121 | .PHONY: common-format | 130 | .PHONY: common-format |
122 | common-format: | 131 | common-format: |
@@ -131,8 +140,12 @@ common-vet: | |||
131 | .PHONY: common-staticcheck | 140 | .PHONY: common-staticcheck |
132 | common-staticcheck: $(STATICCHECK) | 141 | common-staticcheck: $(STATICCHECK) |
133 | @echo ">> running staticcheck" | 142 | @echo ">> running staticcheck" |
143 | chmod +x $(STATICCHECK) | ||
134 | ifdef GO111MODULE | 144 | ifdef GO111MODULE |
135 | GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" -checks "SA*" $(pkgs) | 145 | # 'go list' needs to be executed before staticcheck to prepopulate the modules cache. |
146 | # Otherwise staticcheck might fail randomly for some reason not yet explained. | ||
147 | GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null | ||
148 | GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) | ||
136 | else | 149 | else |
137 | $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) | 150 | $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) |
138 | endif | 151 | endif |
@@ -146,8 +159,9 @@ else | |||
146 | ifdef GO111MODULE | 159 | ifdef GO111MODULE |
147 | @echo ">> running check for unused/missing packages in go.mod" | 160 | @echo ">> running check for unused/missing packages in go.mod" |
148 | GO111MODULE=$(GO111MODULE) $(GO) mod tidy | 161 | GO111MODULE=$(GO111MODULE) $(GO) mod tidy |
162 | ifeq (,$(wildcard vendor)) | ||
149 | @git diff --exit-code -- go.sum go.mod | 163 | @git diff --exit-code -- go.sum go.mod |
150 | ifneq (,$(wildcard vendor)) | 164 | else |
151 | @echo ">> running check for unused packages in vendor/" | 165 | @echo ">> running check for unused packages in vendor/" |
152 | GO111MODULE=$(GO111MODULE) $(GO) mod vendor | 166 | GO111MODULE=$(GO111MODULE) $(GO) mod vendor |
153 | @git diff --exit-code -- go.sum go.mod vendor/ | 167 | @git diff --exit-code -- go.sum go.mod vendor/ |
@@ -192,21 +206,9 @@ proto: | |||
192 | @echo ">> generating code from proto files" | 206 | @echo ">> generating code from proto files" |
193 | @./scripts/genproto.sh | 207 | @./scripts/genproto.sh |
194 | 208 | ||
195 | .PHONY: $(STATICCHECK) | ||
196 | $(STATICCHECK): | 209 | $(STATICCHECK): |
197 | ifdef GO111MODULE | 210 | mkdir -p $(FIRST_GOPATH)/bin |
198 | # Get staticcheck from a temporary directory to avoid modifying the local go.{mod,sum}. | 211 | curl -s -L $(STATICCHECK_URL) > $(STATICCHECK) |
199 | # See https://github.com/golang/go/issues/27643. | ||
200 | # For now, we are using the next branch of staticcheck because master isn't compatible yet with Go modules. | ||
201 | tmpModule=$$(mktemp -d 2>&1) && \ | ||
202 | mkdir -p $${tmpModule}/staticcheck && \ | ||
203 | cd "$${tmpModule}"/staticcheck && \ | ||
204 | GO111MODULE=on $(GO) mod init example.com/staticcheck && \ | ||
205 | GO111MODULE=on GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck@next && \ | ||
206 | rm -rf $${tmpModule}; | ||
207 | else | ||
208 | GOOS= GOARCH= GO111MODULE=off $(GO) get -u honnef.co/go/tools/cmd/staticcheck | ||
209 | endif | ||
210 | 212 | ||
211 | ifdef GOVENDOR | 213 | ifdef GOVENDOR |
212 | .PHONY: $(GOVENDOR) | 214 | .PHONY: $(GOVENDOR) |
diff --git a/collector/ntp.go b/collector/ntp.go index e545a1d..9b3c5a2 100644 --- a/collector/ntp.go +++ b/collector/ntp.go | |||
@@ -68,7 +68,7 @@ func NewNtpCollector() (Collector, error) { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | if *ntpOffsetTolerance < 0 { | 70 | if *ntpOffsetTolerance < 0 { |
71 | return nil, fmt.Errorf("Offset tolerance must be non-negative") | 71 | return nil, fmt.Errorf("offset tolerance must be non-negative") |
72 | } | 72 | } |
73 | 73 | ||
74 | return &ntpCollector{ | 74 | return &ntpCollector{ |
diff --git a/collector/supervisord.go b/collector/supervisord.go index eb6720b..0e32540 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go | |||
@@ -76,14 +76,14 @@ func NewSupervisordCollector() (Collector, error) { | |||
76 | func (c *supervisordCollector) isRunning(state int) bool { | 76 | func (c *supervisordCollector) isRunning(state int) bool { |
77 | // http://supervisord.org/subprocess.html#process-states | 77 | // http://supervisord.org/subprocess.html#process-states |
78 | const ( | 78 | const ( |
79 | STOPPED = 0 | 79 | // STOPPED = 0 |
80 | STARTING = 10 | 80 | STARTING = 10 |
81 | RUNNING = 20 | 81 | RUNNING = 20 |
82 | BACKOFF = 30 | 82 | // BACKOFF = 30 |
83 | STOPPING = 40 | 83 | STOPPING = 40 |
84 | EXITED = 100 | 84 | // EXITED = 100 |
85 | FATAL = 200 | 85 | // FATAL = 200 |
86 | UNKNOWN = 1000 | 86 | // UNKNOWN = 1000 |
87 | ) | 87 | ) |
88 | switch state { | 88 | switch state { |
89 | case STARTING, RUNNING, STOPPING: | 89 | case STARTING, RUNNING, STOPPING: |
diff --git a/collector/textfile.go b/collector/textfile.go index ddd88b8..c80de98 100644 --- a/collector/textfile.go +++ b/collector/textfile.go | |||
@@ -95,7 +95,7 @@ func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Me | |||
95 | break | 95 | break |
96 | } | 96 | } |
97 | } | 97 | } |
98 | if present == false { | 98 | if !present { |
99 | names = append(names, k) | 99 | names = append(names, k) |
100 | values = append(values, "") | 100 | values = append(values, "") |
101 | } | 101 | } |
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index ae80650..a964d50 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go | |||
@@ -29,14 +29,14 @@ import ( | |||
29 | // constants from https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h | 29 | // constants from https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h |
30 | // kept as strings for comparison thus avoiding conversion to int | 30 | // kept as strings for comparison thus avoiding conversion to int |
31 | const ( | 31 | const ( |
32 | kstatDataChar = "0" | 32 | // kstatDataChar = "0" |
33 | kstatDataInt32 = "1" | 33 | // kstatDataInt32 = "1" |
34 | kstatDataUint32 = "2" | 34 | // kstatDataUint32 = "2" |
35 | kstatDataInt64 = "3" | 35 | // kstatDataInt64 = "3" |
36 | kstatDataUint64 = "4" | 36 | kstatDataUint64 = "4" |
37 | kstatDataLong = "5" | 37 | // kstatDataLong = "5" |
38 | kstatDataUlong = "6" | 38 | // kstatDataUlong = "6" |
39 | kstatDataString = "7" | 39 | // kstatDataString = "7" |
40 | ) | 40 | ) |
41 | 41 | ||
42 | func (c *zfsCollector) openProcFile(path string) (*os.File, error) { | 42 | func (c *zfsCollector) openProcFile(path string) (*os.File, error) { |