Makefile: add checkmetrics target, use in CI (#797)
This commit is contained in:
parent
3de2542d21
commit
dcb31670d6
20
Makefile
20
Makefile
|
@ -16,6 +16,7 @@ GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
|
||||||
GOARCH := $(shell $(GO) env GOARCH)
|
GOARCH := $(shell $(GO) env GOARCH)
|
||||||
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
|
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
|
||||||
|
|
||||||
|
PROMTOOL ?= $(GOPATH)/bin/promtool
|
||||||
PROMU ?= $(GOPATH)/bin/promu
|
PROMU ?= $(GOPATH)/bin/promu
|
||||||
STATICCHECK ?= $(GOPATH)/bin/staticcheck
|
STATICCHECK ?= $(GOPATH)/bin/staticcheck
|
||||||
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
|
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
|
||||||
|
@ -48,6 +49,12 @@ else
|
||||||
test-e2e := skip-test-e2e
|
test-e2e := skip-test-e2e
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(MACH), ppc64le)
|
||||||
|
e2e-out = collector/fixtures/e2e-ppc64le-output.txt
|
||||||
|
else
|
||||||
|
e2e-out = collector/fixtures/e2e-output.txt
|
||||||
|
endif
|
||||||
|
|
||||||
# 64bit -> 32bit mapping for cross-checking. At least for amd64/386, the 64bit CPU can execute 32bit code but not the other way around, so we don't support cross-testing upwards.
|
# 64bit -> 32bit mapping for cross-checking. At least for amd64/386, the 64bit CPU can execute 32bit code but not the other way around, so we don't support cross-testing upwards.
|
||||||
cross-test = skip-test-32bit
|
cross-test = skip-test-32bit
|
||||||
define goarch_pair
|
define goarch_pair
|
||||||
|
@ -65,7 +72,7 @@ $(eval $(call goarch_pair,arm64,arm))
|
||||||
$(eval $(call goarch_pair,mips64,mips))
|
$(eval $(call goarch_pair,mips64,mips))
|
||||||
$(eval $(call goarch_pair,mips64el,mipsel))
|
$(eval $(call goarch_pair,mips64el,mipsel))
|
||||||
|
|
||||||
all: format vet staticcheck build test $(cross-test) $(test-e2e)
|
all: format vet staticcheck checkmetrics build test $(cross-test) $(test-e2e)
|
||||||
|
|
||||||
style:
|
style:
|
||||||
@echo ">> checking code style"
|
@echo ">> checking code style"
|
||||||
|
@ -93,6 +100,10 @@ test-e2e: build collector/fixtures/sys/.unpacked
|
||||||
skip-test-e2e:
|
skip-test-e2e:
|
||||||
@echo ">> SKIP running end-to-end tests on $(OS_detected)"
|
@echo ">> SKIP running end-to-end tests on $(OS_detected)"
|
||||||
|
|
||||||
|
checkmetrics: $(PROMTOOL)
|
||||||
|
@echo ">> checking metrics for correctness"
|
||||||
|
./checkmetrics.sh $(PROMTOOL) $(e2e-out)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
@echo ">> formatting code"
|
@echo ">> formatting code"
|
||||||
@$(GO) fmt $(pkgs)
|
@$(GO) fmt $(pkgs)
|
||||||
|
@ -124,6 +135,9 @@ test-docker:
|
||||||
@echo ">> testing docker image"
|
@echo ">> testing docker image"
|
||||||
./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100
|
./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9100
|
||||||
|
|
||||||
|
$(GOPATH)/bin/promtool promtool:
|
||||||
|
@GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool
|
||||||
|
|
||||||
$(GOPATH)/bin/promu promu:
|
$(GOPATH)/bin/promu promu:
|
||||||
@GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
|
@GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
|
||||||
|
|
||||||
|
@ -131,10 +145,10 @@ $(GOPATH)/bin/staticcheck:
|
||||||
@GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
|
@GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all style format build test test-e2e vet tarball docker promu staticcheck
|
.PHONY: all style format build test test-e2e vet tarball docker promtool promu staticcheck checkmetrics
|
||||||
|
|
||||||
# Declaring the binaries at their default locations as PHONY targets is a hack
|
# Declaring the binaries at their default locations as PHONY targets is a hack
|
||||||
# to ensure the latest version is downloaded on every make execution.
|
# to ensure the latest version is downloaded on every make execution.
|
||||||
# If this is not desired, copy/symlink these binaries to a different path and
|
# If this is not desired, copy/symlink these binaries to a different path and
|
||||||
# set the respective environment variables.
|
# set the respective environment variables.
|
||||||
.PHONY: $(GOPATH)/bin/promu $(GOPATH)/bin/staticcheck
|
.PHONY: $(GOPATH)/bin/promtool $(GOPATH)/bin/promu $(GOPATH)/bin/staticcheck
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ ( -z "$1" ) || ( -z "$2" ) ]]; then
|
||||||
|
echo "usage: ./checkmetrics.sh /usr/bin/promtool e2e-output.txt"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Only check node_exporter's metrics, as the Prometheus Go client currently
|
||||||
|
# exposes a metric with a unit of microseconds. Once that is fixed, remove
|
||||||
|
# this filter.
|
||||||
|
lint=$($1 check metrics < $2 2>&1 | grep "node_")
|
||||||
|
|
||||||
|
if [[ ! -z $lint ]]; then
|
||||||
|
echo -e "Some Prometheus metrics do not follow best practices:\n"
|
||||||
|
echo "$lint"
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -148,4 +148,4 @@ get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-outpu
|
||||||
|
|
||||||
diff -u \
|
diff -u \
|
||||||
"${fixture}" \
|
"${fixture}" \
|
||||||
"${tmpdir}/e2e-output.txt"
|
"${tmpdir}/e2e-output.txt"
|
Loading…
Reference in New Issue