Skip to content

Commit 3a8bcb0

Browse files
committed
Add FreeBSD pipeline.
Signed-off-by: K Rin <[email protected]>
1 parent 0fddfd1 commit 3a8bcb0

File tree

4 files changed

+361
-13
lines changed

4 files changed

+361
-13
lines changed

.github/workflows/freebsd-ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: freebsd-ci
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
GO_VERSION: "123"
16+
17+
jobs:
18+
test:
19+
name: e2e-tests
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout the repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup FreeBSD
26+
uses: vmactions/freebsd-vm@v1
27+
with:
28+
envs: 'GO_VERSION'
29+
usesh: true
30+
prepare: |
31+
pkg update -f
32+
pkg install -y bash curl git gmake go${GO_VERSION} python
33+
run: |
34+
ln -s /usr/local/bin/bash /usr/bin/bash
35+
gmake test-e2e
36+
rm -rf "node_exporter/node_exporter/collector/fixtures/proc/self"

Makefile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ MACH ?= $(shell uname -m)
2828

2929
STATICCHECK_IGNORE =
3030

31-
ifeq ($(GOHOSTOS), linux)
32-
test-e2e := test-e2e
33-
else
34-
test-e2e := skip-test-e2e
35-
endif
36-
3731
# Use CGO for non-Linux builds.
3832
ifeq ($(GOOS), linux)
3933
PROMU_CONF ?= .promu.yml
@@ -113,15 +107,17 @@ update_fixtures:
113107
rm -vf collector/fixtures/udev/.unpacked
114108
./ttar -C collector/fixtures -c -f collector/fixtures/udev.ttar udev
115109

116-
117110
.PHONY: test-e2e
118111
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)"
112+
if [ "$(GOHOSTOS)" = "linux" ]; then \
113+
./end-to-end-test.sh; \
114+
elif [ "$(GOHOSTOS)" = "freebsd" ]; then \
115+
./end-to-end-test-freebsd.sh; \
116+
fi
117+
118+
# .PHONY: skip-test-e2e
119+
# skip-test-e2e:
120+
# @echo ">> SKIP running end-to-end tests on $(GOHOSTOS)"
125121

126122
.PHONY: checkmetrics
127123
checkmetrics: $(PROMTOOL)
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# HELP go_gc_duration_seconds A summary of the wall-time pause (stop-the-world) duration in garbage collection cycles.
2+
# TYPE go_gc_duration_seconds summary
3+
# HELP go_gc_gogc_percent Heap size target percentage configured by the user, otherwise 100. This value is set by the GOGC environment variable, and the runtime/debug.SetGCPercent function. Sourced from /gc/gogc:percent
4+
# TYPE go_gc_gogc_percent gauge
5+
# HELP go_gc_gomemlimit_bytes Go runtime memory limit configured by the user, otherwise math.MaxInt64. This value is set by the GOMEMLIMIT environment variable, and the runtime/debug.SetMemoryLimit function. Sourced from /gc/gomemlimit:bytes
6+
# TYPE go_gc_gomemlimit_bytes gauge
7+
# HELP go_goroutines Number of goroutines that currently exist.
8+
# TYPE go_goroutines gauge
9+
# HELP go_info Information about the Go environment.
10+
# TYPE go_info gauge
11+
# HELP go_memstats_alloc_bytes Number of bytes allocated in heap and currently in use. Equals to /memory/classes/heap/objects:bytes.
12+
# TYPE go_memstats_alloc_bytes gauge
13+
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated in heap until now, even if released already. Equals to /gc/heap/allocs:bytes.
14+
# TYPE go_memstats_alloc_bytes_total counter
15+
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. Equals to /memory/classes/profiling/buckets:bytes.
16+
# TYPE go_memstats_buck_hash_sys_bytes gauge
17+
# HELP go_memstats_frees_total Total number of heap objects frees. Equals to /gc/heap/frees:objects + /gc/heap/tiny/allocs:objects.
18+
# TYPE go_memstats_frees_total counter
19+
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata. Equals to /memory/classes/metadata/other:bytes.
20+
# TYPE go_memstats_gc_sys_bytes gauge
21+
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and currently in use, same as go_memstats_alloc_bytes. Equals to /memory/classes/heap/objects:bytes.
22+
# TYPE go_memstats_heap_alloc_bytes gauge
23+
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used. Equals to /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
24+
# TYPE go_memstats_heap_idle_bytes gauge
25+
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes
26+
# TYPE go_memstats_heap_inuse_bytes gauge
27+
# HELP go_memstats_heap_objects Number of currently allocated objects. Equals to /gc/heap/objects:objects.
28+
# TYPE go_memstats_heap_objects gauge
29+
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS. Equals to /memory/classes/heap/released:bytes.
30+
# TYPE go_memstats_heap_released_bytes gauge
31+
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes + /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.
32+
# TYPE go_memstats_heap_sys_bytes gauge
33+
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
34+
# TYPE go_memstats_last_gc_time_seconds gauge
35+
# HELP go_memstats_mallocs_total Total number of heap objects allocated, both live and gc-ed. Semantically a counter version for go_memstats_heap_objects gauge. Equals to /gc/heap/allocs:objects + /gc/heap/tiny/allocs:objects.
36+
# TYPE go_memstats_mallocs_total counter
37+
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures. Equals to /memory/classes/metadata/mcache/inuse:bytes.
38+
# TYPE go_memstats_mcache_inuse_bytes gauge
39+
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system. Equals to /memory/classes/metadata/mcache/inuse:bytes + /memory/classes/metadata/mcache/free:bytes.
40+
# TYPE go_memstats_mcache_sys_bytes gauge
41+
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures. Equals to /memory/classes/metadata/mspan/inuse:bytes.
42+
# TYPE go_memstats_mspan_inuse_bytes gauge
43+
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system. Equals to /memory/classes/metadata/mspan/inuse:bytes + /memory/classes/metadata/mspan/free:bytes.
44+
# TYPE go_memstats_mspan_sys_bytes gauge
45+
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place. Equals to /gc/heap/goal:bytes.
46+
# TYPE go_memstats_next_gc_bytes gauge
47+
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations. Equals to /memory/classes/other:bytes.
48+
# TYPE go_memstats_other_sys_bytes gauge
49+
# HELP go_memstats_stack_inuse_bytes Number of bytes obtained from system for stack allocator in non-CGO environments. Equals to /memory/classes/heap/stacks:bytes.
50+
# TYPE go_memstats_stack_inuse_bytes gauge
51+
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator. Equals to /memory/classes/heap/stacks:bytes + /memory/classes/os-stacks:bytes.
52+
# TYPE go_memstats_stack_sys_bytes gauge
53+
# HELP go_memstats_sys_bytes Number of bytes obtained from system. Equals to /memory/classes/total:byte.
54+
# TYPE go_memstats_sys_bytes gauge
55+
# HELP go_sched_gomaxprocs_threads The current runtime.GOMAXPROCS setting, or the number of operating system threads that can execute user-level Go code simultaneously. Sourced from /sched/gomaxprocs:threads
56+
# TYPE go_sched_gomaxprocs_threads gauge
57+
# HELP go_threads Number of OS threads created.
58+
# TYPE go_threads gauge
59+
# HELP node_boot_time_seconds Unix time of last boot, including microseconds.
60+
# TYPE node_boot_time_seconds gauge
61+
# HELP node_cpu_seconds_total Seconds the CPUs spent in each mode.
62+
# TYPE node_cpu_seconds_total counter
63+
# HELP node_exec_context_switches_total Context switches since system boot. Resets at architecture unsigned integer.
64+
# TYPE node_exec_context_switches_total counter
65+
# HELP node_exec_device_interrupts_total Device interrupts since system boot. Resets at architecture unsigned integer.
66+
# TYPE node_exec_device_interrupts_total counter
67+
# HELP node_exec_forks_total Number of fork() calls since system boot. Resets at architecture unsigned integer.
68+
# TYPE node_exec_forks_total counter
69+
# HELP node_exec_software_interrupts_total Software interrupts since system boot. Resets at architecture unsigned integer.
70+
# TYPE node_exec_software_interrupts_total counter
71+
# HELP node_exec_system_calls_total System calls since system boot. Resets at architecture unsigned integer.
72+
# TYPE node_exec_system_calls_total counter
73+
# HELP node_exec_traps_total Traps since system boot. Resets at architecture unsigned integer.
74+
# TYPE node_exec_traps_total counter
75+
# HELP node_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, goversion from which node_exporter was built, and the goos and goarch for the build.
76+
# TYPE node_exporter_build_info gauge
77+
# HELP node_load1 1m load average.
78+
# TYPE node_load1 gauge
79+
# HELP node_load15 15m load average.
80+
# TYPE node_load15 gauge
81+
# HELP node_load5 5m load average.
82+
# TYPE node_load5 gauge
83+
# HELP node_memory_active_bytes Recently used by userland
84+
# TYPE node_memory_active_bytes gauge
85+
# HELP node_memory_buffer_bytes Disk IO Cache entries for non ZFS filesystems, only usable by kernel
86+
# TYPE node_memory_buffer_bytes gauge
87+
# HELP node_memory_cache_bytes Almost free, backed by swap or files, available for re-allocation
88+
# TYPE node_memory_cache_bytes gauge
89+
# HELP node_memory_free_bytes Unallocated, available for allocation
90+
# TYPE node_memory_free_bytes gauge
91+
# HELP node_memory_inactive_bytes Not recently used by userland
92+
# TYPE node_memory_inactive_bytes gauge
93+
# HELP node_memory_laundry_bytes Dirty not recently used by userland
94+
# TYPE node_memory_laundry_bytes gauge
95+
# HELP node_memory_size_bytes Total physical memory size
96+
# TYPE node_memory_size_bytes gauge
97+
# HELP node_memory_swap_in_bytes_total Bytes paged in from swap devices
98+
# TYPE node_memory_swap_in_bytes_total counter
99+
# HELP node_memory_swap_out_bytes_total Bytes paged out to swap devices
100+
# TYPE node_memory_swap_out_bytes_total counter
101+
# HELP node_memory_swap_size_bytes Total swap memory size
102+
# TYPE node_memory_swap_size_bytes gauge
103+
# HELP node_memory_swap_used_bytes Currently allocated swap
104+
# TYPE node_memory_swap_used_bytes gauge
105+
# HELP node_memory_user_wired_bytes Locked in memory by user, mlock, etc
106+
# TYPE node_memory_user_wired_bytes gauge
107+
# HELP node_memory_wired_bytes Locked in memory by kernel, mlock, etc
108+
# TYPE node_memory_wired_bytes gauge
109+
# HELP node_netisr_bindthreads netisr threads bound to CPUs
110+
# TYPE node_netisr_bindthreads gauge
111+
node_netisr_bindthreads 0
112+
# HELP node_netisr_defaultqlimit netisr default queue limit
113+
# TYPE node_netisr_defaultqlimit gauge
114+
node_netisr_defaultqlimit 256
115+
# HELP node_netisr_maxprot netisr maximum protocols
116+
# TYPE node_netisr_maxprot gauge
117+
node_netisr_maxprot 16
118+
# HELP node_netisr_maxqlimit netisr maximum queue limit
119+
# TYPE node_netisr_maxqlimit gauge
120+
node_netisr_maxqlimit 10240
121+
# HELP node_netisr_maxthreads netisr maximum thread count
122+
# TYPE node_netisr_maxthreads gauge
123+
node_netisr_maxthreads 1
124+
# HELP node_netisr_numthreads netisr current thread count
125+
# TYPE node_netisr_numthreads gauge
126+
node_netisr_numthreads 1
127+
# HELP node_network_receive_bytes_total Network device statistic receive_bytes.
128+
# TYPE node_network_receive_bytes_total counter
129+
# HELP node_network_receive_drop_total Network device statistic receive_drop.
130+
# TYPE node_network_receive_drop_total counter
131+
# HELP node_network_receive_errs_total Network device statistic receive_errs.
132+
# TYPE node_network_receive_errs_total counter
133+
# HELP node_network_receive_multicast_total Network device statistic receive_multicast.
134+
# TYPE node_network_receive_multicast_total counter
135+
# HELP node_network_receive_packets_total Network device statistic receive_packets.
136+
# TYPE node_network_receive_packets_total counter
137+
# HELP node_network_transmit_bytes_total Network device statistic transmit_bytes.
138+
# TYPE node_network_transmit_bytes_total counter
139+
# HELP node_network_transmit_drop_total Network device statistic transmit_drop.
140+
# TYPE node_network_transmit_drop_total counter
141+
# HELP node_network_transmit_errs_total Network device statistic transmit_errs.
142+
# TYPE node_network_transmit_errs_total counter
143+
# HELP node_network_transmit_multicast_total Network device statistic transmit_multicast.
144+
# TYPE node_network_transmit_multicast_total counter
145+
# HELP node_network_transmit_packets_total Network device statistic transmit_packets.
146+
# TYPE node_network_transmit_packets_total counter
147+
# HELP node_os_info A metric with a constant '1' value labeled by build_id, id, id_like, image_id, image_version, name, pretty_name, variant, variant_id, version, version_codename, version_id.
148+
# TYPE node_os_info gauge
149+
node_os_info{build_id="",id="ubuntu",id_like="debian",image_id="",image_version="",name="Ubuntu",pretty_name="Ubuntu 20.04.2 LTS",variant="",variant_id="",version="20.04.2 LTS (Focal Fossa)",version_codename="focal",version_id="20.04"} 1
150+
# HELP node_os_version Metric containing the major.minor part of the OS version.
151+
# TYPE node_os_version gauge
152+
node_os_version{id="ubuntu",id_like="debian",name="Ubuntu"} 20.04
153+
# HELP node_scrape_collector_duration_seconds node_exporter: Duration of a collector scrape.
154+
# TYPE node_scrape_collector_duration_seconds gauge
155+
# HELP node_scrape_collector_success node_exporter: Whether a collector succeeded.
156+
# TYPE node_scrape_collector_success gauge
157+
node_scrape_collector_success{collector="boottime"} 1
158+
node_scrape_collector_success{collector="cpu"} 1
159+
node_scrape_collector_success{collector="exec"} 1
160+
node_scrape_collector_success{collector="loadavg"} 1
161+
node_scrape_collector_success{collector="meminfo"} 1
162+
node_scrape_collector_success{collector="netdev"} 1
163+
node_scrape_collector_success{collector="netisr"} 1
164+
node_scrape_collector_success{collector="os"} 1
165+
node_scrape_collector_success{collector="textfile"} 1
166+
node_scrape_collector_success{collector="time"} 1
167+
# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
168+
# TYPE node_textfile_scrape_error gauge
169+
node_textfile_scrape_error 0
170+
# HELP node_time_seconds System time in seconds since epoch (1970).
171+
# TYPE node_time_seconds gauge
172+
# HELP node_time_zone_offset_seconds System time zone offset in seconds.
173+
# TYPE node_time_zone_offset_seconds gauge
174+
# HELP promhttp_metric_handler_errors_total Total number of internal errors encountered by the promhttp metric handler.
175+
# TYPE promhttp_metric_handler_errors_total counter
176+
promhttp_metric_handler_errors_total{cause="encoding"} 0
177+
promhttp_metric_handler_errors_total{cause="gathering"} 0
178+
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
179+
# TYPE promhttp_metric_handler_requests_in_flight gauge
180+
promhttp_metric_handler_requests_in_flight 1
181+
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
182+
# TYPE promhttp_metric_handler_requests_total counter
183+
promhttp_metric_handler_requests_total{code="200"} 0
184+
promhttp_metric_handler_requests_total{code="500"} 0
185+
promhttp_metric_handler_requests_total{code="503"} 0

end-to-end-test-freebsd.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/local/bin/bash
2+
3+
set -euf -o pipefail
4+
5+
enabled_collectors=$(cat << COLLECTORS
6+
cpu
7+
meminfo
8+
netdev
9+
textfile
10+
COLLECTORS
11+
)
12+
disabled_collectors=$(cat << COLLECTORS
13+
filesystem
14+
uname
15+
zfs
16+
COLLECTORS
17+
)
18+
cd "$(dirname $0)"
19+
20+
port="$((10000 + (RANDOM % 10000)))"
21+
tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
22+
23+
skip_re="^(go_|node_exporter_build_info|node_boot_time_seconds|node_cpu_seconds_total|node_scrape_collector_duration_seconds|node_network_|node_memory_|node_exec_|node_time_|node_load)"
24+
25+
arch="$(uname -m)"
26+
27+
fixture='collector/fixtures/e2e-output-freebsd.txt';
28+
29+
# Only test CPU info collection on x86_64.
30+
case "${arch}" in
31+
x86_64)
32+
cpu_info_collector='--collector.cpu.info'
33+
cpu_info_bugs='^(cpu_meltdown|spectre_.*|mds)$'
34+
cpu_info_flags='^(aes|avx.?|constant_tsc)$'
35+
;;
36+
*)
37+
cpu_info_collector='--no-collector.cpu.info'
38+
cpu_info_bugs=''
39+
cpu_info_flags=''
40+
;;
41+
esac
42+
43+
keep=0; update=0; verbose=0
44+
while getopts 'hkuv' opt
45+
do
46+
case "$opt" in
47+
k)
48+
keep=1
49+
;;
50+
u)
51+
update=1
52+
;;
53+
v)
54+
verbose=1
55+
set -x
56+
;;
57+
*)
58+
echo "Usage: $0 [-k] [-u] [-v]"
59+
echo " -k: keep temporary files and leave node_exporter running"
60+
echo " -u: update fixture"
61+
echo " -v: verbose output"
62+
exit 1
63+
;;
64+
esac
65+
done
66+
67+
if [ ! -x ./node_exporter ]
68+
then
69+
echo './node_exporter not found. Consider running `go build` first.' >&2
70+
exit 1
71+
fi
72+
73+
./node_exporter \
74+
--path.rootfs="collector/fixtures" \
75+
--path.procfs="collector/fixtures/proc" \
76+
--path.sysfs="collector/fixtures/sys" \
77+
--path.udev.data="collector/fixtures/udev/data" \
78+
$(for c in ${enabled_collectors}; do echo --collector.${c} ; done) \
79+
$(for c in ${disabled_collectors}; do echo --no-collector.${c} ; done) \
80+
--web.listen-address "127.0.0.1:${port}" \
81+
--log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
82+
83+
echo $! > "${tmpdir}/node_exporter.pid"
84+
85+
finish() {
86+
if [ $? -ne 0 -o ${verbose} -ne 0 ]
87+
then
88+
cat << EOF >&2
89+
LOG =====================
90+
$(cat "${tmpdir}/node_exporter.log")
91+
=========================
92+
EOF
93+
fi
94+
95+
if [ ${update} -ne 0 ]
96+
then
97+
cp "${tmpdir}/e2e-output.txt" "${fixture}"
98+
fi
99+
100+
if [ ${keep} -eq 0 ]
101+
then
102+
kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
103+
# This silences the "Killed" message
104+
set +e
105+
wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
106+
rm -rf "${tmpdir}"
107+
fi
108+
}
109+
110+
trap finish EXIT
111+
112+
get() {
113+
if command -v curl > /dev/null 2>&1
114+
then
115+
curl -s -f "$@"
116+
elif command -v wget > /dev/null 2>&1
117+
then
118+
wget -O - "$@"
119+
else
120+
echo "Neither curl nor wget found"
121+
exit 1
122+
fi
123+
}
124+
125+
sleep 1
126+
127+
get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-output.txt"
128+
129+
diff -u \
130+
"${fixture}" \
131+
"${tmpdir}/e2e-output.txt"

0 commit comments

Comments
 (0)