mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-26 06:04:20 -08:00
Add an end-to-end test.
This test runs a selection of collectors against the fixtures and compares the output to a reference. The uname and filesystem collectors are disabled because they use system calls that cannot be fixtured easily.
This commit is contained in:
parent
788ac9a859
commit
7c47338081
|
@ -11,3 +11,5 @@ install:
|
|||
|
||||
script:
|
||||
- go test -v ./...
|
||||
- go build
|
||||
- ./end-to-end-test.sh -v
|
||||
|
|
1286
collector/fixtures/e2e-output.txt
Normal file
1286
collector/fixtures/e2e-output.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cat fixtures/megacli_disks.txt
|
||||
cat "$(dirname "$0")/megacli_disks.txt"
|
||||
|
|
|
@ -226,6 +226,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
|||
_, err = os.Stat(statusfile)
|
||||
if os.IsNotExist(err) {
|
||||
// no such file or directory, nothing to do, just return
|
||||
log.Debugf("Not collecting mdstat, file does not exist: %s", statusfile)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
91
end-to-end-test.sh
Executable file
91
end-to-end-test.sh
Executable file
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set +euf +o pipefail
|
||||
|
||||
cd "$(dirname $0)"
|
||||
|
||||
port="$((10000 + (RANDOM % 10000)))"
|
||||
tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
|
||||
|
||||
skip_re="^(go_|node_exporter_|process_|node_textfile_mtime)"
|
||||
|
||||
keep=0; update=0; verbose=0
|
||||
while getopts 'hkuv' opt
|
||||
do
|
||||
case "$opt" in
|
||||
k)
|
||||
keep=1
|
||||
;;
|
||||
u)
|
||||
update=1
|
||||
;;
|
||||
v)
|
||||
verbose=1
|
||||
set -x
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [-k] [-u] [-v]"
|
||||
echo " -k: keep temporary files and leave node_exporter running"
|
||||
echo " -u: update fixture"
|
||||
echo " -v: verbose output"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
./node_exporter \
|
||||
-collector.procfs="collector/fixtures/proc" \
|
||||
-collector.sysfs="collector/fixtures/sys" \
|
||||
-collectors.enabled="diskstats,filefd,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,bonding,megacli" \
|
||||
-collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
|
||||
-collector.megacli.command="collector/fixtures/megacli" \
|
||||
-web.listen-address "127.0.0.1:${port}" \
|
||||
-log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
|
||||
|
||||
echo $! > "${tmpdir}/node_exporter.pid"
|
||||
|
||||
finish() {
|
||||
if [ ${verbose} -ne 0 ]
|
||||
then
|
||||
echo "LOG ====================="
|
||||
cat "${tmpdir}/node_exporter.log"
|
||||
echo "========================="
|
||||
fi
|
||||
|
||||
if [ ${update} -ne 0 ]
|
||||
then
|
||||
cp "${tmpdir}/e2e-output.txt" "collector/fixtures/e2e-output.txt"
|
||||
fi
|
||||
|
||||
if [ ${keep} -eq 0 ]
|
||||
then
|
||||
kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
|
||||
# This silences the "Killed" message
|
||||
wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
|
||||
rm -rf "${tmpdir}"
|
||||
fi
|
||||
}
|
||||
|
||||
trap finish EXIT
|
||||
|
||||
get() {
|
||||
if which curl > /dev/null 2>&1
|
||||
then
|
||||
curl -s -f "$@"
|
||||
elif which wget > /dev/null 2>&1
|
||||
then
|
||||
wget -O - "$@"
|
||||
else
|
||||
echo "Neither curl nor wget found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
sleep 1
|
||||
|
||||
get "127.0.0.1:${port}/metrics" > "${tmpdir}/e2e-output.txt"
|
||||
|
||||
diff -u \
|
||||
<(grep -E -v "${skip_re}" "collector/fixtures/e2e-output.txt") \
|
||||
<(grep -E -v "${skip_re}" "${tmpdir}/e2e-output.txt")
|
Loading…
Reference in a new issue