Skip to content

Commit 0998b15

Browse files
the-mikedavisdcorbacho
authored andcommitted
Filter init args from defaults in rabbit_prelaunch_conf
This change fixes a case in the `config_SUITE` for `rabbitmq_mqtt` which asserts that tuning mnesia environment values through `RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS` takes precedence over the default values set in `rabbit_prelaunch_conf:setup/1`. Application environment specified through CLI flags is inserted when the application is loaded and loading the application overwrites any existing values. The test passes on the main branch because the mnesia application is loaded after `rabbitmq_prelaunch` has fully started and `rabbit_prelaunch_conf:setup/1` has run. On the Khepri branch though, the khepri application is a dependency of `rabbitmq_prelaunch` and khepri loads the mnesia application on startup in `khepri_utils:init_list_of_modules_to_skip/0`. So the application environment specified through the `-mnesia key value` CLI arguments is inserted and then `rabbit_prelaunch_conf:setup/1` overwrites those values. To fix this, we filter the default application environment values for ones that have already been set through init flags by looking at `init:get_argument/1` for each application and filtering any keys explicitly set on the CLI.
1 parent bcc7cf3 commit 0998b15

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

deps/rabbit/apps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,31 @@ set_default_config() ->
136136
]}
137137
| OsirisConfig
138138
],
139-
apply_erlang_term_based_config(Config).
139+
%% Don't apply any defaults for values already set in the init flags.
140+
Config1 = filter_init_args(Config),
141+
apply_erlang_term_based_config(Config1).
142+
143+
filter_init_args(Config) ->
144+
lists:filtermap(
145+
fun({App, Vars}) ->
146+
case init:get_argument(App) of
147+
{ok, Args} ->
148+
Keys = [rabbit_data_coercion:to_atom(KeyName) ||
149+
[KeyName, _ValueExpr] <- Args],
150+
Vars1 = lists:filter(
151+
fun({Key, _Value}) ->
152+
not lists:member(Key, Keys)
153+
end, Vars),
154+
case Vars1 of
155+
[] ->
156+
false;
157+
_ ->
158+
{true, {App, Vars1}}
159+
end;
160+
error ->
161+
true
162+
end
163+
end, Config).
140164

141165
osiris_log(debug, Fmt, Args) ->
142166
?LOG_DEBUG(Fmt, Args,

0 commit comments

Comments
 (0)