From d97d5b8af7cea8de4d3f3ce8cc91f9cba750fd3b Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Mon, 10 Jul 2023 14:31:25 -0300 Subject: [PATCH 1/2] ci(machine_boot): add ci check for missing reboot apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to avoid forgetting to add an application to `emqx_machine_boot:sorted_reboot_apps`, this script checks for any calls to `mria:create_table` in all EMQX applications and checks it against said function in `emqx_machine_boot`. Example run: ``` ͳ scripts/check_missing_reboot_apps.exs --profile emqx-enterprise Some applications are missing from `emqx_machine_boot:sorted_reboot_apps/0`! Missing applications: * emqx_durable_storage * emqx_ee_schema_registry Hint: maybe add them to `emqx_machine_boot:basic_reboot_apps_edition/1` Applications that call `mria:create_table` need to be added to that list; otherwise, when a node joins a cluster, it might lose tables. ``` Example problem: https://github.com/emqx/emqx/pull/11242 --- Makefile | 1 + scripts/check_missing_reboot_apps.exs | 62 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 scripts/check_missing_reboot_apps.exs diff --git a/Makefile b/Makefile index 8c5eb3048..df3d95f62 100644 --- a/Makefile +++ b/Makefile @@ -99,6 +99,7 @@ static_checks: @$(REBAR) as check do xref, dialyzer @if [ "$${PROFILE}" = 'emqx-enterprise' ]; then $(REBAR) ct --suite apps/emqx/test/emqx_static_checks --readable $(CT_READABLE); fi ./scripts/check-i18n-style.sh + ./scripts/check_missing_reboot_apps.exs --profile $(PROFILE) APPS=$(shell $(SCRIPTS)/find-apps.sh) diff --git a/scripts/check_missing_reboot_apps.exs b/scripts/check_missing_reboot_apps.exs new file mode 100755 index 000000000..9ea2c7925 --- /dev/null +++ b/scripts/check_missing_reboot_apps.exs @@ -0,0 +1,62 @@ +#!/usr/bin/env elixir + +{parsed, _argv, _errors = []} = + OptionParser.parse( + System.argv(), + strict: [profile: :string] + ) + +profile = Keyword.fetch!(parsed, :profile) + +:xref.start(:xref) +:xref.set_default(:xref, warnings: false) +rel_dir = '_build/#{profile}/lib/' +:xref.add_release(:xref, rel_dir) + +{:ok, calls} = :xref.q(:xref, '(App) (XC || "mria":"create_table"/".*")') + +emqx_calls = + calls + |> Enum.map(&elem(&1, 0)) + |> Enum.filter(&(to_string(&1) =~ "emqx_")) + |> MapSet.new() + +Path.wildcard(rel_dir ++ "*/ebin") +|> Enum.each(fn dir -> + dir + |> to_charlist() + |> :code.add_pathz() +end) + +Path.wildcard(rel_dir ++ "*") +|> Enum.map(fn dir -> + dir + |> Path.basename() + |> String.to_atom() + |> Application.load() +end) + +reboot_apps = :emqx_machine_boot.sorted_reboot_apps() |> MapSet.new() + +missing_reboot_apps = MapSet.difference(emqx_calls, reboot_apps) + +if MapSet.size(missing_reboot_apps) != 0 do + IO.puts( + :stderr, + IO.ANSI.format([ + :red, + "Some applications are missing from `emqx_machine_boot:sorted_reboot_apps/0`!\n", + "Missing applications:\n", + Enum.map(missing_reboot_apps, fn app -> + " * #{app}\n" + end), + "\n", + :green, + "Hint: maybe add them to `emqx_machine_boot:basic_reboot_apps_edition/1`\n", + "\n", + :yellow, + "Applications that call `mria:create_table` need to be added to that list;\n", + " otherwise, when a node joins a cluster, it might lose tables.\n" + ]) + ) +end From a53768c1d4627083a6d2ec993b0d712d3f094469 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Mon, 10 Jul 2023 14:39:44 -0300 Subject: [PATCH 2/2] fix(machine_boot): add `emqx_durable_storage` to reboot apps list --- apps/emqx_machine/src/emqx_machine_boot.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/emqx_machine/src/emqx_machine_boot.erl b/apps/emqx_machine/src/emqx_machine_boot.erl index b929f0d72..de3c67207 100644 --- a/apps/emqx_machine/src/emqx_machine_boot.erl +++ b/apps/emqx_machine/src/emqx_machine_boot.erl @@ -146,7 +146,8 @@ basic_reboot_apps() -> emqx_slow_subs, emqx_auto_subscribe, emqx_plugins, - emqx_psk + emqx_psk, + emqx_durable_storage ] ++ basic_reboot_apps_edition(emqx_release:edition()). basic_reboot_apps_edition(ce) ->