diff --git a/apps/emqx_statsd/src/emqx_statsd.erl b/apps/emqx_statsd/src/emqx_statsd.erl index 892731a6c..5f88e5bdd 100644 --- a/apps/emqx_statsd/src/emqx_statsd.erl +++ b/apps/emqx_statsd/src/emqx_statsd.erl @@ -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), diff --git a/apps/emqx_statsd/src/emqx_statsd_api.erl b/apps/emqx_statsd/src/emqx_statsd_api.erl index 97e803f5b..2278fa492 100644 --- a/apps/emqx_statsd/src/emqx_statsd_api.erl +++ b/apps/emqx_statsd/src/emqx_statsd_api.erl @@ -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.