fix(statsd): update config in cluster

This commit is contained in:
DDDHuang 2021-12-31 11:00:55 +08:00
parent 888e7fd727
commit 3a38e8d68d
2 changed files with 17 additions and 11 deletions

View File

@ -94,7 +94,7 @@ terminate(_Reason, #state{estatsd_pid = Pid}) ->
ok. ok.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Internale function %% Internal function
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
trans_metrics_name(Name) -> trans_metrics_name(Name) ->
Name0 = atom_to_binary(Name, utf8), Name0 = atom_to_binary(Name, utf8),

View File

@ -55,13 +55,19 @@ statsd(get, _Params) ->
{200, emqx:get_raw_config([<<"statsd">>], #{})}; {200, emqx:get_raw_config([<<"statsd">>], #{})};
statsd(put, #{body := Body}) -> statsd(put, #{body := Body}) ->
{ok, Config} = emqx:update_config([statsd], Body), case emqx:update_config([statsd],
case maps:get(<<"enable">>, Body) of Body,
true -> #{rawconf_with_defaults => true, override_to => cluster}) of
_ = emqx_statsd_sup:stop_child(?APP), {ok, #{raw_config := NewConfig, config := Config}} ->
emqx_statsd_sup:start_child(?APP, maps:get(config, Config)); case maps:get(<<"enable">>, Body) of
false -> true ->
_ = emqx_statsd_sup:stop_child(?APP), _ = emqx_statsd_sup:stop_child(?APP),
ok emqx_statsd_sup:start_child(?APP, maps:get(config, Config));
end, false ->
{200, emqx:get_raw_config([<<"statsd">>], #{})}. _ = emqx_statsd_sup:stop_child(?APP)
end,
{200, NewConfig};
{error, Reason} ->
Message = list_to_binary(io_lib:format("Update config failed ~p", [Reason])),
{500, 'INTERNAL_ERROR', Message}
end.