refactor(schema): reorder config root fields

so more important configs are ordered before less important
This commit is contained in:
Zaiming Shi 2021-09-08 11:01:07 +02:00
parent 01166a8bfb
commit 0b11ab2d59
2 changed files with 73 additions and 39 deletions

View File

@ -69,56 +69,82 @@
cipher/0, cipher/0,
comma_separated_atoms/0]). comma_separated_atoms/0]).
-export([namespace/0, roots/0, fields/1]). -export([namespace/0, roots/0, roots/1, fields/1]).
-export([conf_get/2, conf_get/3, keys/2, filter/1]). -export([conf_get/2, conf_get/3, keys/2, filter/1]).
-export([ssl/1]). -export([ssl/1]).
namespace() -> undefined. namespace() -> undefined.
roots() -> roots() ->
%% TODO change config importance to a field metadata
roots(high) ++ roots(medium) ++ roots(low).
roots(high) ->
[ {"listeners", [ {"listeners",
sc(ref("listeners"), sc(ref("listeners"),
#{ desc => "MQTT listeners identified by their protocol type and assigned names" #{ desc => "MQTT listeners identified by their protocol type and assigned names"
}) })
}, }
{"zones", , {"zones",
sc(map("name", ref("zone")), sc(map("name", ref("zone")),
#{ desc => "A zone is a set of configs grouped by the zone <code>name</code>. <br>" #{ desc => "A zone is a set of configs grouped by the zone <code>name</code>. <br>"
"For flexible configuration mapping, the <code>name</code> " "For flexible configuration mapping, the <code>name</code> "
"can be set to a listener's <code>zone</code> config . <br>" "can be set to a listener's <code>zone</code> config . <br>"
"NOTE: A builtin zone named <code>default</code> is auto created " "NOTE: A builtin zone named <code>default</code> is auto created "
"and can not be deleted." "and can not be deleted."
})}, })}
{"mqtt", , {"mqtt",
sc(ref("mqtt"), sc(ref("mqtt"),
#{ desc => "Global MQTT configuration.<br>" #{ desc => "Global MQTT configuration.<br>"
"The configs here work as default values which can be overriden " "The configs here work as default values which can be overriden "
"in <code>zone</code> configs" "in <code>zone</code> configs"
})}, })}
"rate_limit", , {"authentication",
"force_shutdown",
"force_gc",
"conn_congestion",
"quota",
"broker",
"plugins", %% TODO: move to emqx_machine_schema
"stats",
"sysmon",
"alarm",
{"authentication",
sc(hoconsc:lazy(hoconsc:array(map())), sc(hoconsc:lazy(hoconsc:array(map())),
#{ desc => "Default authentication configs for all MQTT listeners.<br>" #{ desc => "Default authentication configs for all MQTT listeners.<br>"
"For per-listener overrides see <code>authentication</code> " "For per-listener overrides see <code>authentication</code> "
"in listener configs" "in listener configs"
})}, })}
{"authentication", , {"authorization",
sc(hoconsc:lazy(hoconsc:array(map())), sc(ref("authorization"),
#{ desc => "Default authentication configs for all MQTT listeners.<br>" #{})}
"For per-listener overrides see <code>authentication</code> " ];
"in listener configs" roots(medium) ->
})}, [ {"broker",
"authorization", sc(ref("broker"),
"flapping_detect" #{})}
, {"rate_limit",
sc(ref("rate_limit"),
#{})}
, {"force_shutdown",
sc(ref("force_shutdown"),
#{})}
];
roots(low) ->
[ {"force_gc",
sc(ref("force_gc"),
#{})}
, {"conn_congestion",
sc(ref("conn_congestion"),
#{})}
, {"quota",
sc(ref("quota"),
#{})}
, {"plugins", %% TODO: move to emqx_machine_schema
sc(ref("plugins"),
#{})}
, {"stats",
sc(ref("stats"),
#{})}
, {"sysmon",
sc(ref("sysmon"),
#{})}
, {"alarm",
sc(ref("alarm"),
#{})}
, {"flapping_detect",
sc(ref("flapping_detect"),
#{})}
]. ].
fields("stats") -> fields("stats") ->
@ -140,8 +166,7 @@ fields("authorization") ->
, {"cache", , {"cache",
sc(ref(?MODULE, "cache"), sc(ref(?MODULE, "cache"),
#{ #{
}) })}
}
]; ];
fields("cache") -> fields("cache") ->

View File

@ -42,8 +42,7 @@
%% The list can not be made a dynamic read at run-time as it is used %% The list can not be made a dynamic read at run-time as it is used
%% by nodetool to generate app.<time>.config before EMQ X is started %% by nodetool to generate app.<time>.config before EMQ X is started
-define(MERGED_CONFIGS, -define(MERGED_CONFIGS,
[ emqx_schema [ emqx_bridge_schema
, emqx_bridge_schema
, emqx_retainer_schema , emqx_retainer_schema
, emqx_statsd_schema , emqx_statsd_schema
, emqx_authz_schema , emqx_authz_schema
@ -59,7 +58,8 @@
namespace() -> undefined. namespace() -> undefined.
roots() -> roots() ->
lists:flatmap(fun roots/1, ?MERGED_CONFIGS) ++ %% authorization configs are merged in THIS schema's "authorization" fields
lists:keydelete("authorization", 1, emqx_schema:roots(high)) ++
[ {"node", [ {"node",
sc(hoconsc:ref("node"), sc(hoconsc:ref("node"),
#{ desc => "Node name, cookie, config & data directories " #{ desc => "Node name, cookie, config & data directories "
@ -84,7 +84,16 @@ roots() ->
"should work, but in case you need to do performance " "should work, but in case you need to do performance "
"fine-turning or experiment a bit, this is where to look." "fine-turning or experiment a bit, this is where to look."
})} })}
]. , {"authorization",
sc(hoconsc:ref("authorization"),
#{ desc => "In EMQ X, MQTT client access control can be just a few "
"lines of text based rules, or delegated to an external "
"HTTP API, or base externa database query results."
})}
] ++
emqx_schema:roots(medium) ++
emqx_schema:roots(low) ++
lists:flatmap(fun roots/1, ?MERGED_CONFIGS).
fields("cluster") -> fields("cluster") ->
[ {"name", [ {"name",