diff --git a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl index 12a3a8e23..4ecc61cec 100644 --- a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl +++ b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl @@ -221,6 +221,7 @@ t_mqtt_conn_bridge_ingress(_) -> %% ... and a MQTT bridge, using POST %% we bind this bridge to the connector created just now + timer:sleep(50), {ok, 201, Bridge} = request(post, uri(["bridges"]), ?MQTT_BRIDGE_INGRESS(ConnctorID)#{ <<"type">> => ?CONNECTR_TYPE, diff --git a/apps/emqx_prometheus/src/emqx_prometheus_api.erl b/apps/emqx_prometheus/src/emqx_prometheus_api.erl index 9e8904a4e..dda8bbd13 100644 --- a/apps/emqx_prometheus/src/emqx_prometheus_api.erl +++ b/apps/emqx_prometheus/src/emqx_prometheus_api.erl @@ -67,16 +67,22 @@ prometheus(get, _Params) -> {200, emqx:get_raw_config([<<"prometheus">>], #{})}; prometheus(put, #{body := Body}) -> - {ok, Config} = emqx:update_config([prometheus], Body), - case maps:get(<<"enable">>, Body) of - true -> - _ = emqx_prometheus_sup:stop_child(?APP), - emqx_prometheus_sup:start_child(?APP, maps:get(config, Config)); - false -> - _ = emqx_prometheus_sup:stop_child(?APP), - ok - end, - {200, emqx:get_raw_config([<<"prometheus">>], #{})}. + case emqx:update_config([prometheus], + Body, + #{rawconf_with_defaults => true, override_to => cluster}) of + {ok, #{raw_config := NewConfig, config := Config}} -> + case maps:get(<<"enable">>, Body, true) of + true -> + ok = emqx_prometheus_sup:stop_child(?APP), + ok = emqx_prometheus_sup:start_child(?APP, Config); + false -> + ok = emqx_prometheus_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. stats(get, #{headers := Headers}) -> Type = diff --git a/apps/emqx_statsd/src/emqx_statsd_api.erl b/apps/emqx_statsd/src/emqx_statsd_api.erl index ab9416266..c7ac94003 100644 --- a/apps/emqx_statsd/src/emqx_statsd_api.erl +++ b/apps/emqx_statsd/src/emqx_statsd_api.erl @@ -61,10 +61,8 @@ statsd(put, #{body := Body}) -> {ok, #{raw_config := NewConfig, config := Config}} -> ok = emqx_statsd_sup:ensure_child_stopped(?APP), case maps:get(<<"enable">>, Body) of - true -> - ok = emqx_statsd_sup:ensure_child_started(?APP, maps:get(config, Config)); - false -> - ok + true -> emqx_statsd_sup:ensure_child_started(?APP, Config); + false -> ok end, {200, NewConfig}; {error, Reason} ->