-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use gen_mod opts in MAM #1627
Use gen_mod opts in MAM #1627
Conversation
33a626f
to
31b24aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added comments
src/gen_mod.erl
Outdated
@@ -302,6 +303,20 @@ set_module_opt(Host, Module, Opt, Value) -> | |||
{#ejabberd_module.opts, Updated}) | |||
end. | |||
|
|||
%% @doc Non-atomic! You have been warned. | |||
-spec set_module_opts(ejabberd:server(), module(), _Opts) -> boolean(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a new function.
Can we have a test that checks that the function works correctly?
Description is nice to have too, i.e. how it works, what is Opts and what is the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it replace all module opts or appends opts? - it's what I want to know from description
@@ -813,8 +815,7 @@ init_state(C, muc_light, Config) -> | |||
init_state(_C, prefs_cases, Config) -> | |||
Config; | |||
init_state(_C, policy_violation, Config) -> | |||
rpc_apply(mod_mam, set_params, | |||
[ [{max_result_limit, 5}] ]), | |||
rpc_apply(gen_mod, set_module_opt, [host(), mod_mam, max_result_limit, 5]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we put this call into a helper module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this to be explicit since there's some magic going on with external option setting.
src/mod_mam_utils.erl
Outdated
@@ -1062,3 +1066,30 @@ error_on_sql_error(_HostOrConn, _Query, Result) -> | |||
-spec wrapper_id() -> binary(). | |||
wrapper_id() -> | |||
uuid:uuid_to_string(uuid:get_v4(), binary_standard). | |||
|
|||
param(Module, Host, Opt, Default) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specs for each exported function.
src/mod_mam_utils.erl
Outdated
add_archived_element(Module, Host) -> | ||
param(Module, Host, add_archived_element, false). | ||
|
||
%% -spec add_stanzaid_element(Host :: ejabberd:lserver()) -> boolean(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec commented? why?
src/mod_mam_muc.erl
Outdated
|
||
Format = | ||
io_lib:format( | ||
"-module(mod_mam_muc_params).~n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the param module, because I can get all MAM related settings without thinking for default value of each option.
Can we have a function, that returns all possible MAM parameters with current values?
Something like
mod_mam:get_parameters(Host) ->
[{add_archived_element, false}, {default_result_limit, 50}, ....]
Same for mod_mam_muc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the param module, because I can get all MAM related settings without thinking for default value of each option.
True, that's something to improve.
Can we have a function, that returns all possible MAM parameters with current values?
What would be the point of such function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the point of such function?
For checking runtime configuration of the module.
For checking what options are available to override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to implement such functionality for MAM modules. If we want more explicit support for defaults, we should add it to gen_mod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously sans defaults, the runtime config should just be fetched with gen_mod:get_module_opts
?DEBUG("Incoming room packet.", []), | ||
IsArchivable = mod_mam_muc_params:is_archivable_message(?MODULE, incoming, Packet), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see now that we are using function that is configuration depended.
I would rather keep mod_mam_muc_params, by making a real mod_mam_muc_params module.
But of course, you can call gen_mod from inside this new module.
mod_mam_utils is supposed to have functions, that would always work the same predictable way, not depending on configuration parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see now that we are using function that is configuration depended.
If not religiously adhering to dependency injection by parameters, when can you see whether called function is or is not configuration dependent?
mod_mam_utils is supposed to have functions, that would always work the same predictable way, not depending on configuration parameters.
Why? I see mod_mam_utils
as the place for common utility functions of mod_mam
and mod_mam_muc
. These new functions are not even the first ones there to call gen_mod:get_module_opt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils - functions that do something.
params - functions that are allowed to override.
I don't like god-modules, we would end-up with another c2s or muc_room.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that this is a way for mod_mam_utils to become a god module, but I agree that a separation into mod_mam_params would be beneficial for code clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/mod_mam_muc.erl
Outdated
extra_params_module(Host) -> | ||
mod_mam_utils:param(?MODULE, Host, extra_lookup_params, undefined). | ||
|
||
max_result_limit(Host) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add specs for calls like this?
@@ -603,11 +603,14 @@ end_per_group(G, Config) when G == rsm_all; G == mam_purge; G == nostore; | |||
Config; | |||
end_per_group(muc_configurable_archiveid, Config) -> | |||
ParamsB = proplists:get_value(params_backup, Config), | |||
rpc_apply(mod_mam_muc, set_params, [ParamsB]), | |||
lists:foreach(fun({Key, Value}) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It screams to add gen_mod:set_module_opts/3 function.
init_per_group(configurable_archiveid, Config) -> | ||
[{params_backup, rpc_apply(mod_mam_params, params, [])} | Config]; | ||
[{params_backup, rpc_apply(gen_mod, get_module_opts, [host(), mod_mam])} | Config]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole backup mech should probably replaces with save/restore params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all MAM modules have been moved to new folder. Please either move them or cancel the relocation in this PR.
src/mam/mod_mam_params.erl
Outdated
|
||
-spec has_full_text_search(Module :: mod_mam | mod_mam_muc, Host :: ejabberd:server()) -> boolean(). | ||
has_full_text_search(Module, Host) -> | ||
gen_mod:get_module_opt(Host, Module, full_text_search, true). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why param/4
is not reused here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omission
src/mam/mod_mam_muc.erl
Outdated
mod_mam_muc_params:add_stanzaid_element(). | ||
-spec is_archivable_message(Host :: ejabberd:lserver(), Dir :: incoming | outgoing, | ||
Packet :: exml:element()) -> boolean(). | ||
is_archivable_message(Host, Dir, Packet) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be extracted to mod_mam_utils
? I believe it is a duplicate from mod_mam
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arcusfelis wanted to have param-driven functions out of mod_mam_utils
and I sort-of agree. Choosing parameters went to mod_mam_params
, actual logic went to mod_mam_utils
and a convenience shim connecting them went to mam modules. Duplication is a pity here, but it stems more from duplication of other parts of mod_mam
/mod_mam_muc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I understand. May be a subject of refactoring in the future then, maybe there will be a dedicated module for param-driven MAM utils.
src/mam/mod_mam_muc.erl
Outdated
is_archivable_message(Host, Dir, Packet) -> | ||
{M, F} = mod_mam_params:is_archivable_message_fun(?MODULE, Host), | ||
ArchiveChatMarkers = mod_mam_params:archive_chat_markers(?MODULE, Host), | ||
erlang:apply(M, F, [?MODULE, Dir, Packet, ArchiveChatMarkers]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change implies docs update:
https://github.com/esl/MongooseIM/blob/master/doc/modules/mod_mam.md#options
https://github.com/esl/MongooseIM/blob/master/doc/modules/mod_mam.md#is_archivable_message
https://github.com/esl/MongooseIM/blob/master/doc/modules/mod_mam.md#archiving-chat-markers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so? No logic has changed
@fenek done |
Thanks! Only docs update remains. :) |
Apologies, docs became outdated before this PR! |
This PR removes dynamically compiled
mod_mam_prefs
andmod_mam_muc_prefs
modules in favor of fetching module options with ETS viagen_mod:get_module_opts()
and then searching for the right option withlists:keyfind
.