Skip to content

Commit 2bd0094

Browse files
Merge pull request #15975 from rabbitmq/connection-info-disable-metrics-conn
HTTP API: Display static connection info when stats are disabled
2 parents c49465f + a7dc791 commit 2bd0094

9 files changed

Lines changed: 79 additions & 34 deletions

File tree

deps/rabbitmq_management/priv/www/js/formatters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,10 @@ function group_count(mode, group, bools) {
971971
var options = COLUMNS[mode][group];
972972
for (var i = 0; i < options.length; i++) {
973973
var column = options[i][0];
974+
if (mode === 'connections' && disable_stats &&
975+
(column === 'from_client' || column === 'to_client')) {
976+
continue;
977+
}
974978
if (show_column(mode, column)) count++;
975979
}
976980
return count;

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,19 @@ var DISABLED_STATS_COLUMNS =
170170
['msgs-persistent', 'Persistent', false],
171171
['msgs-total', 'Total', true]]},
172172
'connections':
173-
{'Overview': [['user', 'User name', true],
174-
['state', 'State', true]]},
173+
{'Overview': [['container_id', 'Container ID', true],
174+
['user', 'User name', true]],
175+
'Details': [['ssl', 'TLS', true],
176+
['ssl_info', 'TLS details', false],
177+
['protocol', 'Protocol', true],
178+
['channel_max', 'Channel max', false],
179+
['frame_max', 'Frame max', false],
180+
['auth_mechanism', 'SASL auth mechanism', false],
181+
['client', 'Client', false]],
182+
'Network': [['from_client', 'From client', false],
183+
['to_client', 'To client', false],
184+
['heartbeat', 'Heartbeat', false],
185+
['connected_at', 'Connected at', false]]},
175186

176187
'vhosts':
177188
{'Overview': [['cluster-state', 'Cluster state', false]]}};

deps/rabbitmq_management/priv/www/js/tmpl/columns-options.ejs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
<tr>
1616
<th><label><%= group %>:</label></th>
1717
<td>
18-
<% for (var i = 0; i < options.length; i++) { %>
18+
<% for (var i = 0; i < options.length; i++) {
19+
if (mode === 'connections' && disable_stats &&
20+
(options[i][0] === 'from_client' || options[i][0] === 'to_client')) {
21+
continue;
22+
}
23+
%>
1924
<%= fmt_checkbox(mode + '-' + options[i][0], options[i][1], get_pref('column-' + mode + '-' + options[i][0]) == 'true') %>
2025
<% } %>
2126
</td>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<h2>Connection <%= fmt_string(connection.name) %> <%= fmt_maybe_vhost(connection.vhost) %></h1>
22

3-
<% if (!disable_stats) { %>
43
<div class="section" id="connection-overview-section">
54
<h2>Overview</h2>
65
<div class="hider updatable">
6+
<% if (!disable_stats) { %>
77
<%= data_rates('data-rates-conn', connection, 'Data rates') %>
8+
<% } %>
89

910
<h3>Details</h3>
1011
<table class="facts facts-l">
@@ -83,6 +84,7 @@
8384
</div>
8485
</div>
8586

87+
<% if (!disable_stats) { %>
8688
<% if (connection.protocol === 'AMQP 1-0' ||
8789
connection.protocol === 'Web AMQP 1-0') { %>
8890
@@ -102,6 +104,7 @@
102104
</div>
103105
</div>
104106
107+
<% } %>
105108
<% } %>
106109

107110
<% if (connection.ssl) { %>
@@ -157,7 +160,7 @@
157160
</div>
158161
<% } %>
159162

160-
<% if(connection.reductions || connection.garbage_collection) { %>
163+
<% if (!disable_stats && (connection.reductions || connection.garbage_collection)) { %>
161164
<div class="section-hidden" id="connection-runtime-metrics-section">
162165
<h2>Runtime Metrics (Advanced)</h2>
163166
<div class="hider updatable">
@@ -194,7 +197,6 @@
194197
</div>
195198
</div>
196199
197-
<% } %>
198200
<% } %>
199201

200202
<div class="section-hidden" id="connection-close-section">

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
<thead>
99
<tr>
1010
<%= group_heading('connections', 'Overview', [vhosts_interesting, nodes_interesting, true]) %>
11-
<% if (!disable_stats) { %>
1211
<%= group_heading('connections', 'Details', []) %>
1312
<%= group_heading('connections', 'Network', []) %>
14-
<% } %>
1513
<th class="plus-minus"><span class="popup-options-link" title="Click to change columns" type="columns" for="connections">+/-</span></th>
1614
</tr>
1715
<tr>
@@ -32,8 +30,7 @@
3230
<% if (show_column('connections', 'user')) { %>
3331
<th><%= fmt_sort('User name', 'user') %></th>
3432
<% } %>
35-
<% if (!disable_stats) { %>
36-
<% if (show_column('connections', 'state')) { %>
33+
<% if (show_column('connections', 'state') && !disable_stats) { %>
3734
<th><%= fmt_sort('State', 'state') %></th>
3835
<% } %>
3936
<% if (show_column('connections', 'ssl')) { %>
@@ -45,7 +42,7 @@
4542
<% if (show_column('connections', 'protocol')) { %>
4643
<th><%= fmt_sort('Protocol', 'protocol') %></th>
4744
<% } %>
48-
<% if (show_column('connections', 'channels')) { %>
45+
<% if (show_column('connections', 'channels') && !disable_stats) { %>
4946
<th><%= fmt_sort('Channels', 'channels') %></th>
5047
<% } %>
5148
<% if (show_column('connections', 'channel_max')) { %>
@@ -60,18 +57,17 @@
6057
<% if (show_column('connections', 'client')) { %>
6158
<th><%= fmt_sort('Client', 'properties') %></th>
6259
<% } %>
63-
<% if (show_column('connections', 'from_client')) { %>
60+
<% if (show_column('connections', 'from_client') && !disable_stats) { %>
6461
<th><%= fmt_sort('From client', 'recv_oct_details.rate') %></th>
6562
<% } %>
66-
<% if (show_column('connections', 'to_client')) { %>
63+
<% if (show_column('connections', 'to_client') && !disable_stats) { %>
6764
<th><%= fmt_sort('To client', 'send_oct_details.rate') %></th>
6865
<% } %>
6966
<% if (show_column('connections', 'heartbeat')) { %>
7067
<th><%= fmt_sort('Heartbeat', 'timeout') %></th>
7168
<% } %>
7269
<% if (show_column('connections', 'connected_at')) { %>
7370
<th><%= fmt_sort('Connected at', 'connected_at') %></th>
74-
<% } %>
7571
<% } %>
7672
</tr>
7773
</thead>
@@ -107,8 +103,7 @@
107103
<% if (show_column('connections', 'user')) { %>
108104
<td class="c"><%= fmt_string(connection.user) %></td>
109105
<% } %>
110-
<% if (!disable_stats) { %>
111-
<% if (show_column('connections', 'state')) { %>
106+
<% if (show_column('connections', 'state') && !disable_stats) { %>
112107
<td><%= fmt_object_state(connection) %></td>
113108
<% } %>
114109
<% if (show_column('connections', 'ssl')) { %>
@@ -129,7 +124,7 @@
129124
<% if (show_column('connections', 'protocol')) { %>
130125
<td class="c"><%= connection.protocol %></td>
131126
<% } %>
132-
<% if (show_column('connections', 'channels')) { %>
127+
<% if (show_column('connections', 'channels') && !disable_stats) { %>
133128
<td class="r"><%= fmt_string(connection.channels, '') %></td>
134129
<% } %>
135130
<% if (show_column('connections', 'channel_max')) { %>
@@ -144,10 +139,10 @@
144139
<% if (show_column('connections', 'client')) { %>
145140
<td><%= fmt_client_name(connection.client_properties) %></td>
146141
<% } %>
147-
<% if (show_column('connections', 'from_client')) { %>
142+
<% if (show_column('connections', 'from_client') && !disable_stats) { %>
148143
<td><%= fmt_detail_rate_bytes(connection, 'recv_oct') %></td>
149144
<% } %>
150-
<% if (show_column('connections', 'to_client')) { %>
145+
<% if (show_column('connections', 'to_client') && !disable_stats) { %>
151146
<td><%= fmt_detail_rate_bytes(connection, 'send_oct') %></td>
152147
<% } %>
153148
<% if (show_column('connections', 'heartbeat')) { %>
@@ -156,7 +151,6 @@
156151
<% if (show_column('connections', 'connected_at')) { %>
157152
<td><%= fmt_timestamp_mini(connection.connected_at) %></td>
158153
<% } %>
159-
<% } %>
160154
</tr>
161155
<% } %>
162156
</tbody>

deps/rabbitmq_management/src/rabbit_mgmt_db.erl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
get_channel/2, get_connection/2,
2424
get_all_channels/1, get_all_connections/1,
2525
get_all_consumers/0, get_all_consumers/1,
26-
get_overview/2, get_overview/1]).
26+
get_overview/2, get_overview/1,
27+
get_all_connections/0, get_connection/1]).
2728

2829
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
2930
code_change/3, handle_pre_hibernate/1,
@@ -189,6 +190,11 @@ get_connection(Name, Ranges) ->
189190
end
190191
end).
191192

193+
get_connection(Name) ->
194+
submit(fun(_Interval) ->
195+
created_stats_delegated(Name, connection_created_stats)
196+
end).
197+
192198
get_all_channels(?NO_RANGES = Ranges) ->
193199
submit_cached(channels,
194200
fun(Interval) ->
@@ -213,6 +219,11 @@ get_all_connections(Ranges) ->
213219
connection_stats(Ranges, Chans, Interval)
214220
end).
215221

222+
get_all_connections() ->
223+
submit(fun(_) ->
224+
created_stats_delegated(connection_created_stats)
225+
end).
226+
216227
get_all_consumers() -> get_all_consumers(all).
217228
get_all_consumers(VHosts) ->
218229
submit(fun(_Interval) -> consumers_stats(VHosts) end).

deps/rabbitmq_management/src/rabbit_mgmt_wm_connection.erl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,25 @@ resource_exists(ReqData, Context) ->
3535
end.
3636

3737
to_json(ReqData, Context) ->
38-
case rabbit_mgmt_util:disable_stats(ReqData) of
39-
false ->
40-
ConnStats = conn_stats(ReqData),
41-
ConnStatsWithoutPids = rabbit_mgmt_format:strip_pids(ConnStats),
42-
ReplyData = maps:from_list(ConnStatsWithoutPids),
43-
rabbit_mgmt_util:reply(ReplyData, ReqData, Context);
44-
true ->
45-
ReplyData = [{name, rabbit_mgmt_util:id(connection, ReqData)}],
46-
rabbit_mgmt_util:reply(ReplyData, ReqData, Context)
47-
end.
38+
ConnStats =
39+
case rabbit_mgmt_util:disable_stats(ReqData) of
40+
false ->
41+
conn_stats(ReqData);
42+
true ->
43+
case rabbit_mgmt_db:get_connection(
44+
rabbit_mgmt_util:id(connection, ReqData)) of
45+
not_found ->
46+
%% IMPORTANT: connection_created_stats is empty when
47+
%% the metrics collector is disabled. Fall back to
48+
%% the tracked-connection record.
49+
conn(ReqData);
50+
Stats ->
51+
Stats
52+
end
53+
end,
54+
ConnStatsWithoutPids = rabbit_mgmt_format:strip_pids(ConnStats),
55+
ReplyData = maps:from_list(ConnStatsWithoutPids),
56+
rabbit_mgmt_util:reply(ReplyData, ReqData, Context).
4857

4958
delete_resource(ReqData, Context) ->
5059
case conn(ReqData) of

deps/rabbitmq_management/src/rabbit_mgmt_wm_connections.erl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ do_connections_query(ReqData, Context) ->
4848
false ->
4949
augmented(ReqData, Context);
5050
true ->
51-
rabbit_mgmt_util:filter_tracked_conn_list(rabbit_connection_tracking:list(),
52-
ReqData, Context)
51+
case rabbit_mgmt_agent_config:is_metrics_collector_enabled() of
52+
true ->
53+
rabbit_mgmt_util:filter_conn_ch_list(
54+
rabbit_mgmt_db:get_all_connections(), ReqData, Context);
55+
false ->
56+
%% IMPORTANT: connection_created_stats is empty when the
57+
%% metrics collector is disabled. Fall back to the
58+
%% tracked-connection list.
59+
rabbit_mgmt_util:filter_tracked_conn_list(
60+
rabbit_connection_tracking:list(), ReqData, Context)
61+
end
5362
end.

deps/rabbitmq_management/test/rabbit_mgmt_only_http_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ connections_test(Config) ->
317317
[LocalPort, amqp_port(Config)])),
318318
await_condition(fun() ->
319319
C = http_get(Config, Path, ?OK),
320-
maps:size(C) =:= 1 andalso maps:is_key(name, C) andalso
320+
maps:is_key(name, C) andalso maps:is_key(client_properties, C) andalso
321321
not maps:is_key(recv_oct_details, C)
322322
end),
323323
http_delete(Config, Path, {group, '2xx'}),

0 commit comments

Comments
 (0)