Skip to content
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

Merged
merged 3 commits into from
Jan 25, 2018
Merged

Use gen_mod opts in MAM #1627

merged 3 commits into from
Jan 25, 2018

Conversation

kzemek
Copy link
Contributor

@kzemek kzemek commented Jan 8, 2018

This PR removes dynamically compiled mod_mam_prefs and mod_mam_muc_prefs modules in favor of fetching module options with ETS via gen_mod:get_module_opts() and then searching for the right option with lists:keyfind.

@kzemek kzemek added the WIP 🚧 label Jan 8, 2018
@kzemek kzemek force-pushed the mam_get_opt branch 3 times, most recently from 33a626f to 31b24aa Compare January 15, 2018 12:37
@kzemek
Copy link
Contributor Author

kzemek commented Jan 15, 2018

Before

screen shot 2018-01-15 at 14 56 15

After

screen shot 2018-01-15 at 14 56 32

@kzemek
Copy link
Contributor Author

kzemek commented Jan 15, 2018

Closeup on the TTD graph after the main (~2s) peak.

Before

screen shot 2018-01-15 at 14 57 57

After

screen shot 2018-01-15 at 14 58 03

@kzemek
Copy link
Contributor Author

kzemek commented Jan 15, 2018

Closeup on the TTD graph after the second (~80ms) peak.

Before

screen shot 2018-01-15 at 15 04 52

After

screen shot 2018-01-15 at 15 05 31

Copy link
Contributor

@arcusfelis arcusfelis left a 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().
Copy link
Contributor

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.

Copy link
Contributor

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]),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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) ->
Copy link
Contributor

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.

add_archived_element(Module, Host) ->
param(Module, Host, add_archived_element, false).

%% -spec add_stanzaid_element(Host :: ejabberd:lserver()) -> boolean().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec commented? why?


Format =
io_lib:format(
"-module(mod_mam_muc_params).~n"
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

extra_params_module(Host) ->
mod_mam_utils:param(?MODULE, Host, extra_lookup_params, undefined).

max_result_limit(Host) ->
Copy link
Contributor

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}) ->
Copy link
Contributor

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];
Copy link
Contributor

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.

@arcusfelis arcusfelis changed the title Use gen_mod opts in MAM. Use gen_mod opts in MAM Jan 24, 2018
Copy link
Member

@fenek fenek left a 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.


-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).
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omission

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) ->
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

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]).
Copy link
Member

@fenek fenek Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

@kzemek
Copy link
Contributor Author

kzemek commented Jan 25, 2018

Not all MAM modules have been moved to new folder. Please either move them or cancel the relocation in this PR.

@fenek done

@fenek
Copy link
Member

fenek commented Jan 25, 2018

@kzemek

Thanks! Only docs update remains. :)

@fenek
Copy link
Member

fenek commented Jan 25, 2018

Apologies, docs became outdated before this PR!

@fenek fenek added ready and removed WIP 🚧 labels Jan 25, 2018
@fenek fenek added this to the 3.0.0 milestone Jan 25, 2018
@fenek fenek merged commit b8326b8 into master Jan 25, 2018
@fenek fenek deleted the mam_get_opt branch January 25, 2018 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants