fix: keep precent range is 0%~100%
This commit is contained in:
parent
924ed06760
commit
11ee6abf02
|
@ -2496,7 +2496,11 @@ to_integer(Str) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
to_percent(Str) ->
|
to_percent(Str) ->
|
||||||
{ok, hocon_postprocess:percent(Str)}.
|
Percent = hocon_postprocess:percent(Str),
|
||||||
|
case is_number(Percent) andalso Percent >= 0.0 andalso Percent =< 1.0 of
|
||||||
|
true -> {ok, Percent};
|
||||||
|
false -> {error, Str}
|
||||||
|
end.
|
||||||
|
|
||||||
to_comma_separated_list(Str) ->
|
to_comma_separated_list(Str) ->
|
||||||
{ok, string:tokens(Str, ", ")}.
|
{ok, string:tokens(Str, ", ")}.
|
||||||
|
@ -2724,15 +2728,17 @@ check_cpu_watermark(Conf) ->
|
||||||
check_watermark("sysmon.os.cpu_low_watermark", "sysmon.os.cpu_high_watermark", Conf).
|
check_watermark("sysmon.os.cpu_low_watermark", "sysmon.os.cpu_high_watermark", Conf).
|
||||||
|
|
||||||
check_watermark(LowKey, HighKey, Conf) ->
|
check_watermark(LowKey, HighKey, Conf) ->
|
||||||
case hocon_maps:get(LowKey, Conf) of
|
case to_percent(hocon_maps:get(LowKey, Conf)) of
|
||||||
undefined ->
|
{error, undefined} ->
|
||||||
true;
|
true;
|
||||||
Low ->
|
{ok, Low} ->
|
||||||
High = hocon_maps:get(HighKey, Conf),
|
case to_percent(hocon_maps:get(HighKey, Conf)) of
|
||||||
case Low < High of
|
{ok, High} when High > Low -> true;
|
||||||
true -> true;
|
{ok, High} -> {bad_watermark, #{LowKey => Low, HighKey => High}};
|
||||||
false -> {bad_watermark, #{LowKey => Low, HighKey => High}}
|
{error, HighVal} -> {bad_watermark, #{HighKey => HighVal}}
|
||||||
end
|
end;
|
||||||
|
{error, Low} ->
|
||||||
|
{bad_watermark, #{LowKey => Low}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
str(A) when is_atom(A) ->
|
str(A) when is_atom(A) ->
|
||||||
|
|
|
@ -332,8 +332,8 @@ load_etc_config_file() ->
|
||||||
|
|
||||||
filter_readonly_config(Raw) ->
|
filter_readonly_config(Raw) ->
|
||||||
SchemaMod = emqx_conf:schema_module(),
|
SchemaMod = emqx_conf:schema_module(),
|
||||||
RawDefault = fill_defaults(Raw),
|
|
||||||
try
|
try
|
||||||
|
RawDefault = fill_defaults(Raw),
|
||||||
_ = emqx_config:check_config(SchemaMod, RawDefault),
|
_ = emqx_config:check_config(SchemaMod, RawDefault),
|
||||||
ReadOnlyKeys = [atom_to_binary(K) || K <- ?READONLY_KEYS],
|
ReadOnlyKeys = [atom_to_binary(K) || K <- ?READONLY_KEYS],
|
||||||
{ok, maps:without(ReadOnlyKeys, Raw)}
|
{ok, maps:without(ReadOnlyKeys, Raw)}
|
||||||
|
|
Loading…
Reference in New Issue