test(rcmgr): regression test prometherus metrics
Marcin Rataj committed
Aug 17, 2022 at 01:27 UTC
77251b60c42e9f4f3b39c40c383cdab27b2ee2c9
3 files changed
+33
docs/config.md
+2
@@ -1719,6 +1719,8 @@ and tracking recource usage over time.
1719
Enables the libp2p Network Resource Manager and auguments the default limits
1720
using user-defined ones in `Swarm.ResourceMgr.Limits` (if present).
1721
1722
+Various `*rcmgr_*` metrics can be accessed as the prometheus endpoint at `{Addresses.API}/debug/metrics/prometheus` (default: `http://127.0.0.1:5001/debug/metrics/prometheus`)
1723
+
1724
Default: `false`
1725
1726
Type: `flag`
test/sharness/t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr
new
+4
@@ -0,0 +1,4 @@
1
+libp2p_rcmgr_memory_allocations_allowed_total
2
+libp2p_rcmgr_memory_allocations_blocked_total
3
+libp2p_rcmgr_peer_blocked_total
4
+libp2p_rcmgr_peers_allowed_total
test/sharness/t0119-prometheus.sh
+27
@@ -26,4 +26,31 @@ test_expect_success "make sure metrics haven't changed" '
26
diff -u ../t0116-prometheus-data/prometheus_metrics filtered_metrics
27
'
28
29
+# Check what was added by enabling ResourceMgr.Enabled
30
+#
31
+# NOTE: we won't see all the dynamic ones, but that is ok: the point of the
32
+# test here is to detect regression when rcmgr metrics dissapear due to
33
+# refactor/human error.
34
+
35
+test_expect_success "enable ResourceMgr in the config" '
36
+ ipfs config --json Swarm.ResourceMgr.Enabled true
37
+'
38
+
39
+test_launch_ipfs_daemon
40
+
41
+test_expect_success "collect metrics" '
42
+ curl "$API_ADDR/debug/metrics/prometheus" > raw_metrics
43
+'
44
+
45
+test_kill_ipfs_daemon
46
+
47
+test_expect_success "filter metrics and find ones added by enabling ResourceMgr" '
48
+ sed -ne "s/^\([a-z0-9_]\+\).*/\1/p" raw_metrics | LC_ALL=C sort > filtered_metrics &&
49
+ grep -v -x -f ../t0116-prometheus-data/prometheus_metrics filtered_metrics > rcmgr_metrics
50
+'
51
+
52
+test_expect_success "make sure initial metrics added by setting ResourceMgr.Enabled haven't changed" '
53
+ diff -u ../t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr rcmgr_metrics
54
+'
55
+
56
test_done