Skip to content

Commit 32dde12

Browse files
committed
Display container-id in the UI and CLI
1 parent 35fb30f commit 32dde12

File tree

10 files changed

+66
-53
lines changed

10 files changed

+66
-53
lines changed

deps/rabbit/include/rabbit_amqp.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
[pid,
3838
frame_max,
3939
timeout,
40+
container_id,
4041
vhost,
4142
user,
4243
node

deps/rabbit/src/rabbit_amqp_reader.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
-record(v1_connection,
3737
{name :: binary(),
38+
container_id :: binary(),
3839
vhost :: none | rabbit_types:vhost(),
3940
%% server host
4041
host :: inet:ip_address() | inet:hostname(),
@@ -491,6 +492,7 @@ handle_connection_frame(
491492
end,
492493
State1 = State0#v1{connection_state = running,
493494
connection = Connection#v1_connection{
495+
container_id = ContainerId,
494496
vhost = Vhost,
495497
incoming_max_frame_size = IncomingMaxFrameSize,
496498
outgoing_max_frame_size = OutgoingMaxFrameSize,
@@ -969,6 +971,8 @@ i(connected_at, #v1{connection = #v1_connection{connected_at = Val}}) ->
969971
Val;
970972
i(name, #v1{connection = #v1_connection{name = Val}}) ->
971973
Val;
974+
i(container_id, #v1{connection = #v1_connection{container_id = Val}}) ->
975+
Val;
972976
i(vhost, #v1{connection = #v1_connection{vhost = Val}}) ->
973977
Val;
974978
i(host, #v1{connection = #v1_connection{host = Val}}) ->

deps/rabbit/src/rabbit_networking.erl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
node_listeners/1, node_client_listeners/1,
2626
register_connection/1, unregister_connection/1,
2727
register_non_amqp_connection/1, unregister_non_amqp_connection/1,
28-
connections/0, non_amqp_connections/0, connection_info_keys/0,
29-
connection_info/1, connection_info/2,
30-
connection_info_all/0, connection_info_all/1,
28+
connections/0, non_amqp_connections/0,
29+
connection_info/2,
30+
connection_info_all/1,
3131
emit_connection_info_all/4, emit_connection_info_local/3,
3232
close_connection/2, close_connections/2, close_all_connections/1,
3333
close_all_user_connections/2,
@@ -482,23 +482,11 @@ non_amqp_connections() ->
482482
local_non_amqp_connections() ->
483483
pg_local:get_members(rabbit_non_amqp_connections).
484484

485-
-spec connection_info_keys() -> rabbit_types:info_keys().
486-
487-
connection_info_keys() -> rabbit_reader:info_keys().
488-
489-
-spec connection_info(rabbit_types:connection()) -> rabbit_types:infos().
490-
491-
connection_info(Pid) -> rabbit_reader:info(Pid).
492-
493485
-spec connection_info(rabbit_types:connection(), rabbit_types:info_keys()) ->
494486
rabbit_types:infos().
495487

496488
connection_info(Pid, Items) -> rabbit_reader:info(Pid, Items).
497489

498-
-spec connection_info_all() -> [rabbit_types:infos()].
499-
500-
connection_info_all() -> cmap(fun (Q) -> connection_info(Q) end).
501-
502490
-spec connection_info_all(rabbit_types:info_keys()) ->
503491
[rabbit_types:infos()].
504492

deps/rabbit/src/rabbit_reader.erl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
-include_lib("rabbit_common/include/rabbit_framing.hrl").
4444
-include_lib("rabbit_common/include/rabbit.hrl").
4545

46-
-export([start_link/2, info_keys/0, info/1, info/2, force_event_refresh/2,
46+
-export([start_link/2, info/2, force_event_refresh/2,
4747
shutdown/2]).
4848

4949
-export([system_continue/3, system_terminate/4, system_code_change/4]).
@@ -116,10 +116,6 @@
116116
connection_blocked_message_sent
117117
}).
118118

119-
-define(STATISTICS_KEYS, [pid, recv_oct, recv_cnt, send_oct, send_cnt,
120-
send_pend, state, channels, reductions,
121-
garbage_collection]).
122-
123119
-define(SIMPLE_METRICS, [pid, recv_oct, send_oct, reductions]).
124120
-define(OTHER_METRICS, [recv_cnt, send_cnt, send_pend, state, channels,
125121
garbage_collection]).
@@ -132,8 +128,6 @@
132128
timeout, frame_max, channel_max, client_properties, connected_at,
133129
node, user_who_performed_action]).
134130

135-
-define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]).
136-
137131
-define(AUTH_NOTIFICATION_INFO_KEYS,
138132
[host, name, peer_host, peer_port, protocol, auth_mechanism,
139133
ssl, ssl_protocol, ssl_cipher, peer_cert_issuer, peer_cert_subject,
@@ -188,15 +182,6 @@ system_terminate(Reason, _Parent, _Deb, _State) ->
188182
system_code_change(Misc, _Module, _OldVsn, _Extra) ->
189183
{ok, Misc}.
190184

191-
-spec info_keys() -> rabbit_types:info_keys().
192-
193-
info_keys() -> ?INFO_KEYS.
194-
195-
-spec info(pid()) -> rabbit_types:infos().
196-
197-
info(Pid) ->
198-
gen_server:call(Pid, info, infinity).
199-
200185
-spec info(pid(), rabbit_types:info_keys()) -> rabbit_types:infos().
201186

202187
info(Pid, Items) ->
@@ -633,9 +618,6 @@ handle_other({'$gen_call', From, {shutdown, Explanation}}, State) ->
633618
force -> stop;
634619
normal -> NewState
635620
end;
636-
handle_other({'$gen_call', From, info}, State) ->
637-
gen_server:reply(From, infos(?INFO_KEYS, State)),
638-
State;
639621
handle_other({'$gen_call', From, {info, Items}}, State) ->
640622
gen_server:reply(From, try {ok, infos(Items, State)}
641623
catch Error -> {error, Error}
@@ -1627,6 +1609,7 @@ ic(client_properties, #connection{client_properties = CP}) -> CP;
16271609
ic(auth_mechanism, #connection{auth_mechanism = none}) -> none;
16281610
ic(auth_mechanism, #connection{auth_mechanism = {Name, _Mod}}) -> Name;
16291611
ic(connected_at, #connection{connected_at = T}) -> T;
1612+
ic(container_id, _) -> ''; % AMQP 1.0 specific field
16301613
ic(Item, #connection{}) -> throw({bad_argument, Item}).
16311614

16321615
socket_info(Get, Select, #v1{sock = Sock}) ->

deps/rabbit/test/amqp_client_SUITE.erl

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,18 +1662,19 @@ events(Config) ->
16621662

16631663
Protocol = {protocol, {1, 0}},
16641664
AuthProps = [{name, <<"guest">>},
1665-
{auth_mechanism, <<"PLAIN">>},
1666-
{ssl, false},
1667-
Protocol],
1665+
{auth_mechanism, <<"PLAIN">>},
1666+
{ssl, false},
1667+
Protocol],
16681668
?assertMatch(
1669-
{value, _},
1670-
find_event(user_authentication_success, AuthProps, Events)),
1669+
{value, _},
1670+
find_event(user_authentication_success, AuthProps, Events)),
16711671

16721672
Node = get_node_config(Config, 0, nodename),
16731673
ConnectionCreatedProps = [Protocol,
16741674
{node, Node},
16751675
{vhost, <<"/">>},
16761676
{user, <<"guest">>},
1677+
{container_id, <<"my container">>},
16771678
{type, network}],
16781679
{value, ConnectionCreatedEvent} = find_event(
16791680
connection_created,
@@ -1694,8 +1695,8 @@ events(Config) ->
16941695
Pid,
16951696
ClientProperties],
16961697
?assertMatch(
1697-
{value, _},
1698-
find_event(connection_closed, ConnectionClosedProps, Events)),
1698+
{value, _},
1699+
find_event(connection_closed, ConnectionClosedProps, Events)),
16991700
ok.
17001701

17011702
sync_get_unsettled_classic_queue(Config) ->
@@ -3696,17 +3697,21 @@ list_connections(Config) ->
36963697
[ok = rabbit_ct_client_helpers:close_channels_and_connection(Config, Node) || Node <- [0, 1, 2]],
36973698

36983699
Connection091 = rabbit_ct_client_helpers:open_unmanaged_connection(Config, 0),
3699-
{ok, C0} = amqp10_client:open_connection(connection_config(0, Config)),
3700-
{ok, C2} = amqp10_client:open_connection(connection_config(2, Config)),
3700+
ContainerId0 = <<"ID 0">>,
3701+
ContainerId2 = <<"ID 2">>,
3702+
Cfg0 = maps:put(container_id, ContainerId0, connection_config(0, Config)),
3703+
Cfg2 = maps:put(container_id, ContainerId2, connection_config(2, Config)),
3704+
{ok, C0} = amqp10_client:open_connection(Cfg0),
3705+
{ok, C2} = amqp10_client:open_connection(Cfg2),
37013706
receive {amqp10_event, {connection, C0, opened}} -> ok
37023707
after 5000 -> ct:fail({missing_event, ?LINE})
37033708
end,
37043709
receive {amqp10_event, {connection, C2, opened}} -> ok
37053710
after 5000 -> ct:fail({missing_event, ?LINE})
37063711
end,
37073712

3708-
{ok, StdOut} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, ["list_connections", "--silent", "protocol"]),
3709-
Protocols0 = re:split(StdOut, <<"\n">>, [trim]),
3713+
{ok, StdOut0} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, ["list_connections", "--silent", "protocol"]),
3714+
Protocols0 = re:split(StdOut0, <<"\n">>, [trim]),
37103715
%% Remove any whitespaces.
37113716
Protocols1 = [binary:replace(Subject, <<" ">>, <<>>, [global]) || Subject <- Protocols0],
37123717
Protocols = lists:sort(Protocols1),
@@ -3715,6 +3720,13 @@ list_connections(Config) ->
37153720
<<"{1,0}">>],
37163721
Protocols),
37173722

3723+
%% CLI should list AMQP 1.0 container-id
3724+
{ok, StdOut1} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, ["list_connections", "--silent", "container_id"]),
3725+
ContainerIds0 = re:split(StdOut1, <<"\n">>, [trim]),
3726+
ContainerIds = lists:sort(ContainerIds0),
3727+
?assertEqual([<<>>, ContainerId0, ContainerId2],
3728+
ContainerIds),
3729+
37183730
ok = rabbit_ct_client_helpers:close_connection(Connection091),
37193731
ok = close_connection_sync(C0),
37203732
ok = close_connection_sync(C2).
@@ -6021,8 +6033,8 @@ find_event(Type, Props, Events) when is_list(Props), is_list(Events) ->
60216033
fun(#event{type = EventType, props = EventProps}) ->
60226034
Type =:= EventType andalso
60236035
lists:all(
6024-
fun({Key, _Value}) ->
6025-
lists:keymember(Key, 1, EventProps)
6036+
fun(Prop) ->
6037+
lists:member(Prop, EventProps)
60266038
end, Props)
60276039
end, Events).
60286040

deps/rabbit/test/disconnect_detected_during_alarm_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ disconnect_detected_during_alarm(Config) ->
9696

9797
ListConnections =
9898
fun() ->
99-
rpc:call(A, rabbit_networking, connection_info_all, [])
99+
rpc:call(A, rabbit_networking, connection_info_all, [[state]])
100100
end,
101101

102102
%% We've already disconnected, but blocked connection still should still linger on.

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_connections_command.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListConnectionsCommand do
1717
@info_keys ~w(pid name port host peer_port peer_host ssl ssl_protocol
1818
ssl_key_exchange ssl_cipher ssl_hash peer_cert_subject
1919
peer_cert_issuer peer_cert_validity state
20-
channels protocol auth_mechanism user vhost timeout frame_max
20+
channels protocol auth_mechanism user vhost container_id timeout frame_max
2121
channel_max client_properties recv_oct recv_cnt send_oct
2222
send_cnt send_pend connected_at)a
2323

@@ -79,7 +79,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListConnectionsCommand do
7979

8080
def help_section(), do: :observability_and_health_checks
8181

82-
def description(), do: "Lists AMQP 0.9.1 connections for the node"
82+
def description(), do: "Lists AMQP connections for the node"
8383

8484
def banner(_, _), do: "Listing connections ..."
8585
end

deps/rabbitmq_management/priv/www/js/global.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ var ALL_COLUMNS =
108108
['rate-redeliver', 'redelivered', false],
109109
['rate-ack', 'ack', true]]},
110110
'connections':
111-
{'Overview': [['user', 'User name', true],
111+
{'Overview': [['container_id', 'Container ID', true],
112+
['user', 'User name', true],
112113
['state', 'State', true]],
113114
'Details': [['ssl', 'TLS', true],
114115
['ssl_info', 'TLS details', false],
@@ -585,7 +586,10 @@ var HELP = {
585586
<dd>Rate at which queues are created. Declaring a queue that already exists counts for a "Declared" event, but not for a "Created" event. </dd>\
586587
<dt>Deleted</dt>\
587588
<dd>Rate at which queues are deleted.</dd>\
588-
</dl> '
589+
</dl> ',
590+
591+
'container-id':
592+
'Name of the client application as sent from client to RabbitMQ in field container-id of the AMQP 1.0 <a target="_blank" href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-open">open</a> frame.'
589593

590594
};
591595

deps/rabbitmq_management/priv/www/js/tmpl/connection.ejs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
</tr>
2323
<% } %>
2424
25+
<% if (connection.container_id) { %>
26+
<tr>
27+
<th>Container ID
28+
<span class="help" id="container-id"></span>
29+
</th>
30+
<td><%= fmt_string(connection.container_id) %></td>
31+
</tr>
32+
<% } %>
33+
2534
<tr>
2635
<th>Username</th>
2736
<td><%= fmt_string(connection.user) %></td>

deps/rabbitmq_management/priv/www/js/tmpl/connections.ejs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<% if (nodes_interesting) { %>
2727
<th><%= fmt_sort('Node', 'node') %></th>
2828
<% } %>
29+
<% if (show_column('connections', 'container_id')) { %>
30+
<th>Container ID <span class="help" id="container-id"></span></th>
31+
<% } %>
2932
<% if (show_column('connections', 'user')) { %>
3033
<th><%= fmt_sort('User name', 'user') %></th>
3134
<% } %>
@@ -84,14 +87,23 @@
8487
<% if(connection.client_properties) { %>
8588
<td>
8689
<%= link_conn(connection.name) %>
87-
<sub><%= fmt_string(short_conn(connection.client_properties.connection_name)) %></sub>
90+
<% if (connection.client_properties.connection_name) { %>
91+
<sub><%= fmt_string(short_conn(connection.client_properties.connection_name)) %></sub>
92+
<% } %>
8893
</td>
8994
<% } else { %>
9095
<td><%= link_conn(connection.name) %></td>
9196
<% } %>
9297
<% if (nodes_interesting) { %>
9398
<td><%= fmt_node(connection.node) %></td>
9499
<% } %>
100+
<% if (show_column('connections', 'container_id')) { %>
101+
<td class="c">
102+
<% if (connection.container_id) { %>
103+
<%= fmt_string(connection.container_id) %>
104+
<% } %>
105+
</td>
106+
<% } %>
95107
<% if (show_column('connections', 'user')) { %>
96108
<td class="c"><%= fmt_string(connection.user) %></td>
97109
<% } %>

0 commit comments

Comments
 (0)