Skip to content

Commit 9751c7f

Browse files
Merge pull request #3169 from rabbitmq/mk-more-idempotent-tracing-state-change
Do not update virtual host tracing state when it's not necessary (cherry picked from commit c39fa74) Conflicts: deps/rabbit/src/rabbit_trace.erl
1 parent 48c05a5 commit 9751c7f

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

deps/rabbit/src/rabbit_trace.erl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,43 @@ tap_out({#resource{name = QName, virtual_host = VHost},
7474
-spec start(rabbit_types:vhost()) -> 'ok'.
7575

7676
start(VHost) ->
77-
_ = rabbit_log:info("Enabling tracing for vhost '~s'~n", [VHost]),
78-
update_config(fun (VHosts) -> [VHost | VHosts -- [VHost]] end).
77+
case lists:member(VHost, vhosts_with_tracing_enabled()) of
78+
true ->
79+
_ = rabbit_log:info("Tracing is already enabled for vhost '~s'", [VHost]),
80+
ok;
81+
false ->
82+
_ = rabbit_log:info("Enabling tracing for vhost '~s'", [VHost]),
83+
update_config(fun (VHosts) ->
84+
lists:usort([VHost | VHosts])
85+
end)
86+
end.
7987

8088
-spec stop(rabbit_types:vhost()) -> 'ok'.
8189

8290
stop(VHost) ->
83-
_ = rabbit_log:info("Disabling tracing for vhost '~s'~n", [VHost]),
84-
update_config(fun (VHosts) -> VHosts -- [VHost] end).
91+
case lists:member(VHost, vhosts_with_tracing_enabled()) of
92+
true ->
93+
_ = rabbit_log:info("Disabling tracing for vhost '~s'", [VHost]),
94+
update_config(fun (VHosts) -> VHosts -- [VHost] end);
95+
false ->
96+
_ = rabbit_log:info("Tracing is already disabled for vhost '~s'", [VHost]),
97+
ok
98+
end.
8599

86100
update_config(Fun) ->
87-
{ok, VHosts0} = application:get_env(rabbit, ?TRACE_VHOSTS),
101+
VHosts0 = vhosts_with_tracing_enabled(),
88102
VHosts = Fun(VHosts0),
89103
application:set_env(rabbit, ?TRACE_VHOSTS, VHosts),
90-
rabbit_channel:refresh_config_local(),
104+
_ = rabbit_log:debug("Will now refresh channel state after virtual host tracing changes"),
105+
106+
{Time, _} = timer:tc(fun rabbit_channel:refresh_config_local/0),
107+
_ = rabbit_log:debug("Refreshed channel state in ~fs", [Time/1000000]),
108+
91109
ok.
92110

111+
vhosts_with_tracing_enabled() ->
112+
application:get_env(rabbit, ?TRACE_VHOSTS, []).
113+
93114
%%----------------------------------------------------------------------------
94115

95116
trace(#exchange{name = Name}, #basic_message{exchange_name = Name},

0 commit comments

Comments
 (0)