Merge pull request #6616 from DDDHuang/emqx_prometheus_cluster
fix(prometheus): update config in cluster
This commit is contained in:
commit
d35b418ed6
|
@ -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,
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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} ->
|
||||
|
|
Loading…
Reference in New Issue