Merge pull request #6616 from DDDHuang/emqx_prometheus_cluster

fix(prometheus): update config in cluster
This commit is contained in:
DDDHuang 2022-01-05 09:43:11 +08:00 committed by GitHub
commit d35b418ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 14 deletions

View File

@ -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,

View File

@ -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
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 ->
_ = emqx_prometheus_sup:stop_child(?APP),
emqx_prometheus_sup:start_child(?APP, maps:get(config, Config));
ok = emqx_prometheus_sup:stop_child(?APP),
ok = emqx_prometheus_sup:start_child(?APP, Config);
false ->
_ = emqx_prometheus_sup:stop_child(?APP),
ok
ok = emqx_prometheus_sup:stop_child(?APP)
end,
{200, emqx:get_raw_config([<<"prometheus">>], #{})}.
{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 =

View File

@ -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} ->