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

Prepare mod_disco for dynamic domains #3128

Merged
merged 33 commits into from
Jun 1, 2021
Merged

Prepare mod_disco for dynamic domains #3128

merged 33 commits into from
Jun 1, 2021

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented May 26, 2021

Untangle the service discovery logic according to the following rules:

  • No modules should call functions frommod_disco. In general, a module shouldn't call other extension modules unless they are connected with deps.
  • All extra features need to be added using the hook handlers, not with register_feature.
  • mod_disco shouldn't keep its state in ETS tables. There is no need for state when the hooks are used.

Common logic for handling the hooks is extracted to mongoose_disco. It has helpers for disco_local_features and disco_local_items right now.

A lot of new tests for service discovery are added as well.

To do:

  • Finish the rework, making disco_local_identity and disco_sm_* consistent with the functions already changed.
  • Support host types in mod_disco and mongoose_disco.

Both changes can be done in one PR.

@chrzaszcz chrzaszcz changed the title Do not register disco features in pubsub Prepare mod_disco for dynamic domains May 26, 2021
@chrzaszcz chrzaszcz marked this pull request as draft May 26, 2021 07:22
@codecov
Copy link

codecov bot commented May 26, 2021

Codecov Report

Merging #3128 (60a1d3a) into master (6433bca) will increase coverage by 0.05%.
The diff coverage is 91.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3128      +/-   ##
==========================================
+ Coverage   79.47%   79.52%   +0.05%     
==========================================
  Files         396      397       +1     
  Lines       32419    32325      -94     
==========================================
- Hits        25764    25708      -56     
+ Misses       6655     6617      -38     
Impacted Files Coverage Δ
src/event_pusher/mod_event_pusher_push.erl 94.56% <ø> (-0.12%) ⬇️
src/mod_time.erl 92.30% <ø> (-1.03%) ⬇️
src/mongoose_hooks.erl 92.81% <ø> (+0.60%) ⬆️
src/inbox/mod_inbox.erl 89.65% <50.00%> (-0.50%) ⬇️
src/mam/mod_mam.erl 88.93% <66.66%> (-0.65%) ⬇️
src/mod_auth_token.erl 81.45% <66.66%> (-0.55%) ⬇️
src/muc_light/mod_muc_light.erl 85.87% <66.66%> (+0.26%) ⬆️
src/mam/mod_mam_muc.erl 73.63% <75.00%> (-1.13%) ⬇️
src/mod_muc.erl 76.32% <80.00%> (+0.12%) ⬆️
src/mod_version.erl 90.47% <80.00%> (-3.97%) ⬇️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6433bca...60a1d3a. Read the comment docs.

@chrzaszcz chrzaszcz force-pushed the stateless-disco branch 13 times, most recently from 80160eb to 1bb13e5 Compare May 31, 2021 06:59
chrzaszcz added 14 commits May 31, 2021 09:03
It is added in a separate module to avoid calling mod_disco
  from other extension modules (module decoupling).
Also: add missing 'drop' condition to the AMP features.
They are already registered by ejabberd_local with the IQ handler.
It was already registered with the IQ handler.

There was a double bug as well that caused the tests to pass:
  - Wrong group name caused extdisco NOT to start
  - Wrong IQ handler module caused extdisco NOT to stop correctly
It was already registered with the IQ handler.
It was already registered with the IQ handler.
chrzaszcz added 17 commits May 31, 2021 09:10
It will be used by modules that need to get registered features
  and are not returning IQ errors.

Error handling can be changed in the future if needed.
Rework feature discovery to use the hooks for disco.
Additional features are added in place,
  as adding hooks brings no benefits in custom handlers.

Also:
  - Use the disco hook in mod_muc (required for mod_mam_muc features)
  - Move 'features_to_xml' to a helper module

Note:
  This commit breaks MUC Light tests because of the change
  in mod_mam_muc.
This commit fixes big tests.
Instead: register only the necessary IQ handler directly
  This makes the module responsible for its IQ handlers,
  as it should be.
Use the hooks instead.
New ETS table is used for efficient lookup of the NS list.
They are unused, hooks are used instead.
- Remove unnecessary error handling
    (no errors are returned form handlers anymore)
- Remove unnecessary support for feature tuples
    (no tuples are returned from handlers anymore)
- Add type specs
Update the interface and the helperes in mongoose_disco.
A map is used to guarantee unique JID's in the result.

This commit breaks tests as the modules need to be updated.
Also:
  - Fix a bug in get_module_opt
  - Fix the tests to detect the bug
Also:
  - use add_features as well
  - add missing disco tests
  - remove nested hook with only one handler

%adhoc fix
Change the test to check that the name is included.
This commit fixes the tests as all modules are reworked now.
@chrzaszcz chrzaszcz marked this pull request as ready for review May 31, 2021 07:53
Copy link
Collaborator

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

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

I like these changes, special thanks for SUITEs extension.

@@ -688,7 +695,8 @@ config_metrics(HostType) ->

-spec hooks(jid:lserver()) -> [ejabberd_hooks:hook()].
hooks(HostType) ->
[{user_send_packet, HostType, ?MODULE, user_send_packet, 60},
[{disco_local_features, HostType, ?MODULE, add_local_features, 99},
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe {disco_local_features, HostType, ?MODULE, disco_local_features, 99}

Copy link
Member Author

@chrzaszcz chrzaszcz Jun 1, 2021

Choose a reason for hiding this comment

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

This name would be consistent with the hook, but on the other hand add_local_features is more descriptive as the features are added to the list... Anyway, I can make the handler names more consistent in part 2 (there is more of them and they are mostly called add_local_features).

@DenysGonchar
Copy link
Collaborator

still LGTM

Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

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

Love these changes! 😄

gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_EXTDISCO, ?MODULE, process_iq, IQDisc).

-spec stop(jid:server()) -> ok.
stop(Host) ->
mod_disco:unregister_feature(Host, ?NS_EXTDISCO),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_EXTDISCO).
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_EXTDISCO).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good one!

@NelsonVides NelsonVides merged commit 44d63b9 into master Jun 1, 2021
@NelsonVides NelsonVides deleted the stateless-disco branch June 1, 2021 10:49
@Premwoik Premwoik added this to the 5.0.0 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants