fix(emqx_config): always check config files using richmap at emqx bootup
This commit is contained in:
parent
35032e1d44
commit
dc1ba51935
|
@ -195,14 +195,14 @@ init_load(SchemaModule, Conf) when is_list(Conf) orelse is_binary(Conf) ->
|
||||||
error(failed_to_load_hocon_conf)
|
error(failed_to_load_hocon_conf)
|
||||||
end;
|
end;
|
||||||
init_load(SchemaModule, RawRichConf) when is_map(RawRichConf) ->
|
init_load(SchemaModule, RawRichConf) when is_map(RawRichConf) ->
|
||||||
RawConf = hocon_schema:richmap_to_map(RawRichConf),
|
|
||||||
%% check with richmap for line numbers in error reports (future enhancement)
|
%% check with richmap for line numbers in error reports (future enhancement)
|
||||||
Opts = #{return_plain => true,
|
Opts = #{return_plain => true,
|
||||||
nullable => true
|
nullable => true
|
||||||
},
|
},
|
||||||
%% this call throws exception in case of check failure
|
%% this call throws exception in case of check failure
|
||||||
{_AppEnvs, CheckedConf} = check_config(SchemaModule, RawConf, Opts),
|
{_AppEnvs, CheckedConf} = hocon_schema:map_translate(SchemaModule, RawRichConf, Opts),
|
||||||
ok = save_to_config_map(CheckedConf, RawConf).
|
ok = save_to_config_map(emqx_map_lib:unsafe_atom_key_map(CheckedConf),
|
||||||
|
hocon_schema:richmap_to_map(RawRichConf)).
|
||||||
|
|
||||||
-spec check_config(module(), raw_config()) -> {AppEnvs, CheckedConf}
|
-spec check_config(module(), raw_config()) -> {AppEnvs, CheckedConf}
|
||||||
when AppEnvs :: app_envs(), CheckedConf :: config().
|
when AppEnvs :: app_envs(), CheckedConf :: config().
|
||||||
|
@ -211,11 +211,6 @@ check_config(SchemaModule, RawConf) ->
|
||||||
nullable => true,
|
nullable => true,
|
||||||
is_richmap => false
|
is_richmap => false
|
||||||
},
|
},
|
||||||
check_config(SchemaModule, RawConf, Opts).
|
|
||||||
|
|
||||||
-spec check_config(module(), raw_config(), map()) -> {AppEnvs, CheckedConf}
|
|
||||||
when AppEnvs :: app_envs(), CheckedConf :: config().
|
|
||||||
check_config(SchemaModule, RawConf, Opts) ->
|
|
||||||
{AppEnvs, CheckedConf} =
|
{AppEnvs, CheckedConf} =
|
||||||
hocon_schema:map_translate(SchemaModule, RawConf, Opts),
|
hocon_schema:map_translate(SchemaModule, RawConf, Opts),
|
||||||
Conf = maps:with(maps:keys(RawConf), CheckedConf),
|
Conf = maps:with(maps:keys(RawConf), CheckedConf),
|
||||||
|
@ -225,8 +220,8 @@ check_config(SchemaModule, RawConf, Opts) ->
|
||||||
read_override_conf() ->
|
read_override_conf() ->
|
||||||
load_hocon_file(emqx_override_conf_name(), map).
|
load_hocon_file(emqx_override_conf_name(), map).
|
||||||
|
|
||||||
-spec save_configs(app_envs(), raw_config(), config(), raw_config()) -> ok | {error, term()}.
|
-spec save_configs(app_envs(), config(), raw_config(), raw_config()) -> ok | {error, term()}.
|
||||||
save_configs(_AppEnvs, RawConf, Conf, OverrideConf) ->
|
save_configs(_AppEnvs, Conf, RawConf, OverrideConf) ->
|
||||||
%% We may need also support hot config update for the apps that use application envs.
|
%% We may need also support hot config update for the apps that use application envs.
|
||||||
%% If that is the case uncomment the following line to update the configs to app env
|
%% If that is the case uncomment the following line to update the configs to app env
|
||||||
%save_to_app_env(AppEnvs),
|
%save_to_app_env(AppEnvs),
|
||||||
|
|
|
@ -95,7 +95,7 @@ handle_call({change_config, SchemaModule, ConfKeyPath, UpdateReq}, _From,
|
||||||
Handlers, UpdateReq),
|
Handlers, UpdateReq),
|
||||||
{AppEnvs, CheckedConf} = emqx_config:check_config(SchemaModule, NewRawConf),
|
{AppEnvs, CheckedConf} = emqx_config:check_config(SchemaModule, NewRawConf),
|
||||||
do_post_config_update(ConfKeyPath, Handlers, OldConf, CheckedConf, UpdateReq),
|
do_post_config_update(ConfKeyPath, Handlers, OldConf, CheckedConf, UpdateReq),
|
||||||
emqx_config:save_configs(AppEnvs, NewRawConf, CheckedConf, OverrideConf)
|
emqx_config:save_configs(AppEnvs, CheckedConf, NewRawConf, OverrideConf)
|
||||||
catch Error:Reason:ST ->
|
catch Error:Reason:ST ->
|
||||||
?LOG(error, "change_config failed: ~p", [{Error, Reason, ST}]),
|
?LOG(error, "change_config failed: ~p", [{Error, Reason, ST}]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
|
|
Loading…
Reference in New Issue