diff options
author | Will Holley <willholley@apache.org> | 2023-03-10 09:10:40 +0000 |
---|---|---|
committer | Will Holley <willholley@gmail.com> | 2023-03-13 18:44:31 +0000 |
commit | 138163147dc735b0a0015c5dd90adc9c415112a4 (patch) | |
tree | 5fe22baf9baf8d90261606d700e0ee85d28dfaa2 | |
parent | dff01446cbb17001f419f39b7a7293a30ddfdeaa (diff) | |
download | couchdb-138163147dc735b0a0015c5dd90adc9c415112a4.tar.gz |
fix: remove duplicate couchdb_erlang* from _prometheus
The `_node/_local/_prometheus` was returning duplicate rows for the
following metrics:
```
couchdb_erlang_memory_bytes
couchdb_erlang_gc_collections_total
couchdb_erlang_gc_words_reclaimed_total
couchdb_erlang_context_switches_total
couchdb_erlang_reductions_total
couchdb_erlang_processes
couchdb_erlang_process_limit
```
Prometheus will gracefully handle the duplication, picking the first
entry only, but it bloats the response and can potentially cause
unexpected results if there's a signficant delay capturing the
samples.
The duplication is caused by a duplicate function call to
`get_vm_stats()` in the prometheus endpoint handler. Removing the
duplicate call fixes the problem.
-rw-r--r-- | src/couch_prometheus/src/couch_prometheus_server.erl | 1 | ||||
-rw-r--r-- | src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl | 18 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/couch_prometheus/src/couch_prometheus_server.erl b/src/couch_prometheus/src/couch_prometheus_server.erl index 7a0eb4bf9..7597c7e28 100644 --- a/src/couch_prometheus/src/couch_prometheus_server.erl +++ b/src/couch_prometheus/src/couch_prometheus_server.erl @@ -108,7 +108,6 @@ get_couchdb_stats() -> get_system_stats() -> lists:flatten([ get_uptime_stat(), - get_vm_stats(), get_io_stats(), get_message_queue_stats(), get_run_queue_stats(), diff --git a/src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl b/src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl index 5f458ba8c..9b1c47633 100644 --- a/src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl +++ b/src/couch_prometheus/test/eunit/couch_prometheus_e2e_tests.erl @@ -39,7 +39,8 @@ e2e_test_() -> [ ?TDEF_FE(t_chttpd_port), ?TDEF_FE(t_prometheus_port), - ?TDEF_FE(t_metric_updated) + ?TDEF_FE(t_metric_updated), + ?TDEF_FE(t_no_duplicate_metrics) ] } } @@ -105,6 +106,21 @@ t_reject_prometheus_port(Port) -> Response = test_request:get(node_local_url(Port), [?CONTENT_JSON, ?AUTH]), ?assertEqual({error, {conn_failed, {error, econnrefused}}}, Response). +t_no_duplicate_metrics(Port) -> + Url = node_local_url(Port), + Stats = get_stats(Url), + Lines = re:split(Stats, "\n"), + % Filter the result to only the lines containing the metric + % definition, not the values. These lines always start with + % a # character. + MetricDefs = lists:filter(fun(S) -> string:find(S, "#") =:= S end, Lines), + ?assertNotEqual(erlang:length(MetricDefs), 0), + Diff = get_duplicates(MetricDefs), + ?assertEqual(erlang:length(Diff), 0). + +get_duplicates(List) -> + List -- sets:to_list(sets:from_list(List)). + t_metric_updated(Port) -> % The passage of time should increment this metric Metric = "couchdb_uptime_seconds", |