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.
%%------------------------------------------------------------------------------
%% Internale function
%% Internal function
%%------------------------------------------------------------------------------
trans_metrics_name(Name) ->
Name0 = atom_to_binary(Name, utf8),

View File

@ -55,13 +55,19 @@ statsd(get, _Params) ->
{200, emqx:get_raw_config([<<"statsd">>], #{})};
statsd(put, #{body := Body}) ->
{ok, Config} = emqx:update_config([statsd], Body),
case maps:get(<<"enable">>, Body) of
true ->
_ = emqx_statsd_sup:stop_child(?APP),
emqx_statsd_sup:start_child(?APP, maps:get(config, Config));
false ->
_ = emqx_statsd_sup:stop_child(?APP),
ok
end,
{200, emqx:get_raw_config([<<"statsd">>], #{})}.
case emqx:update_config([statsd],
Body,
#{rawconf_with_defaults => true, override_to => cluster}) of
{ok, #{raw_config := NewConfig, config := Config}} ->
case maps:get(<<"enable">>, Body) of
true ->
_ = emqx_statsd_sup:stop_child(?APP),
emqx_statsd_sup:start_child(?APP, maps:get(config, Config));
false ->
_ = 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.