Skip to content

Commit 4e38dcb

Browse files
Merge pull request #2741 from rabbitmq/single-auth-attempts-declarations-on-per-object_2740
Avoid duplicate auth_attempts declarations when per-object metrics enabled (cherry picked from commit 4f43f39)
1 parent 627cb73 commit 4e38dcb

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_core_metrics_collector.erl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@
191191
]},
192192

193193
{auth_attempt_metrics, [
194-
{2, undefined, auth_attempts_total, counter, "Total number of authorization attempts on a node"},
195-
{3, undefined, auth_attempts_succeeded_total, counter, "Total number of successful authentication attempts on a node"},
196-
{4, undefined, auth_attempts_failed_total, counter, "Total number of failed authentication attempts on a node"}
194+
{2, undefined, auth_attempts_total, counter, "Total number of authorization attempts"},
195+
{3, undefined, auth_attempts_succeeded_total, counter, "Total number of successful authentication attempts"},
196+
{4, undefined, auth_attempts_failed_total, counter, "Total number of failed authentication attempts"}
197197
]},
198198

199199
{auth_attempt_detailed_metrics, [
200-
{2, undefined, auth_attempts_total, counter, "Total number of authorization attempts on a node"},
201-
{3, undefined, auth_attempts_succeeded_total, counter, "Total number of successful authorization attempts on a node"},
202-
{4, undefined, auth_attempts_failed_total, counter, "Total number of failed authorization attempts on a node"}
200+
{2, undefined, auth_attempts_detailed_total, counter, "Total number of authorization attempts with source info"},
201+
{3, undefined, auth_attempts_detailed_succeeded_total, counter, "Total number of successful authorization attempts with source info"},
202+
{4, undefined, auth_attempts_detailed_failed_total, counter, "Total number of failed authorization attempts with source info"}
203203
]}
204204

205205
]).
@@ -231,7 +231,7 @@ collect(PerObjectMetrics, Callback) ->
231231
[begin
232232
Data = get_data(Table, PerObjectMetrics),
233233
mf(Callback, Contents, Data)
234-
end || {Table, Contents} <- ?METRICS_RAW, needs_processing(PerObjectMetrics, Table)],
234+
end || {Table, Contents} <- ?METRICS_RAW, include_when_per_object_metrics(PerObjectMetrics, Table)],
235235
[begin
236236
Size = ets:info(Table, size),
237237
mf_totals(Callback, Name, Type, Help, Size)
@@ -240,11 +240,9 @@ collect(PerObjectMetrics, Callback) ->
240240
add_metric_family(identity_info(), Callback),
241241
ok.
242242

243-
needs_processing(false, auth_attempt_detailed_metrics) ->
244-
%% When per object metrics are disabled the detailed authentication attempt metrics
245-
%% create duplicates. Totals are carried on `auth_attempt_metrics`
243+
include_when_per_object_metrics(false, auth_attempt_detailed_metrics) ->
246244
false;
247-
needs_processing(_, _) ->
245+
include_when_per_object_metrics(_, _) ->
248246
true.
249247

250248
build_info() ->

deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ aggregated_metrics_test(Config) ->
217217
?assertEqual(match, re:run(Body, "^rabbitmq_raft_term_total ", [{capture, none}, multiline])),
218218
?assertEqual(match, re:run(Body, "^rabbitmq_queue_messages_ready ", [{capture, none}, multiline])),
219219
?assertEqual(match, re:run(Body, "^rabbitmq_queue_consumers ", [{capture, none}, multiline])),
220+
?assertEqual(match, re:run(Body, "TYPE rabbitmq_auth_attempts_total", [{capture, none}, multiline])),
221+
?assertEqual(nomatch, re:run(Body, "TYPE rabbitmq_auth_attempts_detailed_total", [{capture, none}, multiline])),
220222
%% Check the first metric value in each ETS table that requires converting
221223
?assertEqual(match, re:run(Body, "^rabbitmq_erlang_uptime_seconds ", [{capture, none}, multiline])),
222224
?assertEqual(match, re:run(Body, "^rabbitmq_io_read_time_seconds_total ", [{capture, none}, multiline])),
@@ -251,6 +253,8 @@ per_object_metrics_test(Config, Path) ->
251253
?assertEqual(match, re:run(Body, "^rabbitmq_raft_term_total{", [{capture, none}, multiline])),
252254
?assertEqual(match, re:run(Body, "^rabbitmq_queue_messages_ready{", [{capture, none}, multiline])),
253255
?assertEqual(match, re:run(Body, "^rabbitmq_queue_consumers{", [{capture, none}, multiline])),
256+
?assertEqual(match, re:run(Body, "TYPE rabbitmq_auth_attempts_total", [{capture, none}, multiline])),
257+
?assertEqual(match, re:run(Body, "TYPE rabbitmq_auth_attempts_detailed_total", [{capture, none}, multiline])),
254258
%% Check the first metric value in each ETS table that requires converting
255259
?assertEqual(match, re:run(Body, "^rabbitmq_erlang_uptime_seconds ", [{capture, none}, multiline])),
256260
?assertEqual(match, re:run(Body, "^rabbitmq_io_read_time_seconds_total ", [{capture, none}, multiline])),

0 commit comments

Comments
 (0)