Skip to content

Commit 5a13cb4

Browse files
committed
WIP List sessions for connection
Display session and link details on the connection page in the Management UI. Example query: ``` curl -u guest:guest 'http://localhost:15672/api/connections/%5B%3A%3A1%5D%3A49564%20-%3E%20%5B%3A%3A1%5D%3A5672/sessions' | jq . ```
1 parent a7281c4 commit 5a13cb4

File tree

8 files changed

+336
-5
lines changed

8 files changed

+336
-5
lines changed

deps/rabbit/src/rabbit_amqp_reader.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,8 @@ silent_close_delay() ->
967967
-spec info(rabbit_types:connection(), rabbit_types:info_keys()) ->
968968
rabbit_types:infos().
969969
info(Pid, InfoItems) ->
970-
case InfoItems -- ?INFO_ITEMS of
970+
KnownItems = [sessions | ?INFO_ITEMS],
971+
case InfoItems -- KnownItems of
971972
[] ->
972973
case gen_server:call(Pid, {info, InfoItems}, infinity) of
973974
{ok, InfoList} ->
@@ -1065,6 +1066,8 @@ i(client_properties, #v1{connection = #v1_connection{properties = Props}}) ->
10651066
end;
10661067
i(channels, #v1{tracked_channels = Channels}) ->
10671068
maps:size(Channels);
1069+
i(sessions, #v1{tracked_channels = Val}) ->
1070+
Val;
10681071
i(channel_max, #v1{connection = #v1_connection{channel_max = Max}}) ->
10691072
Max;
10701073
i(reductions = Item, _State) ->

deps/rabbit/src/rabbit_amqp_session.erl

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
conserve_resources/3,
9393
check_resource_access/4,
9494
check_read_permitted_on_topic/4,
95-
reset_authz/2
95+
reset_authz/2,
96+
info/1
9697
]).
9798

9899
-export([init/1,
@@ -149,6 +150,7 @@
149150

150151
-record(incoming_link, {
151152
snd_settle_mode :: snd_settle_mode(),
153+
target_address :: undefined | {utf8, binary()},
152154
%% The exchange is either defined in the ATTACH frame and static for
153155
%% the life time of the link or dynamically provided in each message's
154156
%% "to" field (address v2).
@@ -490,6 +492,8 @@ conserve_resources(Pid, Source, {_, Conserve, _}) ->
490492
reset_authz(Pid, User) ->
491493
gen_server:cast(Pid, {reset_authz, User}).
492494

495+
handle_call(infos, _From, State) ->
496+
reply(infos(State), State);
493497
handle_call(Msg, _From, State) ->
494498
Reply = {error, {not_understood, Msg}},
495499
reply(Reply, State).
@@ -1266,7 +1270,7 @@ handle_attach(#'v1_0.attach'{role = ?AMQP_ROLE_SENDER,
12661270
handle = Handle = ?UINT(HandleInt),
12671271
source = Source,
12681272
snd_settle_mode = MaybeSndSettleMode,
1269-
target = Target,
1273+
target = Target = #'v1_0.target'{address = TargetAddress},
12701274
initial_delivery_count = DeliveryCount = ?UINT(DeliveryCountInt)
12711275
},
12721276
State0 = #state{incoming_links = IncomingLinks0,
@@ -1280,6 +1284,7 @@ handle_attach(#'v1_0.attach'{role = ?AMQP_ROLE_SENDER,
12801284
MaxMessageSize = persistent_term:get(max_message_size),
12811285
IncomingLink = #incoming_link{
12821286
snd_settle_mode = SndSettleMode,
1287+
target_address = TargetAddress,
12831288
exchange = Exchange,
12841289
routing_key = RoutingKey,
12851290
queue_name_bin = QNameBin,
@@ -3702,6 +3707,87 @@ format_status(
37023707
topic_permission_cache => TopicPermissionCache},
37033708
maps:update(state, State, Status).
37043709

3710+
-spec info(pid()) ->
3711+
{ok, rabbit_types:infos()} | {error, term()}.
3712+
info(Pid) ->
3713+
try gen_server:call(Pid, infos) of
3714+
Infos ->
3715+
{ok, Infos}
3716+
catch exit:timeout ->
3717+
{error, timeout}
3718+
end.
3719+
3720+
infos(#state{cfg = #cfg{channel_num = ChannelNum,
3721+
max_handle = MaxHandle},
3722+
next_incoming_id = NextIncomingId,
3723+
incoming_window = IncomingWindow,
3724+
next_outgoing_id = NextOutgoingId,
3725+
remote_incoming_window = RemoteIncomingWindow,
3726+
remote_outgoing_window = RemoteOutgoingWindow,
3727+
management_link_pairs = ManagementLinkPairs,
3728+
outgoing_unsettled_map = OutgoingUnsettledMap,
3729+
incoming_links = IncomingLinks,
3730+
outgoing_links = OutgoingLinks
3731+
}) ->
3732+
[
3733+
{channel_number, ChannelNum},
3734+
{handle_max, MaxHandle},
3735+
{next_incoming_id, NextIncomingId},
3736+
{incoming_window, IncomingWindow},
3737+
{next_outgoing_id, NextOutgoingId},
3738+
{remote_incoming_window, RemoteIncomingWindow},
3739+
{remote_outgoing_window, RemoteOutgoingWindow},
3740+
{link_pairs, maps:size(ManagementLinkPairs)},
3741+
{outgoing_unsettled_deliveries, maps:size(OutgoingUnsettledMap)},
3742+
{incoming_links, info_incoming_links(IncomingLinks)},
3743+
{outgoing_links, info_outgoing_links(OutgoingLinks)}
3744+
].
3745+
3746+
info_incoming_links(Links) ->
3747+
[begin
3748+
Addr = case TargetAddress of
3749+
undefined -> null;
3750+
{utf8, Addr0} -> Addr0
3751+
end,
3752+
[
3753+
{handle, Handle},
3754+
{snd_settle_mode, SndSettleMode},
3755+
{target_address, Addr},
3756+
{delivery_count, DeliveryCount},
3757+
{credit, Credit},
3758+
{unconfirmed_messages, maps:size(IncomingUnconfirmedMap)}
3759+
]
3760+
end
3761+
|| Handle := #incoming_link{
3762+
snd_settle_mode = SndSettleMode,
3763+
target_address = TargetAddress,
3764+
delivery_count = DeliveryCount,
3765+
credit = Credit,
3766+
incoming_unconfirmed_map = IncomingUnconfirmedMap} <- Links].
3767+
3768+
info_outgoing_links(Links) ->
3769+
[begin
3770+
{DeliveryCount, Credit} = case ClientFlowCtl of
3771+
#client_flow_ctl{delivery_count = DC,
3772+
credit = C} ->
3773+
{DC, C};
3774+
credit_api_v1 ->
3775+
{'', ''}
3776+
end,
3777+
[
3778+
{handle, Handle},
3779+
{queue_name, QueueName#resource.name},
3780+
{send_settled, SendSettled},
3781+
{max_message_size, MaxMessageSize},
3782+
{delivery_count, DeliveryCount},
3783+
{credit, Credit}
3784+
]
3785+
end
3786+
|| Handle := #outgoing_link{
3787+
queue_name = QueueName,
3788+
max_message_size = MaxMessageSize,
3789+
send_settled = SendSettled,
3790+
client_flow_ctl = ClientFlowCtl} <- Links].
37053791

37063792
unwrap_simple_type(V = {list, _}) ->
37073793
V;

deps/rabbitmq_management/priv/www/js/dispatcher.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ dispatcher_add(function(sammy) {
4848
var name = esc(this.params['name']);
4949
render({'connection': {path: '/connections/' + name,
5050
options: {ranges: ['data-rates-conn']}},
51-
'channels': '/connections/' + name + '/channels'},
51+
'channels': '/connections/' + name + '/channels',
52+
'sessions': '/connections/' + name + '/sessions'},
5253
'connection', '#/connections');
5354
});
5455
sammy.del('#/connections', function() {

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ var ALL_COLUMNS =
107107
['rate-deliver', 'deliver / get', true],
108108
['rate-redeliver', 'redelivered', false],
109109
['rate-ack', 'ack', true]]},
110+
111+
'sessions' :
112+
{'Overview': [],
113+
'Session Flow Control': [['incoming-window', 'Incoming window', true]]},
114+
110115
'connections':
111116
{'Overview': [['container_id', 'Container ID', true],
112117
['user', 'User name', true],
@@ -586,8 +591,34 @@ var HELP = {
586591
</dl> ',
587592

588593
'container-id':
589-
'Name of the client application as sent from client to RabbitMQ in the "container-id" field 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.'
594+
'Name of the client application as sent from client to RabbitMQ in the "container-id" field 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.',
595+
596+
'link-pairs':
597+
'Number of <a target="_blank" href="https://docs.oasis-open.org/amqp/linkpair/v1.0/cs01/linkpair-v1.0-cs01.html#_Toc51331304">link pairs</a>.',
598+
599+
'incoming-links':
600+
'<a target="_blank" href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#section-links">Links</a> where the client is the sender/publisher and RabbitMQ is the receiver of messages.',
601+
602+
'outgoing-links':
603+
'<a target="_blank" href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#section-links">Links</a> where the client is the receiver/consumer and RabbitMQ is the sender of messages.',
604+
605+
'target-address':
606+
'The "address" field of the link <a target="_blank" href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-target">target</a>.',
607+
608+
'amqp-source-queue':
609+
'The client receives messages from this queue.',
610+
611+
'amqp-unconfirmed-messages':
612+
'Number of messages that have been sent to queues but have not been confirmed by all queues.',
613+
614+
'snd-settle-mode':
615+
'<a target="_blank" href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-sender-settle-mode">Sender Settle Mode</a>',
616+
617+
'sender-settles':
618+
'"true" if the sender sends all deliveries settled to the receiver. "false" if the sender sends all deliveries initially unsettled to the receiver.',
590619

620+
'outgoing-unsettled-deliveries':
621+
'Number of messages that have been sent to consumers but have not yet been settled/forgotten/acknowledged.'
591622
};
592623

593624
///////////////////////////////////////////////////////////////////////////

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,23 @@
8484
</div>
8585
</div>
8686
87+
<% if (connection.protocol === "AMQP 1-0") { %>
88+
<div class="section">
89+
<h2 class="updatable" >Sessions (<%=(sessions.length)%>) </h2>
90+
<div class="hider updatable">
91+
<%= format('sessions-list', {'sessions': sessions}) %>
92+
</div>
93+
</div>
94+
<% } %>
95+
96+
<% if (connection.protocol === "AMQP 0-9-1") { %>
8797
<div class="section">
8898
<h2 class="updatable" >Channels (<%=(channels.length)%>) </h2>
8999
<div class="hider updatable">
90100
<%= format('channels-list', {'channels': channels, 'mode': 'connection'}) %>
91101
</div>
92102
</div>
103+
<% } %>
93104
94105
<% if (connection.ssl) { %>
95106
<div class="section">
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<table class="list">
2+
<thead>
3+
<tr>
4+
<th>Channel number</th>
5+
<th>handle-max</th>
6+
<th>next-incoming-id</th>
7+
<th>incoming-window</th>
8+
<th>next-outgoing-id</th>
9+
<th>remote-incoming-window</th>
10+
<th>remote-outgoing-window</th>
11+
<th>Link pairs <span class="help" id="link-pairs"></span></th>
12+
<th>Outgoing unsettled deliveries <span class="help" id="outgoing-unsettled-deliveries"></span></th>
13+
</tr>
14+
</thead>
15+
16+
<tbody>
17+
<%
18+
for (var i = 0; i < sessions.length; i++) {
19+
var session = sessions[i];
20+
%>
21+
<tr>
22+
<td class="c"><%= fmt_string(session.channel_number) %></td>
23+
<td class="c"><%= fmt_string(session.handle_max) %></td>
24+
<td class="c"><%= fmt_string(session.next_incoming_id) %></td>
25+
<td class="c"><%= fmt_string(session.incoming_window) %></td>
26+
<td class="c"><%= fmt_string(session.next_outgoing_id) %></td>
27+
<td class="c"><%= fmt_string(session.remote_incoming_window) %></td>
28+
<td class="c"><%= fmt_string(session.remote_outgoing_window) %></td>
29+
<td class="c"><%= fmt_string(session.link_pairs) %></td>
30+
<td class="c"><%= fmt_string(session.outgoing_unsettled_deliveries) %></td>
31+
</tr>
32+
<% if (session.incoming_links.length > 0) { %>
33+
<tr>
34+
<td colspan="9">
35+
<p>Incoming Links (<%=(session.incoming_links.length)%>) <span class="help" id="incoming-links"></span></p>
36+
<table class="list">
37+
<thead>
38+
<tr>
39+
<th>Link handle</th>
40+
<th>Target address <span class="help" id="target-address"></span></th>
41+
<th>snd-settle-mode <span class="help" id="snd-settle-mode"></span></th>
42+
<th>delivery-count</th>
43+
<th>link-credit</th>
44+
<th>Unconfirmed messages <span class="help" id="amqp-unconfirmed-messages"></span></th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
<%
49+
for (var j = 0; j < session.incoming_links.length; j++) {
50+
var in_link = session.incoming_links[j];
51+
%>
52+
<tr>
53+
<td class="c"><%= fmt_string(in_link.handle) %></td>
54+
<td class="c"><%= fmt_string(in_link.target_address) %></td>
55+
<td class="c"><%= fmt_string(in_link.snd_settle_mode) %></td>
56+
<td class="c"><%= fmt_string(in_link.delivery_count) %></td>
57+
<td class="c"><%= fmt_string(in_link.credit) %></td>
58+
<td class="c"><%= fmt_string(in_link.unconfirmed_messages) %></td>
59+
</tr>
60+
<% } %>
61+
</tbody>
62+
</table>
63+
</td>
64+
</tr>
65+
<% } %>
66+
<% if (session.outgoing_links.length > 0) { %>
67+
<tr>
68+
<td colspan="9">
69+
<p>Outgoing Links (<%=(session.outgoing_links.length)%>) <span class="help" id="outgoing-links"></span></p>
70+
<table class="list">
71+
<thead>
72+
<tr>
73+
<th>Link handle</th>
74+
<th>Source queue <span class="help" id="amqp-source-queue"></span></th>
75+
<th>Sender settles <span class="help" id="sender-settles"></span></th>
76+
<th>max-message-size</th>
77+
<th>delivery-count</th>
78+
<th>link-credit</th>
79+
</tr>
80+
</thead>
81+
<tbody>
82+
<%
83+
for (var k = 0; k < session.outgoing_links.length; k++) {
84+
var out_link = session.outgoing_links[k];
85+
%>
86+
<tr>
87+
<td class="c"><%= fmt_string(out_link.handle) %></td>
88+
<td class="c"><%= fmt_string(out_link.queue_name) %></td>
89+
<td class="c"><%= fmt_string(out_link.send_settled) %></td>
90+
<td class="c"><%= fmt_string(out_link.max_message_size) %></td>
91+
<td class="c"><%= fmt_string(out_link.delivery_count) %></td>
92+
<td class="c"><%= fmt_string(out_link.credit) %></td>
93+
</tr>
94+
<% } %>
95+
</tbody>
96+
</table>
97+
</td>
98+
</tr>
99+
<% } %>
100+
<% } %>
101+
</tbody>
102+
</table>

deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ dispatcher() ->
132132
{"/connections/:connection", rabbit_mgmt_wm_connection, []},
133133
{"/connections/username/:username", rabbit_mgmt_wm_connection_user_name, []},
134134
{"/connections/:connection/channels", rabbit_mgmt_wm_connection_channels, []},
135+
{"/connections/:connection/sessions", rabbit_mgmt_wm_connection_sessions, []},
135136
{"/channels", rabbit_mgmt_wm_channels, []},
136137
{"/channels/:channel", rabbit_mgmt_wm_channel, []},
137138
{"/consumers", rabbit_mgmt_wm_consumers, []},

0 commit comments

Comments
 (0)