From 77251b60c42e9f4f3b39c40c383cdab27b2ee2c9 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 17 Aug 2022 01:27:50 +0200 Subject: [PATCH] test(rcmgr): regression test prometherus metrics --- docs/config.md | 2 ++ ...prometheus_metrics_added_by_enabling_rcmgr | 4 +++ test/sharness/t0119-prometheus.sh | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/sharness/t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr diff --git a/docs/config.md b/docs/config.md index 386ab584a..404debd1c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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` diff --git a/test/sharness/t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr b/test/sharness/t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr new file mode 100644 index 000000000..382ab1256 --- /dev/null +++ b/test/sharness/t0116-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr @@ -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 diff --git a/test/sharness/t0119-prometheus.sh b/test/sharness/t0119-prometheus.sh index 0412179fe..cd7346735 100755 --- a/test/sharness/t0119-prometheus.sh +++ b/test/sharness/t0119-prometheus.sh @@ -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