Skip to content

Commit dc4f8cd

Browse files
committed
Use prelaunch context first and fallback to app env. variable
[Why] We use the application environment as some kind of "cache" for the configuration parameters and some system environment variables. However, because we don't use `sys.config`, the application environment could be reset to its default/empty state if we were to use Erlang releases. [How] For values that may come from the system environment, we use the prelaunch context instead. V2: If the value is unavailable from the context, we fall back to the application environment variable. We still need this for the CLI and some testsuites.
1 parent fe09fa2 commit dc4f8cd

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

deps/rabbit/src/rabbit.erl

+7-2
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,13 @@ get_default_data_param(Param) ->
11751175
%% </ul>
11761176

11771177
data_dir() ->
1178-
{ok, DataDir} = application:get_env(rabbit, data_dir),
1179-
DataDir.
1178+
case rabbit_prelaunch:get_context() of
1179+
#{data_dir := DataDir} ->
1180+
DataDir;
1181+
_ ->
1182+
{ok, DataDir} = application:get_env(rabbit, data_dir),
1183+
DataDir
1184+
end.
11801185

11811186
%%---------------------------------------------------------------------------
11821187
%% logging

deps/rabbit/src/rabbit_feature_flags.erl

+8-3
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,14 @@ delete_enabled_feature_flags_list_file() ->
11641164
%% @returns the path to the file.
11651165

11661166
enabled_feature_flags_list_file() ->
1167-
case application:get_env(rabbit, feature_flags_file) of
1168-
{ok, Val} -> Val;
1169-
undefined -> throw(feature_flags_file_not_set)
1167+
case rabbit_prelaunch:get_context() of
1168+
#{feature_flags_file := File} ->
1169+
File;
1170+
_ ->
1171+
case application:get_env(rabbit, feature_flags_file) of
1172+
{ok, Val} -> Val;
1173+
undefined -> throw(feature_flags_file_not_set)
1174+
end
11701175
end.
11711176

11721177
copy_feature_states_after_reset(RemoteNode) ->

deps/rabbit/src/rabbit_ff_controller.erl

+4-2
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,10 @@ get_forced_feature_flag_names_from_env() ->
670670
%% @private
671671

672672
get_forced_feature_flag_names_from_config() ->
673-
Value = application:get_env(
674-
rabbit, forced_feature_flags_on_init, undefined),
673+
Value = maps:get(
674+
forced_feature_flags_on_init,
675+
rabbit_prelaunch:get_context(),
676+
undefined),
675677
case Value of
676678
undefined ->
677679
Value;

deps/rabbit/src/rabbit_plugins.erl

+29-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ensure(FileJustChanged) ->
3232
end.
3333

3434
ensure1(FileJustChanged0) ->
35-
{ok, OurFile0} = application:get_env(rabbit, enabled_plugins_file),
35+
OurFile0 = enabled_plugins_file(),
3636
FileJustChanged = filename:nativename(FileJustChanged0),
3737
OurFile = filename:nativename(OurFile0),
3838
case OurFile of
@@ -72,39 +72,51 @@ ensure1(FileJustChanged0) ->
7272

7373
-spec plugins_expand_dir() -> file:filename().
7474
plugins_expand_dir() ->
75-
case application:get_env(rabbit, plugins_expand_dir) of
76-
{ok, ExpandDir} ->
75+
case rabbit_prelaunch:get_context() of
76+
#{plugins_expand_dir := ExpandDir} ->
7777
ExpandDir;
7878
_ ->
79-
filename:join([rabbit:data_dir(), "plugins_expand_dir"])
79+
case application:get_env(rabbit, plugins_expand_dir) of
80+
{ok, ExpandDir} ->
81+
ExpandDir;
82+
undefined ->
83+
filename:join([rabbit:data_dir(), "plugins_expand_dir"])
84+
end
8085
end.
8186

8287
-spec plugins_dir() -> file:filename().
8388
plugins_dir() ->
84-
case application:get_env(rabbit, plugins_dir) of
85-
{ok, PluginsDistDir} ->
89+
case rabbit_prelaunch:get_context() of
90+
#{plugins_path := PluginsDistDir} ->
8691
PluginsDistDir;
8792
_ ->
88-
filename:join([rabbit:data_dir(), "plugins_dir_stub"])
93+
case application:get_env(rabbit, plugins_dir) of
94+
{ok, PluginsDistDir} ->
95+
PluginsDistDir;
96+
undefined ->
97+
filename:join([rabbit:data_dir(), "plugins_dir_stub"])
98+
end
8999
end.
90100

91101
-spec enabled_plugins_file() -> file:filename().
92102
enabled_plugins_file() ->
93-
case application:get_env(rabbit, enabled_plugins_file) of
94-
{ok, Val} ->
95-
Val;
103+
case rabbit_prelaunch:get_context() of
104+
#{enabled_plugins_file := File} ->
105+
File;
96106
_ ->
97-
filename:join([rabbit:data_dir(), "enabled_plugins"])
107+
case application:get_env(rabbit, enabled_plugins_file) of
108+
{ok, File} ->
109+
File;
110+
undefined ->
111+
filename:join([rabbit:data_dir(), "enabled_plugins"])
112+
113+
end
98114
end.
99115

100116
-spec enabled_plugins() -> [atom()].
101117
enabled_plugins() ->
102-
case application:get_env(rabbit, enabled_plugins_file) of
103-
{ok, EnabledFile} ->
104-
read_enabled(EnabledFile);
105-
_ ->
106-
[]
107-
end.
118+
EnabledFile = enabled_plugins_file(),
119+
read_enabled(EnabledFile).
108120

109121
%% @doc Prepares the file system and installs all enabled plugins.
110122

0 commit comments

Comments
 (0)