Skip to content

Commit 828bc8e

Browse files
committed
Test gc of core metrics
1 parent 7ff014f commit 828bc8e

File tree

2 files changed

+305
-7
lines changed

2 files changed

+305
-7
lines changed

src/rabbit_core_metrics_gc.erl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ start_link() ->
2929
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
3030

3131
init(_) ->
32-
Interval = rabbit_misc:get_env(rabbit, core_metrics_gc_interval, 30000),
32+
Interval = rabbit_misc:get_env(rabbit, core_metrics_gc_interval, 120000),
3333
{ok, start_timer(#state{interval = Interval})}.
3434

35-
handle_call(_Request, _From, State) ->
36-
{noreply, State}.
35+
handle_call(test, _From, State) ->
36+
{reply, ok, State}.
3737

3838
handle_cast(_Request, State) ->
3939
{noreply, State}.
@@ -77,7 +77,7 @@ gc_queues() ->
7777
gc_entity(queue_coarse_metrics, GbSet),
7878
gc_process_and_entity(channel_queue_metrics, GbSet),
7979
gc_process_and_entity(consumer_created, GbSet),
80-
ExchangeGbSet = gb_sets:from_list(rabbit_amqqueue:list_names()),
80+
ExchangeGbSet = gb_sets:from_list(rabbit_exchange:list_names()),
8181
gc_process_and_entities(channel_queue_exchange_metrics, GbSet, ExchangeGbSet).
8282

8383
gc_exchanges() ->
@@ -88,9 +88,6 @@ gc_exchanges() ->
8888
gc_nodes() ->
8989
Nodes = rabbit_mnesia:cluster_nodes(all),
9090
GbSet = gb_sets:from_list(Nodes),
91-
gc_entity(node_persister_metrics, GbSet),
92-
gc_entity(node_coarse_metrics, GbSet),
93-
gc_entity(node_metrics, GbSet),
9491
gc_entity(node_node_metrics, GbSet).
9592

9693
gc_gen_server2() ->
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(rabbit_core_metrics_gc_SUITE).
18+
19+
-include_lib("common_test/include/ct.hrl").
20+
-include_lib("eunit/include/eunit.hrl").
21+
-include_lib("amqp_client/include/amqp_client.hrl").
22+
23+
-compile(export_all).
24+
25+
all() ->
26+
[
27+
{group, non_parallel_tests}
28+
].
29+
30+
groups() ->
31+
[
32+
{non_parallel_tests, [],
33+
[ queue_metrics,
34+
connection_metrics,
35+
channel_metrics,
36+
node_metrics,
37+
gen_server2_metrics
38+
]
39+
}
40+
].
41+
42+
%% -------------------------------------------------------------------
43+
%% Testsuite setup/teardown.
44+
%% -------------------------------------------------------------------
45+
46+
merge_app_env(Config) ->
47+
rabbit_ct_helpers:merge_app_env(Config,
48+
{rabbit, [
49+
{core_metrics_gc_interval, 6000000},
50+
{collect_statistics_interval, 100},
51+
{collect_statistics, fine}
52+
]}).
53+
54+
init_per_suite(Config) ->
55+
rabbit_ct_helpers:log_environment(),
56+
Config1 = rabbit_ct_helpers:set_config(Config, [
57+
{rmq_nodename_suffix, ?MODULE}
58+
]),
59+
rabbit_ct_helpers:run_setup_steps(
60+
Config1,
61+
[ fun merge_app_env/1 ] ++ rabbit_ct_broker_helpers:setup_steps()).
62+
63+
end_per_suite(Config) ->
64+
rabbit_ct_helpers:run_teardown_steps(
65+
Config,
66+
rabbit_ct_broker_helpers:teardown_steps()).
67+
68+
init_per_group(_, Config) ->
69+
Config.
70+
71+
end_per_group(_, Config) ->
72+
Config.
73+
74+
init_per_testcase(Testcase, Config) ->
75+
rabbit_ct_helpers:testcase_started(Config, Testcase),
76+
rabbit_ct_helpers:run_steps(Config,
77+
rabbit_ct_client_helpers:setup_steps()).
78+
79+
end_per_testcase(Testcase, Config) ->
80+
rabbit_ct_helpers:testcase_finished(Config, Testcase),
81+
rabbit_ct_helpers:run_teardown_steps(
82+
Config,
83+
rabbit_ct_client_helpers:teardown_steps()).
84+
85+
%% -------------------------------------------------------------------
86+
%% Testcases.
87+
%% -------------------------------------------------------------------
88+
89+
queue_metrics(Config) ->
90+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
91+
Ch = rabbit_ct_client_helpers:open_channel(Config, A),
92+
93+
amqp_channel:call(Ch, #'queue.declare'{queue = <<"queue_metrics">>}),
94+
amqp_channel:cast(Ch, #'basic.publish'{routing_key = <<"queue_metrics">>},
95+
#amqp_msg{payload = <<"hello">>}),
96+
timer:sleep(150),
97+
98+
Q = q(<<"myqueue">>),
99+
100+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics, queue_stats,
101+
[Q, infos]),
102+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics, queue_stats,
103+
[Q, 1, 1, 1, 1]),
104+
105+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
106+
[queue_metrics, Q]),
107+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
108+
[queue_coarse_metrics, Q]),
109+
110+
%% Trigger gc. When the gen_server:call returns, the gc has already finished.
111+
rabbit_ct_broker_helpers:rpc(Config, A, erlang, send, [rabbit_core_metrics_gc, start_gc]),
112+
rabbit_ct_broker_helpers:rpc(Config, A, gen_server, call, [rabbit_core_metrics_gc, test]),
113+
114+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list,
115+
[queue_metrics]),
116+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list,
117+
[queue_coarse_metrics]),
118+
119+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
120+
[queue_metrics, Q]),
121+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
122+
[queue_coarse_metrics, Q]),
123+
124+
amqp_channel:call(Ch, #'queue.delete'{queue = <<"queue_metrics">>}),
125+
rabbit_ct_client_helpers:close_channel(Ch),
126+
127+
ok.
128+
129+
connection_metrics(Config) ->
130+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
131+
Ch = rabbit_ct_client_helpers:open_channel(Config, A),
132+
133+
amqp_channel:call(Ch, #'queue.declare'{queue = <<"queue_metrics">>}),
134+
amqp_channel:cast(Ch, #'basic.publish'{routing_key = <<"queue_metrics">>},
135+
#amqp_msg{payload = <<"hello">>}),
136+
timer:sleep(200),
137+
138+
DeadPid = rabbit_ct_broker_helpers:rpc(Config, A, ?MODULE, dead_pid, []),
139+
140+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
141+
connection_created, [DeadPid, infos]),
142+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
143+
connection_stats, [DeadPid, infos]),
144+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
145+
connection_stats, [DeadPid, 1, 1, 1]),
146+
147+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
148+
[connection_created, DeadPid]),
149+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
150+
[connection_metrics, DeadPid]),
151+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
152+
[connection_coarse_metrics, DeadPid]),
153+
154+
%% Trigger gc. When the gen_server:call returns, the gc has already finished.
155+
rabbit_ct_broker_helpers:rpc(Config, A, erlang, send, [rabbit_core_metrics_gc, start_gc]),
156+
rabbit_ct_broker_helpers:rpc(Config, A, gen_server, call, [rabbit_core_metrics_gc, test]),
157+
158+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
159+
[connection_created, DeadPid]),
160+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
161+
[connection_metrics, DeadPid]),
162+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
163+
[connection_coarse_metrics, DeadPid]),
164+
165+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [connection_created]),
166+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [connection_metrics]),
167+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [connection_coarse_metrics]),
168+
169+
amqp_channel:call(Ch, #'queue.delete'{queue = <<"queue_metrics">>}),
170+
rabbit_ct_client_helpers:close_channel(Ch),
171+
172+
ok.
173+
174+
channel_metrics(Config) ->
175+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
176+
Ch = rabbit_ct_client_helpers:open_channel(Config, A),
177+
178+
amqp_channel:call(Ch, #'queue.declare'{queue = <<"queue_metrics">>}),
179+
amqp_channel:cast(Ch, #'basic.publish'{routing_key = <<"queue_metrics">>},
180+
#amqp_msg{payload = <<"hello">>}),
181+
{#'basic.get_ok'{}, _} = amqp_channel:call(Ch, #'basic.get'{queue = <<"queue_metrics">>,
182+
no_ack=true}),
183+
timer:sleep(150),
184+
185+
DeadPid = rabbit_ct_broker_helpers:rpc(Config, A, ?MODULE, dead_pid, []),
186+
187+
Q = q(<<"myqueue">>),
188+
X = x(<<"myexchange">>),
189+
190+
191+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
192+
channel_created, [DeadPid, infos]),
193+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
194+
channel_stats, [DeadPid, infos]),
195+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
196+
channel_stats, [reductions, DeadPid, 1]),
197+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
198+
channel_stats, [exchange_stats, publish,
199+
{DeadPid, X}, 1]),
200+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
201+
channel_stats, [queue_stats, get,
202+
{DeadPid, Q}, 1]),
203+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics,
204+
channel_stats, [queue_exchange_stats, publish,
205+
{DeadPid, {Q, X}}, 1]),
206+
207+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
208+
[channel_created, DeadPid]),
209+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
210+
[channel_metrics, DeadPid]),
211+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
212+
[channel_process_metrics, DeadPid]),
213+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
214+
[channel_exchange_metrics, {DeadPid, X}]),
215+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
216+
[channel_queue_metrics, {DeadPid, Q}]),
217+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
218+
[channel_queue_exchange_metrics, {DeadPid, {Q, X}}]),
219+
220+
%% Trigger gc. When the gen_server:call returns, the gc has already finished.
221+
rabbit_ct_broker_helpers:rpc(Config, A, erlang, send, [rabbit_core_metrics_gc, start_gc]),
222+
rabbit_ct_broker_helpers:rpc(Config, A, gen_server, call, [rabbit_core_metrics_gc, test]),
223+
224+
225+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_created]),
226+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_metrics]),
227+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_process_metrics]),
228+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_exchange_metrics]),
229+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_queue_metrics]),
230+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [channel_queue_exchange_metrics]),
231+
232+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
233+
[channel_created, DeadPid]),
234+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
235+
[channel_metrics, DeadPid]),
236+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
237+
[channel_process_metrics, DeadPid]),
238+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
239+
[channel_exchange_metrics, {DeadPid, X}]),
240+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
241+
[channel_queue_metrics, {DeadPid, Q}]),
242+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
243+
[channel_queue_exchange_metrics, {DeadPid, {Q, X}}]),
244+
245+
amqp_channel:call(Ch, #'queue.delete'{queue = <<"queue_metrics">>}),
246+
rabbit_ct_client_helpers:close_channel(Ch),
247+
248+
ok.
249+
250+
node_metrics(Config) ->
251+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
252+
253+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics, node_node_stats,
254+
[{node(), 'deer@localhost'}, infos]),
255+
256+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
257+
[node_node_metrics, {node(), 'deer@localhost'}]),
258+
259+
%% Trigger gc. When the gen_server:call returns, the gc has already finished.
260+
rabbit_ct_broker_helpers:rpc(Config, A, erlang, send, [rabbit_core_metrics_gc, start_gc]),
261+
rabbit_ct_broker_helpers:rpc(Config, A, gen_server, call, [rabbit_core_metrics_gc, test]),
262+
263+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
264+
[node_node_metrics, {node(), 'deer@localhost'}]),
265+
266+
ok.
267+
268+
gen_server2_metrics(Config) ->
269+
A = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
270+
271+
DeadPid = rabbit_ct_broker_helpers:rpc(Config, A, ?MODULE, dead_pid, []),
272+
273+
rabbit_ct_broker_helpers:rpc(Config, A, rabbit_core_metrics, gen_server2_stats,
274+
[DeadPid, 1]),
275+
276+
[_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
277+
[gen_server2_metrics, DeadPid]),
278+
279+
%% Trigger gc. When the gen_server:call returns, the gc has already finished.
280+
rabbit_ct_broker_helpers:rpc(Config, A, erlang, send, [rabbit_core_metrics_gc, start_gc]),
281+
rabbit_ct_broker_helpers:rpc(Config, A, gen_server, call, [rabbit_core_metrics_gc, test]),
282+
283+
[_|_] = rabbit_ct_broker_helpers:rpc(Config, A, ets, tab2list, [gen_server2_metrics]),
284+
285+
[] = rabbit_ct_broker_helpers:rpc(Config, A, ets, lookup,
286+
[gen_server2_metrics, DeadPid]),
287+
288+
ok.
289+
290+
dead_pid() ->
291+
spawn(fun() -> ok end).
292+
293+
q(Name) ->
294+
#resource{ virtual_host = <<"/">>,
295+
kind = queue,
296+
name = Name }.
297+
298+
x(Name) ->
299+
#resource{ virtual_host = <<"/">>,
300+
kind = exchange,
301+
name = Name }.

0 commit comments

Comments
 (0)