2015-03-09 11:14:42 -07:00
# Copyright 2015 The Prometheus Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2014-04-09 16:20:52 -07:00
2019-03-25 04:47:57 -07:00
# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
all ::
2019-04-15 08:36:25 -07:00
# Needs to be defined before including Makefile.common to auto-generate targets
2020-01-27 01:55:35 -08:00
DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le s390x
2019-04-15 08:36:25 -07:00
2018-05-24 14:31:48 -07:00
i n c l u d e M a k e f i l e . c o m m o n
2021-09-22 11:40:04 -07:00
PROMTOOL_VERSION ?= 2.30.0
2018-11-30 05:01:20 -08:00
PROMTOOL_URL ?= https://github.com/prometheus/prometheus/releases/download/v$( PROMTOOL_VERSION) /prometheus-$( PROMTOOL_VERSION) .$( GO_BUILD_PLATFORM) .tar.gz
PROMTOOL ?= $( FIRST_GOPATH) /bin/promtool
2015-12-17 07:06:58 -08:00
2016-01-24 14:38:06 -08:00
DOCKER_IMAGE_NAME ?= node-exporter
2017-08-17 02:53:04 -07:00
MACH ?= $( shell uname -m)
2015-12-17 07:06:58 -08:00
2018-02-19 06:44:59 -08:00
STATICCHECK_IGNORE =
2017-10-14 05:23:42 -07:00
2019-01-23 12:44:12 -08:00
i f e q ( $( GOHOSTOS ) , l i n u x )
2018-09-25 07:02:42 -07:00
test-e2e := test-e2e
2017-02-28 04:04:52 -08:00
e l s e
2018-09-25 07:02:42 -07:00
test-e2e := skip-test-e2e
2017-02-28 04:04:52 -08:00
e n d i f
2018-09-25 07:02:42 -07:00
# Use CGO for non-Linux builds.
i f e q ( $( GOOS ) , l i n u x )
2018-10-19 23:21:51 -07:00
PROMU_CONF ?= .promu.yml
2018-09-25 07:02:42 -07:00
e l s e
ifndef GOOS
2019-02-04 11:10:26 -08:00
ifeq ( $( GOHOSTOS) , linux)
2018-10-19 23:21:51 -07:00
PROMU_CONF ?= .promu.yml
2018-09-25 07:02:42 -07:00
else
PROMU_CONF ?= .promu-cgo.yml
endif
else
2020-07-02 05:43:14 -07:00
# Do not use CGO for openbsd/amd64 builds
ifeq ( $( GOOS) , openbsd)
ifeq ( $( GOARCH) , amd64)
PROMU_CONF ?= .promu.yml
else
PROMU_CONF ?= .promu-cgo.yml
endif
else
PROMU_CONF ?= .promu-cgo.yml
endif
2018-09-25 07:02:42 -07:00
endif
e n d i f
PROMU := $( FIRST_GOPATH) /bin/promu --config $( PROMU_CONF)
2021-12-09 02:48:57 -08:00
e2e-out-64k-page = collector/fixtures/e2e-64k-page-output.txt
2018-05-14 06:55:49 -07:00
e2e-out = collector/fixtures/e2e-output.txt
2018-02-13 09:04:03 -08:00
i f e q ( $( MACH ) , p p c 6 4 l e )
2021-12-09 02:48:57 -08:00
e2e-out = $( e2e-out-64k-page)
2018-05-14 06:55:49 -07:00
e n d i f
i f e q ( $( MACH ) , a a r c h 6 4 )
2021-12-09 02:48:57 -08:00
e2e-out = $( e2e-out-64k-page)
2018-02-13 09:04:03 -08:00
e n d i f
2017-08-21 09:46:43 -07:00
# 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
d e f i n e g o a r c h _ p a i r
2019-01-23 12:44:12 -08:00
ifeq ( $$ ( GOHOSTOS) ,linux)
ifeq ( $$ ( GOHOSTARCH) ,$1 )
2017-08-24 00:13:17 -07:00
GOARCH_CROSS = $2
cross-test = test-32bit
endif
endif
2017-08-21 09:46:43 -07:00
e n d e f
# By default, "cross" test with ourselves to cover unknown pairings.
$( eval $ ( call goarch_pair ,amd 64,386) )
$( eval $ ( call goarch_pair ,mips 64,mips ) )
$( eval $ ( call goarch_pair ,mips 64el ,mipsel ) )
2019-03-25 04:47:57 -07:00
all :: vet checkmetrics checkrules common -all $( cross -test ) $( test -e 2e )
2014-04-09 16:20:52 -07:00
2018-07-23 00:38:39 -07:00
.PHONY : test
2022-09-27 14:07:57 -07:00
test : collector /fixtures /sys /.unpacked collector /fixtures /udev /.unpacked
2016-01-24 14:38:06 -08:00
@echo ">> running tests"
2017-10-03 13:40:22 -07:00
$( GO) test -short $( test-flags) $( pkgs)
2016-01-24 14:38:06 -08:00
2018-07-23 00:38:39 -07:00
.PHONY : test -32bit
2022-09-27 14:07:57 -07:00
test-32bit : collector /fixtures /sys /.unpacked collector /fixtures /udev /.unpacked
2017-08-21 09:46:43 -07:00
@echo ">> running tests in 32-bit mode"
@env GOARCH = $( GOARCH_CROSS) $( GO) test $( pkgs)
2018-07-23 00:38:39 -07:00
.PHONY : skip -test -32bit
2017-08-21 09:46:43 -07:00
skip-test-32bit :
2019-01-23 12:44:12 -08:00
@echo " >> SKIP running tests in 32-bit mode: not supported on $( GOHOSTOS) / $( GOHOSTARCH) "
2017-08-21 09:46:43 -07:00
2019-11-23 05:52:47 -08:00
%/.unpacked : %.ttar
@echo ">> extracting fixtures"
2021-05-20 13:31:45 -07:00
if [ -d $( dir $@ ) ] ; then rm -rf $( dir $@ ) ; fi
2019-11-23 05:52:47 -08:00
./ttar -C $( dir $* ) -x -f $* .ttar
Add bcache collector (#597)
* Add bcache collector for Linux
This collector gathers metrics related to the Linux block cache
(bcache) from sysfs.
* Removed commented out code
* Use project comment style
* Add _sectors to metric name to indicate unit
* Really use project comment style
* Rename bcache.go to bcache_linux.go
* Keep collector namespace clean
Rename:
- metric -> bcacheMetric
- periodStatsToMetrics -> bcachePeriodStatsToMetric
* Shorten slice initialization
* Change label names to backing_device, cache_device
* Remove five minute metrics (keep only total)
* Include units in additional metric names
* Enable bcache collector by default
* Provide metrics in seconds, not nanoseconds
* remove metrics with label "all"
* Add fixtures, update end-to-end for bcache collector
* Move fixtures/sys into tar.gz
This changeset moves the collector/fixtures/sys directory into
collector/fixtures/sys.tar.gz and tweaks the Makefile to unpack the
tarball before tests are run.
The reason for this change is that Windows does not allow colons in a
path (colons are present in some of the bcache fixture files), nor can
it (out of the box) deal with pathnames longer than 260 characters
(which we would be increasingly likely to hit if we tried to replace
colons with longer codes that are guaranteed not the turn up in regular
file names).
* Add ttar: plain text archive, replacement for tar
This changeset adds ttar, a plain text replacement for tar, and uses it
for the sysfs fixture archive. The syntax is loosely based on tar(1).
Using a plain text archive makes it possible to review changes without
downloading and extracting the archive. Also, when working on the repo,
git diff and git log become useful again, allowing a committer to verify
and track changes over time.
The code is written in bash, because bash is available out of the box on
all major flavors of Linux and on macOS. The feature set used is
restricted to bash version 3.2 because that is what Apple is still
shipping.
The programm also works on Windows if bash is installed. Obviously, it
does not solve the Windows limitations (path length limited to 260
characters, no symbolic links) that prompted the move to an archive
format in the first place.
2017-07-06 22:20:18 -07:00
touch $@
2019-11-23 05:52:47 -08:00
update_fixtures :
rm -vf collector/fixtures/sys/.unpacked
./ttar -C collector/fixtures -c -f collector/fixtures/sys.ttar sys
2022-09-27 14:07:57 -07:00
rm -vf collector/fixtures/udev/.unpacked
./ttar -C collector/fixtures -c -f collector/fixtures/udev.ttar udev
2019-11-23 05:52:47 -08:00
2018-07-23 00:38:39 -07:00
.PHONY : test -e 2e
2022-09-27 14:07:57 -07:00
test-e2e : build collector /fixtures /sys /.unpacked collector /fixtures /udev /.unpacked
2016-12-21 03:00:32 -08:00
@echo ">> running end-to-end tests"
./end-to-end-test.sh
2018-07-23 00:38:39 -07:00
.PHONY : skip -test -e 2e
2017-02-28 04:04:52 -08:00
skip-test-e2e :
2019-01-23 12:44:12 -08:00
@echo " >> SKIP running end-to-end tests on $( GOHOSTOS) "
2017-02-28 04:04:52 -08:00
2018-07-23 00:38:39 -07:00
.PHONY : checkmetrics
2018-02-13 09:04:03 -08:00
checkmetrics : $( PROMTOOL )
@echo ">> checking metrics for correctness"
./checkmetrics.sh $( PROMTOOL) $( e2e-out)
2021-12-09 02:48:57 -08:00
./checkmetrics.sh $( PROMTOOL) $( e2e-out-64k-page)
2018-02-13 09:04:03 -08:00
2018-10-30 10:44:17 -07:00
.PHONY : checkrules
checkrules : $( PROMTOOL )
@echo ">> checking rules for correctness"
find . -name "*rules*.yml" | xargs -I { } $( PROMTOOL) check rules { }
2018-07-23 00:38:39 -07:00
.PHONY : test -docker
2017-01-24 02:19:44 -08:00
test-docker :
@echo ">> testing docker image"
2019-04-15 08:36:25 -07:00
./test_image.sh " $( DOCKER_REPO) / $( DOCKER_IMAGE_NAME) -linux-amd64: $( DOCKER_IMAGE_TAG) " 9100
2017-01-24 02:19:44 -08:00
2018-11-30 05:01:20 -08:00
.PHONY : promtool
promtool : $( PROMTOOL )
$(PROMTOOL) :
mkdir -p $( FIRST_GOPATH) /bin
2021-09-14 07:46:44 -07:00
curl -fsS -L $( PROMTOOL_URL) | tar -xvzf - -C $( FIRST_GOPATH) /bin --strip 1 " prometheus- $( PROMTOOL_VERSION) . $( GO_BUILD_PLATFORM) /promtool "