Skip to content

Commit

Permalink
fix: test queue filter & add missing ex_qu test
Browse files Browse the repository at this point in the history
Fixes the queue filtering broken mechanism for the functions added by
this branch and adds the missing queue_exchange_metrics test
  • Loading branch information
LoisSotoLopez committed May 24, 2024
1 parent a9ae940 commit db343da
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
11 changes: 8 additions & 3 deletions deps/rabbit_common/include/rabbit_core_metrics.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
{channel_exchange_metrics, set},
{channel_process_metrics, set},
{consumer_created, set},
{exchange_metrics, set},
{queue_metrics, set},
{queue_counter_metrics, set},
{queue_coarse_metrics, set},
{queue_exchange_metrics, set},
{node_persister_metrics, set},
{node_coarse_metrics, set},
{node_metrics, set},
Expand All @@ -31,6 +28,14 @@
{auth_attempt_metrics, set},
{auth_attempt_detailed_metrics, set}]).

% `CORE_NON_CHANNEL_TABLES` are tables that store counters representing the
% same info as some of the channel_queue_metrics, channel_exchange_metrics and
% channel_queue_exchange_metrics but without including the channel ID in the
% key.
-define(CORE_NON_CHANNEL_TABLES, [{queue_counter_metrics, set},
{exchange_metrics, set},
{queue_exchange_metrics, set}]).

-define(CONNECTION_CHURN_METRICS, {node(), 0, 0, 0, 0, 0, 0, 0}).

%% connection_created :: {connection_id, proplist}
Expand Down
8 changes: 5 additions & 3 deletions deps/rabbit_common/src/rabbit_core_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ create_table({Table, Type}) ->
{read_concurrency, true}]).

init() ->
_ = [create_table({Table, Type})
|| {Table, Type} <- ?CORE_TABLES ++ ?CORE_EXTRA_TABLES],
Tables = ?CORE_TABLES ++ ?CORE_EXTRA_TABLES ++ ?CORE_NON_CHANNEL_TABLES,
_ = [create_table({Table, Type})
|| {Table, Type} <- Tables],
ok.

terminate() ->
Tables = ?CORE_TABLES ++ ?CORE_EXTRA_TABLES ++ ?CORE_NON_CHANNEL_TABLES,
[ets:delete(Table)
|| {Table, _Type} <- ?CORE_TABLES ++ ?CORE_EXTRA_TABLES],
|| {Table, _Type} <- Tables],
ok.

connection_created(Pid, Infos) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ get_data(Table, false, VHostsFilter, QueuesFilter) when Table == channel_exchang
{T, V1 + A1, V2 + A2, V3 + A3, V4 + A4}
end;
({#resource{kind = queue, name = Name}, V1, V2, V3, V4, V5, V6, V7, _}, {T, A1, A2, A3, A4, A5, A6, A7} = Acc)
when is_list(QueuesFilter) ->
when QueuesFilter /= false ->
case re:run(Name, QueuesFilter, [{capture, none}]) of
match ->
Acc;
Expand Down Expand Up @@ -653,8 +653,11 @@ get_data(queue_counter_metrics = Table, true, VHostsFilter, QueuesFilter) ->
({#resource{kind = queue, virtual_host = VHost, name = QueueName}, _, _, _, _, _, _, _, _} = Row, Acc) when
map_get(VHost, VHostsFilter)
->
IgnoreQueue = is_list(QueuesFilter)
andalso re:run(QueueName, QueuesFilter, [{capture, none}]),
IgnoreQueue =
(QueuesFilter /= false)
andalso (
re:run(QueueName, QueuesFilter, [{capture, none}]) == match
),
case IgnoreQueue of
true ->
Acc;
Expand All @@ -672,8 +675,11 @@ get_data(queue_exchange_metrics = Table, true, VHostsFilter, QueuesFilter) ->
}, _, _} = Row, Acc) when
map_get(VHost, VHostsFilter)
->
IgnoreQueue = is_list(QueuesFilter)
andalso re:run(QueueName, QueuesFilter, [{capture, none}]),
IgnoreQueue =
(QueuesFilter /= false)
andalso (
re:run(QueueName, QueuesFilter, [{capture, none}]) == match
),
case IgnoreQueue of
true ->
Acc;
Expand Down
71 changes: 71 additions & 0 deletions deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ groups() ->
queue_consumer_count_all_vhosts_per_object_test,
queue_coarse_metrics_per_object_test,
queue_counter_metrics_per_object_test,
queue_exchange_metrics_per_object_test,
queue_metrics_per_object_test,
queue_consumer_count_and_queue_metrics_mutually_exclusive_test,
vhost_status_metric,
Expand Down Expand Up @@ -552,10 +553,80 @@ queue_counter_metrics_per_object_test(Config) ->
map_get(
rabbitmq_detailed_queue_messages_delivered_ack_total,
parse_response(Body2))),

rabbit_ct_broker_helpers:rpc(
Config, 0, application, set_env, [rabbitmq_prometheus, filter_aggregated_queue_metrics_pattern, ".*"]),

{_, Body3} = http_get_with_pal(Config,
"/metrics/detailed?vhost=vhost-2&family=queue_counter_metrics",
[], 200),

Expected3 = undefined,

?assertEqual(
Expected3,
maps:get(
rabbitmq_detailed_queue_messages_delivered_ack_total,
parse_response(Body3),
undefined)),

rabbit_ct_broker_helpers:rpc(
Config, 0, application, set_env, [rabbitmq_prometheus, filter_aggregated_queue_metrics_pattern, undefined]),

%% Maybe missing, tests for the queue_exchange_metrics
ok.


queue_exchange_metrics_per_object_test(Config) ->
Expected1 = #{
#{
queue => "vhost-1-queue-with-messages",
vhost => "vhost-1",
exchange => ""
} => [7],
#{
exchange => "",
queue => "vhost-1-queue-with-consumer",
vhost => "vhost-1"
} => [7]
},

{_, Body1} = http_get_with_pal(Config,
"/metrics/detailed?vhost=vhost-1&family=queue_exchange_metrics",
[], 200),
?assertEqual(
Expected1,
map_get(
rabbitmq_detailed_queue_exchange_messages_published_total,
parse_response(Body1))),


{_, Body2} = http_get_with_pal(Config,
"/metrics/detailed?vhost=vhost-2&family=queue_exchange_metrics",
[], 200),


Expected2 = #{
#{
queue => "vhost-2-queue-with-messages",
vhost => "vhost-2",
exchange => ""
} => [11],
#{
exchange => "",
queue => "vhost-2-queue-with-consumer",
vhost => "vhost-2"
} => [11]
},

?assertEqual(
Expected2,
map_get(
rabbitmq_detailed_queue_exchange_messages_published_total,
parse_response(Body2))),

ok.

exchange_metrics_per_object_test(Config) ->
Expected1 = #{#{queue => "vhost-1-queue-with-consumer", vhost => "vhost-1"} => [7]},

Expand Down

0 comments on commit db343da

Please sign in to comment.