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

Mongoose service #1792

Merged
merged 15 commits into from
Apr 17, 2018
Merged

Mongoose service #1792

merged 15 commits into from
Apr 17, 2018

Conversation

bartekgorny
Copy link
Collaborator

This PR addresses feature #18914

Introduces mongoose_service behaviour, with dependencies between services and modules requiring certain services.

There will be another PR with slightly modified interface.

@codecov
Copy link

codecov bot commented Apr 6, 2018

Codecov Report

Merging #1792 into master will decrease coverage by 0.13%.
The diff coverage is 76.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1792      +/-   ##
==========================================
- Coverage   74.48%   74.35%   -0.14%     
==========================================
  Files         290      291       +1     
  Lines       26996    27061      +65     
==========================================
+ Hits        20109    20122      +13     
- Misses       6887     6939      +52
Impacted Files Coverage Δ
src/service_admin_extra_stats.erl 84.61% <ø> (ø)
src/service_admin_extra_srg.erl 0% <ø> (ø)
src/service_admin_extra_last.erl 66.66% <ø> (ø)
src/service_admin_extra_stanza.erl 96.66% <ø> (ø)
src/service_admin_extra_roster.erl 88.19% <ø> (ø)
src/service_admin_extra.erl 100% <ø> (ø)
src/service_admin_extra_vcard.erl 92.06% <ø> (ø)
src/service_admin_extra_node.erl 20% <ø> (ø)
src/service_admin_extra_private.erl 81.48% <ø> (ø)
src/service_admin_extra_sessions.erl 86.79% <ø> (ø)
... and 25 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 497ede9...d9daa35. Read the comment docs.

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.

  1. Missing documentation
  2. I'd transform logs into ?[level]("event='something_happened',...", [...]) format

%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongoose_service_big_SUITE).
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate in old directory.

@@ -27,9 +27,9 @@
-module(mod_admin_extra).
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be renamed, so it would be clear it's no longer a module. E.g. service_admin_extra or srv_admin_extra

%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongoose_service_big_SUITE).
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we need such suite. If ejabberdctl_SUITE works, then admin extra as a service works. For mongoose_service alone there is a dedicated small test.


-spec loaded_services_with_opts() -> [{service(), options()}].
loaded_services_with_opts() ->
[Z || [Z] <- ets:match(?ETAB, '$1')].
Copy link
Member

Choose a reason for hiding this comment

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

ets:tab2list?

src/gen_mod.erl Outdated
@@ -115,6 +116,7 @@ start_module_for_host(Host, Module, Opts0) ->
Opts = clear_opts(Module, Opts0),
set_module_opts_mnesia(Host, Module, Opts),
ets:insert(ejabberd_modules, #ejabberd_module{module_host = {Module, Host}, opts = Opts}),
lists:map(fun mongoose_service:assert_loaded/1, get_required_services(Host, Module, Opts)),
Copy link
Member

Choose a reason for hiding this comment

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

I'd put it inside try..catch - nicer error handling.

@fenek fenek added the WIP 🚧 label Apr 10, 2018
@fenek fenek added this to the 3.0.0 milestone Apr 10, 2018
@bartekgorny bartekgorny force-pushed the mongoose-service branch 3 times, most recently from 9b74608 to 668054e Compare April 12, 2018 15:19
### Module Description
This module significantly extends `mongooseimctl` script capabilities. New functionalities appear as additional commands. For detailed description, just run `mongooseimctl` script with no parameters.
Some functionalities in MongooseIM are provided by "services".
A service is similar to a module, only it is started only globally, while a module can be global or host-specific.
Copy link
Member

Choose a reason for hiding this comment

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

Module may have global configuration.

A wide range of options includes authentication, privacy, storage, backend integration and mobile optimisations.
See '[Extension Modules](../advanced-configuration/Modules.md)' for a full list.

Modules can be configured and started either globally (for all virutal hosts served by the instance) or individually for each host.
Copy link
Member

Choose a reason for hiding this comment

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

Modules can be configured and started either for all virtual hosts served by the instance or with individual configuration for only some of them.


Modules can be configured and started either globally (for all virutal hosts served by the instance) or individually for each host.
Modules may include dependencies on services and on other modules.
If a module depends on other modules, required modules are started automatically.
Copy link
Member

Choose a reason for hiding this comment

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

... started automatically with a default configuration provided by dependent module.


Some functionalities which are not related to virtual hosts but rather are provided for the whole instance or for modules started for various hosts are provided by "services".
Services are configured globally launched on startup, before modules, so that dependencies are satisfied.
A service can require other services to be operational; required services are started automatically.
Copy link
Member

Choose a reason for hiding this comment

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

Wat? TBH I haven't noticed it in the code. Why should service be started as a dependency (with empty config!) by another service but we deny the same for modules?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The service will not be started with empty config, it will be started with the config from the config file. Since services are singletond you cant give your own config at runtime. We do this for convenience, so that you can start a service without complete knowledge about the whole dependency tree.why we do not allow modules start required services lm not sure, it was decided on tech meeting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually the main advantage of it is that you can define services in the config file in any order and they will resolve their dependencies themselves.

catch
Class:Reason ->
ets:delete(?ETAB, Service),
Template = "event=service_startup,status=error,service=~p,options=~p,class=~p,reason=~p~n~p",

Choose a reason for hiding this comment

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

According to Elvis:

Line 131 is too long: Template = "event=service_startup,status=error,service=~p,options=~p,class=p,reason=pnp",.

@esl esl deleted a comment from gadgetci Apr 16, 2018
### Module Description
This module significantly extends `mongooseimctl` script capabilities. New functionalities appear as additional commands. For detailed description, just run `mongooseimctl` script with no parameters.
Some functionalities in MongooseIM are provided by "services".
A service is similar to a module, only it is started only once with a global configuration, while a module is started for every virtual host and may have global or host-specific configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

A service is similar to a module, but while a module is started for every virtual host and may have global or host-specific configuration, a service is started only once with global configuration.

## Service list

As of version 2.2, only one module is a "service provider".
Over time, part of modules which are not host-specific will be refactored to be services.
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually the modules which are not host-specific will be refactored to be services.
?


Modules can be configured and started either for all virutal hosts served by the instance or with individual configuration for only some of them.
Modules may include dependencies on services and on other modules.
If a module depends on other modules, required modules are started automatically with configuration provided by the dependent module..
Copy link
Contributor

Choose a reason for hiding this comment

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

If a module depends on other modules, required modules are started automatically with configuration provided by the dependent module.


### Services

Some functionalities which are not related to virtual hosts but rather are provided for the whole instance or for modules started for various hosts are provided by "services".
Copy link
Contributor

Choose a reason for hiding this comment

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

Services provide certain fuctionalities not specific to virtual hosts but rather applied to the whole instance or to modules started for various hosts.
?

### Services

Some functionalities which are not related to virtual hosts but rather are provided for the whole instance or for modules started for various hosts are provided by "services".
Services are configured globally launched on startup, before modules, so that dependencies are satisfied.
Copy link
Contributor

Choose a reason for hiding this comment

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

They are configured globally and launched on startup, before modules, so that dependencies are satisfied.

@fenek fenek merged commit 4f76cbc into master Apr 17, 2018
@fenek fenek deleted the mongoose-service branch April 17, 2018 09:46
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.

4 participants