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

adding mongoose_subdomain_core #3116

Merged
merged 11 commits into from
May 14, 2021
Merged

adding mongoose_subdomain_core #3116

merged 11 commits into from
May 14, 2021

Conversation

DenysGonchar
Copy link
Collaborator

@DenysGonchar DenysGonchar commented May 11, 2021

Initial implementation of subdomains management subsystem.
Note that it detects but doesn't solve subdomains or domain/subdomain names collisions:
for more information see comment in the corresponding test cases:

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #3116 (3e0a1a8) into master (23a8e60) will increase coverage by 0.01%.
The diff coverage is 85.98%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3116      +/-   ##
==========================================
+ Coverage   79.23%   79.24%   +0.01%     
==========================================
  Files         388      389       +1     
  Lines       31850    31957     +107     
==========================================
+ Hits        25235    25325      +90     
- Misses       6615     6632      +17     
Impacted Files Coverage Δ
src/mongoose_hooks.erl 92.35% <0.00%> (-0.60%) ⬇️
src/domain/mongoose_subdomain_core.erl 86.27% <86.27%> (ø)
src/domain/mongoose_domain_core.erl 88.09% <100.00%> (+0.29%) ⬆️
src/domain/mongoose_subdomain_utils.erl 100.00% <100.00%> (ø)
src/ejabberd.erl 45.00% <0.00%> (-10.00%) ⬇️
...c/global_distrib/mod_global_distrib_server_mgr.erl 75.14% <0.00%> (-2.26%) ⬇️
src/ejabberd_c2s.erl 89.43% <0.00%> (+0.14%) ⬆️
src/mod_muc_log.erl 77.97% <0.00%> (+0.25%) ⬆️
src/ejabberd_sm.erl 82.71% <0.00%> (+0.33%) ⬆️

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 23a8e60...3e0a1a8. Read the comment docs.

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

The general idea looks good, I like the systematic way of handling the collisions.
I agree that we don't need to have active collision prevention at the moment.

There are quite a lot of comments, but most of them are minor.

src/domain/mongoose_subdomain_core.erl Show resolved Hide resolved
src/domain/mongoose_subdomain_core.erl Outdated Show resolved Hide resolved
src/domain/mongoose_subdomain_utils.erl Outdated Show resolved Hide resolved
src/domain/mongoose_subdomain_utils.erl Outdated Show resolved Hide resolved
-type subdomain_item() :: #subdomain_item{}.

%% corresponds to the fields in #subdomain_item{} record
-type subdomain_info() :: #{host_type := host_type(),
Copy link
Member

@chrzaszcz chrzaszcz May 12, 2021

Choose a reason for hiding this comment

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

The two types: record and map look a bit odd to me. I understand that the record is used for ETS operations and the map is easier to use in the tests but... I would only have the record here.

Applying the Occam's razor makes me think that having only one type here would have the following benefits:

  • Easier to learn how it works
  • Easier to debug - one data structure is easier to follow
  • Less code, no unnecessary conversions
  • Easier to maintain in case the type needs to be extended

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't want to expose this record to the external code (not in this PR), it's not only about tests. I would say it was done not for the tests at all.

Copy link
Member

@chrzaszcz chrzaszcz May 12, 2021

Choose a reason for hiding this comment

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

Not exposing the record beyond a a module would make more sense to me if there were a lot of data in the record taht we could hide. Otherwise it's just a lightweight and efficient data structure that you can just use directly instead of converting to a new structure that does not offer anything extra.

I don't want to start a long discussion here... it can stay as it is, in my view it's just unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep it as it is for now.

%%------------------------------------------
?assertEqual(ok, mongoose_subdomain_core:register_subdomain(?DYNAMIC_HOST_TYPE1,
Pattern1, Handler)),
mongoose_domain_core:insert(<<"example.net">>, ?DYNAMIC_HOST_TYPE1, dummy_src),
Copy link
Member

Choose a reason for hiding this comment

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

How about checking return values in these tests? Would it be too verbose?

test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
src/mongoose_hooks.erl Outdated Show resolved Hide resolved
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.

looks ok

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

Thanks for all the work! It looks good to me, only minor comments, you can address them if you want to.

-type subdomain_item() :: #subdomain_item{}.

%% corresponds to the fields in #subdomain_item{} record
-type subdomain_info() :: #{host_type := host_type(),
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep it as it is for now.

test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
test/mongoose_subdomain_core_SUITE.erl Outdated Show resolved Hide resolved
tested with the following command:
    ./rebar3 ct --suite mongoose_subdomain_core_SUITE  --repeat 100
@chrzaszcz chrzaszcz merged commit 4a31a98 into master May 14, 2021
@chrzaszcz chrzaszcz deleted the multi-tenancy-subdomains branch May 14, 2021 07:45
@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.

4 participants