diff options
author | Gerhard Lazu <gerhard@lazu.co.uk> | 2021-01-22 11:33:20 +0000 |
---|---|---|
committer | Gerhard Lazu <gerhard@lazu.co.uk> | 2021-01-22 11:36:42 +0000 |
commit | 5a6e3f235b880f753a017515014bac6e993f87a4 (patch) | |
tree | c389a96ab7584017f6de31422ef8d24784f8dcdf | |
parent | 52479099ecc9807097ad0af70b6c5d54cb5031e7 (diff) | |
download | rabbitmq-server-git-5a6e3f235b880f753a017515014bac6e993f87a4.tar.gz |
Single auth_attempts declarations when per-object metrics enabled
Closes #2740
Signed-off-by: Gerhard Lazu <gerhard@lazu.co.uk>
-rw-r--r-- | deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl | 10 | ||||
-rw-r--r-- | deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl b/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl index cd2baad964..9c155bb030 100644 --- a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl +++ b/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl @@ -231,7 +231,7 @@ collect(PerObjectMetrics, Callback) -> [begin Data = get_data(Table, PerObjectMetrics), mf(Callback, Contents, Data) - end || {Table, Contents} <- ?METRICS_RAW, needs_processing(PerObjectMetrics, Table)], + end || {Table, Contents} <- ?METRICS_RAW, include_when_per_object_metrics(PerObjectMetrics, Table)], [begin Size = ets:info(Table, size), mf_totals(Callback, Name, Type, Help, Size) @@ -240,11 +240,11 @@ collect(PerObjectMetrics, Callback) -> add_metric_family(identity_info(), Callback), ok. -needs_processing(false, auth_attempt_detailed_metrics) -> - %% When per object metrics are disabled the detailed authentication attempt metrics - %% create duplicates. Totals are carried on `auth_attempt_metrics` +include_when_per_object_metrics(true, auth_attempt_metrics) -> false; -needs_processing(_, _) -> +include_when_per_object_metrics(false, auth_attempt_detailed_metrics) -> + false; +include_when_per_object_metrics(_, _) -> true. build_info() -> diff --git a/deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl b/deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl index fc66306f59..06ddc9fc94 100644 --- a/deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl +++ b/deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl @@ -36,7 +36,8 @@ groups() -> ]}, {per_object_metrics, [], [ globally_configure_per_object_metrics_test, - specific_erlang_metrics_present_test + specific_erlang_metrics_present_test, + single_auth_attempts_type_test ]}, {per_object_endpoint_metrics, [], [ endpoint_per_object_metrics, @@ -258,6 +259,12 @@ per_object_metrics_test(Config, Path) -> %% Check the first TOTALS metric value ?assertEqual(match, re:run(Body, "^rabbitmq_connections ", [{capture, none}, multiline])). +single_auth_attempts_type_test(Config) -> + {_Headers, Body} = http_get_with_pal(Config, [], 200), + TypeDefinition = "TYPE rabbitmq_auth_attempts_total", + {match, Matches} = re:run(Body, TypeDefinition, [{capture, all, binary}, global]), + ?assertEqual(1, length(Matches), "Expecting a single occurence of " ++ TypeDefinition). + build_info_test(Config) -> {_Headers, Body} = http_get_with_pal(Config, [], 200), ?assertEqual(match, re:run(Body, "^rabbitmq_build_info{", [{capture, none}, multiline])), |