test(rcmgr): regression test prometherus metrics

This commit is contained in:
Marcin Rataj 2022-08-17 01:27:50 +02:00
parent a42848ac62
commit 77251b60c4
No known key found for this signature in database
GPG Key ID: 222B6784D5A79E42
3 changed files with 33 additions and 0 deletions

View File

@ -1719,6 +1719,8 @@ and tracking recource usage over time.
Enables the libp2p Network Resource Manager and auguments the default limits
using user-defined ones in `Swarm.ResourceMgr.Limits` (if present).
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`)
Default: `false`
Type: `flag`

View File

@ -0,0 +1,4 @@
libp2p_rcmgr_memory_allocations_allowed_total
libp2p_rcmgr_memory_allocations_blocked_total
libp2p_rcmgr_peer_blocked_total
libp2p_rcmgr_peers_allowed_total

View File

@ -26,4 +26,31 @@ test_expect_success "make sure metrics haven't changed" '
diff -u ../t0116-prometheus-data/prometheus_metrics filtered_metrics
'
# Check what was added by enabling ResourceMgr.Enabled
#
# NOTE: we won't see all the dynamic ones, but that is ok: the point of the
# test here is to detect regression when rcmgr metrics dissapear due to
# refactor/human error.
test_expect_success "enable ResourceMgr in the config" '
ipfs config --json Swarm.ResourceMgr.Enabled true
'
test_launch_ipfs_daemon
test_expect_success "collect metrics" '
curl "$API_ADDR/debug/metrics/prometheus" > raw_metrics
'
test_kill_ipfs_daemon
test_expect_success "filter metrics and find ones added by enabling ResourceMgr" '
sed -ne "s/^\([a-z0-9_]\+\).*/\1/p" raw_metrics | LC_ALL=C sort > filtered_metrics &&
grep -v -x -f ../t0116-prometheus-data/prometheus_metrics filtered_metrics > rcmgr_metrics
'
test_expect_success "make sure initial metrics added by setting ResourceMgr.Enabled haven't changed" '
diff -u ../t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr rcmgr_metrics
'
test_done