| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2020 Protocol Labs |
| 4 | # MIT/Apache-2.0 Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test prometheus metrics are exposed correctly" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | test_init_ipfs |
| 12 | |
| 13 | test_expect_success "enable ResourceMgr in the config" ' |
| 14 | ipfs config --json Swarm.ResourceMgr.Enabled false |
| 15 | ' |
| 16 | |
| 17 | test_launch_ipfs_daemon |
| 18 | |
| 19 | test_expect_success "collect metrics" ' |
| 20 | curl "$API_ADDR/debug/metrics/prometheus" > raw_metrics |
| 21 | ' |
| 22 | |
| 23 | test_kill_ipfs_daemon |
| 24 | |
| 25 | test_expect_success "filter metrics" ' |
| 26 | sed -ne "s/^\([a-z0-9_]\+\).*/\1/p" raw_metrics | LC_ALL=C sort | uniq > filtered_metrics |
| 27 | ' |
| 28 | |
| 29 | test_expect_success "make sure metrics haven't changed" ' |
| 30 | diff -u ../t0119-prometheus-data/prometheus_metrics filtered_metrics |
| 31 | ' |
| 32 | |
| 33 | # Check what was added by enabling ResourceMgr.Enabled |
| 34 | # |
| 35 | # NOTE: we won't see all the dynamic ones, but that is ok: the point of the |
| 36 | # test here is to detect regression when rcmgr metrics disappear due to |
| 37 | # refactor/human error. |
| 38 | |
| 39 | test_expect_success "enable ResourceMgr in the config" ' |
| 40 | ipfs config --json Swarm.ResourceMgr.Enabled true |
| 41 | ' |
| 42 | |
| 43 | test_launch_ipfs_daemon |
| 44 | |
| 45 | test_expect_success "collect metrics" ' |
| 46 | curl "$API_ADDR/debug/metrics/prometheus" > raw_metrics |
| 47 | ' |
| 48 | |
| 49 | test_kill_ipfs_daemon |
| 50 | |
| 51 | test_expect_success "filter metrics and find ones added by enabling ResourceMgr" ' |
| 52 | sed -ne "s/^\([a-z0-9_]\+\).*/\1/p" raw_metrics | LC_ALL=C sort > filtered_metrics && |
| 53 | grep -v -x -f ../t0119-prometheus-data/prometheus_metrics filtered_metrics | LC_ALL=C sort | uniq > rcmgr_metrics |
| 54 | ' |
| 55 | |
| 56 | test_expect_success "make sure initial metrics added by setting ResourceMgr.Enabled haven't changed" ' |
| 57 | diff -u ../t0119-prometheus-data/prometheus_metrics_added_by_enabling_rcmgr rcmgr_metrics |
| 58 | ' |
| 59 | |
| 60 | # Reinitialize ipfs with --profile=flatfs-measure and check metrics. |
| 61 | |
| 62 | test_expect_success "remove ipfs directory" ' |
| 63 | rm -rf .ipfs mountdir ipfs ipns |
| 64 | ' |
| 65 | |
| 66 | test_init_ipfs_measure |
| 67 | |
| 68 | test_launch_ipfs_daemon |
| 69 | |
| 70 | test_expect_success "collect metrics" ' |
| 71 | curl "$API_ADDR/debug/metrics/prometheus" > raw_metrics |
| 72 | ' |
| 73 | test_kill_ipfs_daemon |
| 74 | |
| 75 | test_expect_success "filter metrics and find ones added by enabling flatfs-measure profile" ' |
| 76 | sed -ne "s/^\([a-z0-9_]\+\).*/\1/p" raw_metrics | LC_ALL=C sort > filtered_metrics && |
| 77 | grep -v -x -f ../t0119-prometheus-data/prometheus_metrics filtered_metrics | LC_ALL=C sort | uniq > measure_metrics |
| 78 | ' |
| 79 | |
| 80 | test_expect_success "make sure initial metrics added by initializing with flatfs-measure profile haven't changed" ' |
| 81 | diff -u ../t0119-prometheus-data/prometheus_metrics_added_by_measure_profile measure_metrics |
| 82 | ' |
| 83 | |
| 84 | test_done |