node_exporter

Форк
0
/
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.
15
all::
16

17
# Needs to be defined before including Makefile.common to auto-generate targets
18
DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le s390x
19

20
include Makefile.common
21

22
PROMTOOL_VERSION ?= 2.30.0
23
PROMTOOL_URL     ?= https://github.com/prometheus/prometheus/releases/download/v$(PROMTOOL_VERSION)/prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM).tar.gz
24
PROMTOOL         ?= $(FIRST_GOPATH)/bin/promtool
25

26
DOCKER_IMAGE_NAME       ?= node-exporter
27
MACH                    ?= $(shell uname -m)
28

29
STATICCHECK_IGNORE =
30

31
ifeq ($(GOHOSTOS), linux)
32
	test-e2e := test-e2e
33
else
34
	test-e2e := skip-test-e2e
35
endif
36

37
# Use CGO for non-Linux builds.
38
ifeq ($(GOOS), linux)
39
	PROMU_CONF ?= .promu.yml
40
else
41
	ifndef GOOS
42
		ifeq ($(GOHOSTOS), linux)
43
			PROMU_CONF ?= .promu.yml
44
		else
45
			PROMU_CONF ?= .promu-cgo.yml
46
		endif
47
	else
48
		# Do not use CGO for openbsd/amd64 builds
49
		ifeq ($(GOOS), openbsd)
50
			ifeq ($(GOARCH), amd64)
51
				PROMU_CONF ?= .promu.yml
52
			else
53
				PROMU_CONF ?= .promu-cgo.yml
54
			endif
55
		else
56
			PROMU_CONF ?= .promu-cgo.yml
57
		endif
58
	endif
59
endif
60

61
PROMU := $(FIRST_GOPATH)/bin/promu --config $(PROMU_CONF)
62

63
e2e-out-64k-page = collector/fixtures/e2e-64k-page-output.txt
64
e2e-out = collector/fixtures/e2e-output.txt
65
ifeq ($(MACH), ppc64le)
66
	e2e-out = $(e2e-out-64k-page)
67
endif
68
ifeq ($(MACH), aarch64)
69
	e2e-out = $(e2e-out-64k-page)
70
endif
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.
73
cross-test = skip-test-32bit
74
define goarch_pair
75
	ifeq ($$(GOHOSTOS),linux)
76
		ifeq ($$(GOHOSTARCH),$1)
77
			GOARCH_CROSS = $2
78
			cross-test = test-32bit
79
		endif
80
	endif
81
endef
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

88
all:: vet checkmetrics checkrules common-all $(cross-test) $(test-e2e)
89

90
.PHONY: test
91
test: collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked
92
	@echo ">> running tests"
93
	$(GO) test -short $(test-flags) $(pkgs)
94

95
.PHONY: test-32bit
96
test-32bit: collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked
97
	@echo ">> running tests in 32-bit mode"
98
	@env GOARCH=$(GOARCH_CROSS) $(GO) test $(pkgs)
99

100
.PHONY: skip-test-32bit
101
skip-test-32bit:
102
	@echo ">> SKIP running tests in 32-bit mode: not supported on $(GOHOSTOS)/$(GOHOSTARCH)"
103

104
%/.unpacked: %.ttar
105
	@echo ">> extracting fixtures"
106
	if [ -d $(dir $@) ] ; then rm -rf $(dir $@) ; fi
107
	./ttar -C $(dir $*) -x -f $*.ttar
108
	touch $@
109

110
update_fixtures:
111
	rm -vf collector/fixtures/sys/.unpacked
112
	./ttar -C collector/fixtures -c -f collector/fixtures/sys.ttar sys
113
	rm -vf collector/fixtures/udev/.unpacked
114
	./ttar -C collector/fixtures -c -f collector/fixtures/udev.ttar udev
115

116

117
.PHONY: test-e2e
118
test-e2e: build collector/fixtures/sys/.unpacked collector/fixtures/udev/.unpacked
119
	@echo ">> running end-to-end tests"
120
	./end-to-end-test.sh
121

122
.PHONY: skip-test-e2e
123
skip-test-e2e:
124
	@echo ">> SKIP running end-to-end tests on $(GOHOSTOS)"
125

126
.PHONY: checkmetrics
127
checkmetrics: $(PROMTOOL)
128
	@echo ">> checking metrics for correctness"
129
	./checkmetrics.sh $(PROMTOOL) $(e2e-out)
130
	./checkmetrics.sh $(PROMTOOL) $(e2e-out-64k-page)
131

132
.PHONY: checkrules
133
checkrules: $(PROMTOOL)
134
	@echo ">> checking rules for correctness"
135
	find . -name "*rules*.yml" | xargs -I {} $(PROMTOOL) check rules {}
136

137
.PHONY: test-docker
138
test-docker:
139
	@echo ">> testing docker image"
140
	./test_image.sh "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-amd64:$(DOCKER_IMAGE_TAG)" 9100
141

142
.PHONY: promtool
143
promtool: $(PROMTOOL)
144

145
$(PROMTOOL):
146
	mkdir -p $(FIRST_GOPATH)/bin
147
	curl -fsS -L $(PROMTOOL_URL) | tar -xvzf - -C $(FIRST_GOPATH)/bin --strip 1 "prometheus-$(PROMTOOL_VERSION).$(GO_BUILD_PLATFORM)/promtool"
148

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.