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
|
%% ... and a MQTT bridge, using POST
|
||||||
%% we bind this bridge to the connector created just now
|
%% we bind this bridge to the connector created just now
|
||||||
|
timer:sleep(50),
|
||||||
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
{ok, 201, Bridge} = request(post, uri(["bridges"]),
|
||||||
?MQTT_BRIDGE_INGRESS(ConnctorID)#{
|
?MQTT_BRIDGE_INGRESS(ConnctorID)#{
|
||||||
<<"type">> => ?CONNECTR_TYPE,
|
<<"type">> => ?CONNECTR_TYPE,
|
||||||
|
|
|
@ -67,16 +67,22 @@ prometheus(get, _Params) ->
|
||||||
{200, emqx:get_raw_config([<<"prometheus">>], #{})};
|
{200, emqx:get_raw_config([<<"prometheus">>], #{})};
|
||||||
|
|
||||||
prometheus(put, #{body := Body}) ->
|
prometheus(put, #{body := Body}) ->
|
||||||
{ok, Config} = emqx:update_config([prometheus], Body),
|
case emqx:update_config([prometheus],
|
||||||
case maps:get(<<"enable">>, Body) of
|
Body,
|
||||||
|
#{rawconf_with_defaults => true, override_to => cluster}) of
|
||||||
|
{ok, #{raw_config := NewConfig, config := Config}} ->
|
||||||
|
case maps:get(<<"enable">>, Body, true) of
|
||||||
true ->
|
true ->
|
||||||
_ = emqx_prometheus_sup:stop_child(?APP),
|
ok = emqx_prometheus_sup:stop_child(?APP),
|
||||||
emqx_prometheus_sup:start_child(?APP, maps:get(config, Config));
|
ok = emqx_prometheus_sup:start_child(?APP, Config);
|
||||||
false ->
|
false ->
|
||||||
_ = emqx_prometheus_sup:stop_child(?APP),
|
ok = emqx_prometheus_sup:stop_child(?APP)
|
||||||
ok
|
|
||||||
end,
|
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}) ->
|
stats(get, #{headers := Headers}) ->
|
||||||
Type =
|
Type =
|
||||||
|
|
|
@ -61,10 +61,8 @@ statsd(put, #{body := Body}) ->
|
||||||
{ok, #{raw_config := NewConfig, config := Config}} ->
|
{ok, #{raw_config := NewConfig, config := Config}} ->
|
||||||
ok = emqx_statsd_sup:ensure_child_stopped(?APP),
|
ok = emqx_statsd_sup:ensure_child_stopped(?APP),
|
||||||
case maps:get(<<"enable">>, Body) of
|
case maps:get(<<"enable">>, Body) of
|
||||||
true ->
|
true -> emqx_statsd_sup:ensure_child_started(?APP, Config);
|
||||||
ok = emqx_statsd_sup:ensure_child_started(?APP, maps:get(config, Config));
|
false -> ok
|
||||||
false ->
|
|
||||||
ok
|
|
||||||
end,
|
end,
|
||||||
{200, NewConfig};
|
{200, NewConfig};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
|
Loading…
Reference in New Issue