Browse Source

feat(schema): generate document when building the release

Zaiming Shi 4 years ago
parent
commit
01166a8bfb
3 changed files with 55 additions and 23 deletions
  1. 24 14
      apps/emqx/src/emqx_schema.erl
  2. 27 9
      apps/emqx_machine/src/emqx_machine_schema.erl
  3. 4 0
      build

+ 24 - 14
apps/emqx/src/emqx_schema.erl

@@ -76,31 +76,41 @@
 namespace() -> undefined.
 namespace() -> undefined.
 
 
 roots() ->
 roots() ->
-    [{"zones",
+    [ {"listeners",
+      sc(ref("listeners"),
+         #{ desc => "MQTT listeners identified by their protocol type and assigned names"
+          })
+     },
+     {"zones",
       sc(map("name", ref("zone")),
       sc(map("name", ref("zone")),
-         #{ desc => "A zone is a set of configs grouped by the zone `$name`. <br>"
-                    "The `$name` can be set to a listner's `zone` config for "
-                    "flexible configuration mapping. <br>"
-                    "NOTE: A builtin zone named `default` is auto created "
+         #{ desc => "A zone is a set of configs grouped by the zone <code>name</code>. <br>"
+                    "For flexible configuration mapping, the <code>name</code> "
+                    "can be set to a listener's <code>zone</code> config . <br>"
+                    "NOTE: A builtin zone named <code>default</code> is auto created "
                     "and can not be deleted."
                     "and can not be deleted."
           })},
           })},
-     "mqtt",
-     "flapping_detect",
+     {"mqtt",
+      sc(ref("mqtt"),
+         #{ desc => "Global MQTT configuration.<br>"
+                    "The configs here work as default values which can be overriden "
+                    "in <code>zone</code> configs"
+          })},
+     "rate_limit",
      "force_shutdown",
      "force_shutdown",
      "force_gc",
      "force_gc",
      "conn_congestion",
      "conn_congestion",
-     "rate_limit",
      "quota",
      "quota",
-     {"listeners",
-      sc(ref("listeners"),
-         #{ desc => "MQTT listeners identified by their protocol type and assigned names. "
-                    "The listeners enabled by default are named with 'default'"})
-     },
      "broker",
      "broker",
-     "plugins",
+     "plugins", %% TODO: move to emqx_machine_schema
      "stats",
      "stats",
      "sysmon",
      "sysmon",
      "alarm",
      "alarm",
+     {"authentication",
+      sc(hoconsc:lazy(hoconsc:array(map())),
+         #{ desc => "Default authentication configs for all MQTT listeners.<br>"
+                    "For per-listener overrides see <code>authentication</code> "
+                    "in listener configs"
+          })},
      {"authentication",
      {"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>"

+ 27 - 9
apps/emqx_machine/src/emqx_machine_schema.erl

@@ -59,13 +59,32 @@
 namespace() -> undefined.
 namespace() -> undefined.
 
 
 roots() ->
 roots() ->
-    %% This is a temp workaround to define part of authorization config
-    %% in emqx_schema and part of it in emqx_authz_schema but then
-    %% merged here in this module
-    %% The proper fix should be to make connection (channel, session) state
-    %% extendable by e.g. allow hooks be stateful.
-    ["cluster", "node", "rpc", "log", "authorization"] ++
-    lists:keydelete("authorization", 1, lists:flatmap(fun roots/1, ?MERGED_CONFIGS)).
+    lists:flatmap(fun roots/1, ?MERGED_CONFIGS) ++
+    [ {"node",
+       sc(hoconsc:ref("node"),
+          #{ desc => "Node name, cookie, config & data directories "
+                     "and the Eralng virtual machine (beam) boot parameters."
+           })}
+    , {"cluster",
+       sc(hoconsc:ref("cluster"),
+          #{ desc => "EMQ X nodes can form a cluster to scale up the total capacity.<br>"
+                     "Here holds the configs to instruct how individual nodes "
+                     "can discover each other, also the database replication "
+                     "role of this node etc."
+           })}
+    , {"log",
+       sc(hoconsc:ref("log"),
+          #{ desc => "Configure logging backends (to console or to file), "
+                     "and logging level for each logger backend."
+           })}
+    , {"rpc",
+       sc(hoconsc:ref("rpc"),
+          #{ desc => "EMQ X uses a library called <code>gen_rpc</code> for "
+                     "inter-broker RPCs.<br>Most of the time the default config "
+                     "should work, but in case you need to do performance "
+                     "fine-turning or experiment a bit, this is where to look."
+           })}
+    ].
 
 
 fields("cluster") ->
 fields("cluster") ->
     [ {"name",
     [ {"name",
@@ -738,5 +757,4 @@ to_atom(Bin) when is_binary(Bin) ->
     binary_to_atom(Bin, utf8).
     binary_to_atom(Bin, utf8).
 
 
 roots(Module) ->
 roots(Module) ->
-    lists:map(fun({_BinName, Root}) -> Root end,
-              maps:to_list(hocon_schema:roots(Module))).
+    lists:map(fun({_BinName, Root}) -> Root end, hocon_schema:roots(Module)).

+ 4 - 0
build

@@ -69,6 +69,10 @@ make_rel() {
         echo "gpb should not be included in the release"
         echo "gpb should not be included in the release"
         exit 1
         exit 1
     fi
     fi
+    local conf_doc
+    conf_doc="$(pwd)/_build/${PROFILE}/rel/emqx/etc/emqx-config-doc.html"
+    echo "===< Generating config document $conf_doc"
+	./_build/"$PROFILE"/rel/emqx/bin/emqx cold_eval "file:write_file('$conf_doc', hocon_schema_html:gen(emqx_machine_schema, \"EMQ X ${PKG_VSN}\"))"
 }
 }
 
 
 ## unzip previous version .zip files to _build/$PROFILE/rel/emqx/releases before making relup
 ## unzip previous version .zip files to _build/$PROFILE/rel/emqx/releases before making relup