node_exporter
/
Makefile
147 строк · 4.4 Кб
1# Copyright 2015 The Prometheus Authors
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
15all::16
17# Needs to be defined before including Makefile.common to auto-generate targets
18DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le s390x19
20include Makefile.common21
22PROMTOOL_VERSION ?= 2.30.023PROMTOOL_URL ?= https://github.com/prometheus/prometheus/releases/download/v$(PROMTOOL_VERSION)/prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM).tar.gz24PROMTOOL ?= $(FIRST_GOPATH)/bin/promtool25
26DOCKER_IMAGE_NAME ?= node-exporter27MACH ?= $(shell uname -m)28
29STATICCHECK_IGNORE =30
31ifeq ($(GOHOSTOS), linux)32test-e2e := test-e2e33else
34test-e2e := skip-test-e2e35endif
36
37# Use CGO for non-Linux builds.
38ifeq ($(GOOS), linux)39PROMU_CONF ?= .promu.yml40else
41ifndef GOOS42ifeq ($(GOHOSTOS), linux)43PROMU_CONF ?= .promu.yml44else45PROMU_CONF ?= .promu-cgo.yml46endif47else48# Do not use CGO for openbsd/amd64 builds49ifeq ($(GOOS), openbsd)50ifeq ($(GOARCH), amd64)51PROMU_CONF ?= .promu.yml52else53PROMU_CONF ?= .promu-cgo.yml54endif55else56PROMU_CONF ?= .promu-cgo.yml57endif58endif59endif
60
61PROMU := $(FIRST_GOPATH)/bin/promu --config $(PROMU_CONF)62
63e2e-out-64k-page = collector/fixtures/e2e-64k-page-output.txt64e2e-out = collector/fixtures/e2e-output.txt65ifeq ($(MACH), ppc64le)66e2e-out = $(e2e-out-64k-page)67endif
68ifeq ($(MACH), aarch64)69e2e-out = $(e2e-out-64k-page)70endif
71
72# 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.
73cross-test = skip-test-32bit74define goarch_pair75ifeq ($$(GOHOSTOS),linux)76ifeq ($$(GOHOSTARCH),$1)77GOARCH_CROSS = $278cross-test = test-32bit79endif80endif81endef
82
83# By default, "cross" test with ourselves to cover unknown pairings.
84$(eval $(call goarch_pair,amd64,386))85$(eval $(call goarch_pair,mips64,mips))86$(eval $(call goarch_pair,mips64el,mipsel))87
88all:: vet checkmetrics checkrules common-all $(cross-test) $(test-e2e)89
90.PHONY: test91test: collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked92@echo ">> running tests"93$(GO) test -short $(test-flags) $(pkgs)94
95.PHONY: test-32bit96test-32bit: collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked97@echo ">> running tests in 32-bit mode"98@env GOARCH=$(GOARCH_CROSS) $(GO) test $(pkgs)99
100.PHONY: skip-test-32bit101skip-test-32bit:102@echo ">> SKIP running tests in 32-bit mode: not supported on $(GOHOSTOS)/$(GOHOSTARCH)"103
104%/.unpacked: %.ttar105@echo ">> extracting fixtures"106if [ -d $(dir $@) ] ; then rm -rf $(dir $@) ; fi107./ttar -C $(dir $*) -x -f $*.ttar108touch $@109
110update_fixtures:111rm -vf collector/fixtures/sys/.unpacked
112./ttar -C collector/fixtures -c -f collector/fixtures/sys.ttar sys
113rm -vf collector/fixtures/udev/.unpacked
114./ttar -C collector/fixtures -c -f collector/fixtures/udev.ttar udev
115
116
117.PHONY: test-e2e118test-e2e: build collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked119@echo ">> running end-to-end tests"120./end-to-end-test.sh
121
122.PHONY: skip-test-e2e123skip-test-e2e:124@echo ">> SKIP running end-to-end tests on $(GOHOSTOS)"125
126.PHONY: checkmetrics127checkmetrics: $(PROMTOOL)128@echo ">> checking metrics for correctness"129./checkmetrics.sh $(PROMTOOL) $(e2e-out)130./checkmetrics.sh $(PROMTOOL) $(e2e-out-64k-page)131
132.PHONY: checkrules133checkrules: $(PROMTOOL)134@echo ">> checking rules for correctness"135find . -name "*rules*.yml" | xargs -I {} $(PROMTOOL) check rules {}136
137.PHONY: test-docker138test-docker:139@echo ">> testing docker image"140./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9100141
142.PHONY: promtool143promtool: $(PROMTOOL)144
145$(PROMTOOL):146mkdir -p $(FIRST_GOPATH)/bin147curl -fsS -L $(PROMTOOL_URL) | tar -xvzf - -C $(FIRST_GOPATH)/bin --strip 1 "prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM)/promtool"148