Przeglądaj źródła

Merge remote-tracking branch 'origin/release-58' into sync-release-58-20240829-162145

thalesmg 1 rok temu
rodzic
commit
93be97546d

+ 5 - 3
apps/emqx_enterprise/src/emqx_enterprise_schema.erl

@@ -110,7 +110,7 @@ fields("log_audit_handler") ->
             )}
     ] ++ CommonConfs1;
 fields(Name) ->
-    ee_delegate(fields, ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES, Name).
+    ee_delegate(fields, ee_mods(), Name).
 
 translations() ->
     emqx_conf_schema:translations().
@@ -125,7 +125,7 @@ translation(Name) ->
 desc("log_audit_handler") ->
     ?DESC(emqx_conf_schema, "desc_audit_log_handler");
 desc(Name) ->
-    ee_delegate(desc, ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES, Name).
+    ee_delegate(desc, ee_mods(), Name).
 
 validations() ->
     emqx_conf_schema:validations() ++ emqx_license_schema:validations().
@@ -144,9 +144,11 @@ ee_roots() ->
         fun(Module) ->
             apply(Module, roots, [])
         end,
-        ?EE_SCHEMA_MODULES
+        ee_mods()
     ).
 
+ee_mods() -> ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES.
+
 ee_delegate(Method, [EEMod | EEMods], Name) ->
     case lists:member(Name, apply(EEMod, roots, [])) of
         true ->

+ 31 - 14
apps/emqx_enterprise/test/emqx_enterprise_schema_tests.erl

@@ -54,11 +54,11 @@ ensure_acl_conf() ->
 
 injected_roots_test() ->
     ExpectedRoots = lists:usort(ee_schema_roots()),
-    InjectedRoots = lists:usort([Root || {Root, _Sc} <- emqx_enterprise_schema:roots()]),
+    InjectedRoots = lists:usort(get_roots(emqx_enterprise_schema)),
     MissingRoots = ExpectedRoots -- InjectedRoots,
     ?assertEqual([], MissingRoots, #{
-        expected_roots => ExpectedRoots,
-        injected_roots => InjectedRoots,
+        missing => ExpectedRoots -- InjectedRoots,
+        unknown => InjectedRoots -- ExpectedRoots,
         hint =>
             <<
                 "maybe there's a missing schema module to be added to"
@@ -69,30 +69,47 @@ injected_roots_test() ->
     ok.
 
 ee_schema_roots() ->
+    #{ee_business_apps := Apps} = emqx_machine_boot:read_apps(),
+    lists:append([ee_schema_roots(atom_to_list(App)) || App <- Apps]).
+
+ee_schema_roots(AppName) ->
     lists:foldl(
         fun(Filepath, Acc) ->
-            ["apps", App | _] = filename:split(Filepath),
             Mod = module(Filepath),
-            case is_ee(App) andalso has_roots(Mod) of
+            case has_roots(Mod) of
                 true ->
-                    Roots = [Root || {Root, _Sc} <- Mod:roots()],
-                    Roots ++ Acc;
+                    get_roots(Mod) ++ Acc;
                 false ->
                     Acc
             end
         end,
         [],
-        filelib:wildcard("apps/*/src/**/*_schema.erl")
+        filelib:wildcard("apps/" ++ AppName ++ "/src/**/*_schema.erl")
     ).
 
-is_ee(App) ->
-    filelib:is_file(filename:join(["apps", App, "BSL.txt"])).
-
 module(Filepath) ->
     ModStr = filename:basename(Filepath, ".erl"),
     list_to_atom(ModStr).
 
+get_roots(Mod) ->
+    lists:map(
+        fun
+            ({Root, _Sc}) ->
+                Root;
+            (Root) when is_atom(Root) ->
+                Root
+        end,
+        Mod:roots()
+    ).
+
 has_roots(Mod) ->
-    _ = Mod:module_info(),
-    erlang:function_exported(Mod, roots, 0) andalso
-        Mod:roots() =/= [].
+    try
+        _ = Mod:module_info(),
+        erlang:function_exported(Mod, roots, 0) andalso
+            Mod:roots() =/= []
+    catch
+        error:undef ->
+            %% may have picked a module from an app that's not in the enterprise release.
+            ct:pal("module not found?  ~s", [Mod]),
+            false
+    end.

+ 13 - 9
apps/emqx_machine/src/emqx_machine_boot.erl

@@ -23,6 +23,7 @@
 -export([sorted_reboot_apps/0]).
 -export([start_autocluster/0]).
 -export([stop_port_apps/0]).
+-export([read_apps/0]).
 
 -dialyzer({no_match, [basic_reboot_apps/0]}).
 
@@ -134,15 +135,11 @@ reboot_apps() ->
     BaseRebootApps ++ ConfigApps.
 
 basic_reboot_apps() ->
-    PrivDir = code:priv_dir(emqx_machine),
-    RebootListPath = filename:join([PrivDir, "reboot_lists.eterm"]),
-    {ok, [
-        #{
-            common_business_apps := CommonBusinessApps,
-            ee_business_apps := EEBusinessApps,
-            ce_business_apps := CEBusinessApps
-        }
-    ]} = file:consult(RebootListPath),
+    #{
+        common_business_apps := CommonBusinessApps,
+        ee_business_apps := EEBusinessApps,
+        ce_business_apps := CEBusinessApps
+    } = read_apps(),
     EditionSpecificApps =
         case emqx_release:edition() of
             ee -> EEBusinessApps;
@@ -152,6 +149,13 @@ basic_reboot_apps() ->
     BusinessApps = CommonBusinessApps ++ EditionSpecificApps,
     ?BASIC_REBOOT_APPS ++ (BusinessApps -- excluded_apps()).
 
+%% @doc Read business apps belonging to the current profile/edition.
+read_apps() ->
+    PrivDir = code:priv_dir(emqx_machine),
+    RebootListPath = filename:join([PrivDir, "reboot_lists.eterm"]),
+    {ok, [Apps]} = file:consult(RebootListPath),
+    Apps.
+
 excluded_apps() ->
     %% Optional apps _should_ be (re)started automatically, but only
     %% when they are found in the release:

+ 1 - 1
apps/emqx_s3/src/emqx_s3.app.src

@@ -1,6 +1,6 @@
 {application, emqx_s3, [
     {description, "EMQX S3"},
-    {vsn, "5.1.1"},
+    {vsn, "5.1.2"},
     {modules, []},
     {registered, [emqx_s3_sup]},
     {applications, [

+ 1 - 1
apps/emqx_s3/src/emqx_s3_schema.erl

@@ -16,7 +16,7 @@
 -export([translate/2]).
 
 roots() ->
-    [s3].
+    [].
 
 namespace() -> "s3".