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

Inbox extensions #3067

Merged
merged 64 commits into from
Apr 9, 2021
Merged

Inbox extensions #3067

merged 64 commits into from
Apr 9, 2021

Conversation

NelsonVides
Copy link
Collaborator

@NelsonVides NelsonVides commented Mar 31, 2021

This PR contains a bunch of commits extracted as-is from beekeeper's fork. They implement extended functionality, best explained in the documentation prepared for them at Beekeeper inbox extensions.pdf (markdown made a pdf).

They implement extensions to set inbox entries as archived, muted (and until), or read, being able to set all of them as either value.

On top of their work, I've carried out a big merge of modules, and also reworked the internals on my own effort, to reduce stringprepping, timestamps, conventions with correctly treating jids, reworking all the docs, and what not.

What is missing:

  • fix details for mysql and mssql, see CI failing
  • add a note in migrations for the new columns in the DB
  • prepared queries for the whole thing This is to be done in a separate PR.

Details on the commits donated:
Rebasing on esl/master from

*   commit 135fec226fa3be355dcac6be5536821c78b34bb4
|\  Merge: eb561a9dd 3217ef6b4
| | Author: Paweł Chrząszcz <pawel.chrzaszcz@erlang-solutions.com>
| | Date:   Tue Mar 2 09:34:53 2021 +0100
| | 
| |     Merge pull request #3018 from esl/mongoose_session
| |     
| |     Mongoose session

these are the commits that were done on the bkpr fork.

* commit 5185b5a7685c1b0cf3b678723222d53e38539c6e (HEAD -> bkpr_inbox_extensions, origin/bkpr_inbox_extensions)
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 10 11:25:25 2021 +0100
| 
|     [inbox] add test for timestamp keeping
| 
* commit 6cf6adb5685f7bcc458440f2e5f1f980d3952794
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 10 11:08:47 2021 +0100
| 
|     [inbox] leave timestamp when setting properties
| 
* commit b3dee1beff737be349c5b4f1d7004809ef647d13
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Mon Mar 8 11:52:20 2021 +0100
| 
|     [test] second page is possible
|     
|     Also rework a bit how other tests were done
| 
* commit 4a803e08db434fc718d5645134f33ec2b4428d45
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 18:39:39 2021 +0100
| 
|     [src] implement pagination
| 
* commit 9f973e7ddd96173f945254499791d63694db2bf7
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 18:39:11 2021 +0100
| 
|     [test] pagination
| 
* commit 6baef7a26132f3d1b1a98f41d52b9e26e7a3a5a3
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 18:36:20 2021 +0100
| 
|     [doc] Limiting query by RSM max parameter
| 
* commit b873dbace0f31101032df9feee7bb2f1ce6754ac
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 18:35:12 2021 +0100
| 
|     [rdbms query] Add limit to the pgsql query
| 
* commit 691e01b4fab1845d58845e9160a73798edb184f7
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 15:48:15 2021 +0100
| 
|     [review] apply changes as requested
| 
* commit b475d1263e4f21e292a8e1d22ab491661c7acfe4
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Thu Mar 4 10:49:16 2021 +0100
| 
|     [src] Simplify the case where mute=0
| 
* commit bdf8b7c4acce812e9fdf9ad5c7128fd638158623
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 19:16:28 2021 +0100
| 
|     [src] mod_inbox get-form reports archive field
| 
* commit 07c16f4eb766f896c9b0f233d4a380abda552bff
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 18:49:34 2021 +0100
| 
|     [src] mod_inbox_bkpr
|     
|     Here it is, all of the actions requested by Beekeeper, implemented.
| 
* commit ad206a022222253e13199b59e09d73dcff020589
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 14:20:39 2021 +0100
| 
|     [src] add inbox storage filtering based on the extension
|     
|     The extensions might send more messages, with certain attributes,
|     that are not desired to be stored on inbox, so the extension needs to
|     add more filtering for this.
| 
* commit 2061b8165daf0fdd47cc28287505058005044e8e
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 14:02:11 2021 +0100
| 
|     [src] mod_inbox forwards other filter flags
|     
|     This way we can add more flags to the extensions without touching
|     mod_inbox in the future. The only problem was in the type for the
|     parameters, where it wasn't accepting the new flags without adding
|     them there.
| 
* commit 82c88da7853ba65ca1577f89293deabfbcba5f0d
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 13:47:18 2021 +0100
| 
|     [src] mod_inbox deals with the new return values
|     
|     As before, mod_inbox tries not to care what are these extra values being
|     processed, and simply takes them and forwards them to mod_inbox_bkpr for
|     processing.
| 
* commit 6e0bc09e7154c43e70598e10c9a35c6e9a7d7bfe
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 13:03:18 2021 +0100
| 
|     [src] Redirect new IQs from main inbox to bkpr inbox
| 
* commit 331c1ebfd9c5dd9f2ebb5d4eba3fa1d55b4b15d5
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 12:38:45 2021 +0100
| 
|     [src] Query extensions in base mod_inbox_rdbms
|     
|     There's a bunch of hardcoded calls to mod_inbox_bkpr, for selecting more
|     fields, filtering from more patterns, and returning more values, that I
|     tried to keep out of the base mod_inbox_rdbms, that might suffer
|     modifications in open source, keeping all bkpr logic just in
|     mod_inbox_bkpr.
|     
|     The most challenging part is the tuple returned from the sql driver,
|     there's no way to pattern-match a variable-length tuple and tell the
|     extensions to parse all the suffix, I had to change the tuple size and
|     hardcode the extended fields.
|     
|     I considered doing a tuple_to_list and pattern-match on that, but it
|     would be a performance overkill, I don't think we need to go that far.
|     
|     Note that, as only the extension knows how the fields were requested,
|     only the extension knows how to process them and in which order.
| 
* commit 6205f41dd988b9b7073c61977c8f183ff8697ca2
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 12:08:53 2021 +0100
| 
|     [rdbms query] Reset archive flag on new message
|     
|     Note that I'm modifying only the pgsql query, and I'm not touching
|     mod_inbox_rdbms_mssql nor mod_inbox_rdbms_mysql, as in bkpr we're using
|     pgsql alone.
| 
* commit 703f9d3c04279a27697a0d4888fbe2c9a3a4f408
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 12:11:03 2021 +0100
| 
|     [schema] Add new columns to pgsql inbox table
|     
|     Note that I'm modifying only the pgsql schema, and I'm not touching
|     mssql nor mysql schemas, as in bkpr we're using pgsql alone.
| 
* commit a8c1bb5aa5a272f1fc471991c8a5bbe53579a293
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 12:05:39 2021 +0100
| 
|     [inc] extend inbox_res() type
|     
|     I'm making the new values just binaries, to be transparent in their
|     meaning, mod_inbox should just put more childrens in the xml-stanza,
|     without knowing what are they.
| 
* commit f65bd1840b5d13c3cc72758644b2535dc32f1f44
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 15:03:48 2021 +0100
| 
|     [tests] Implement all possible extension tests
|     
|     This suite just has every single scenario covered by the extension, it
|     is very exhaustive and I tried to write the code in an organised and
|     predictable way, full of comments describing the intention, spec
|     annotations, and what not. I'm not reflecting here how did this came to
|     happen, just the final state of the test-suite.
| 
* commit 20273c9bd7906084fa3ea6ae365535791237e145
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 14:22:18 2021 +0100
| 
|     [tests] expand verifier options
|     
|     Sometimes an inbox verifier wants to access the outer message, and not
|     the default inner one, so add more cases based on the arity of the
|     function. This is a hack for the extension tests.
| 
* commit 59eb36cb29efafbbde2474a6d2ffeb6418896b2c
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Tue Mar 2 12:20:36 2021 +0100
| 
|     [doc] Explain inbox tags for properties
| 
* commit 66f665516826b855bc77e2bbf0f2d8acfe0a50b3
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Tue Mar 2 12:19:55 2021 +0100
| 
|     [doc] fix link to mod_inbox filtering
| 
* commit 8247f427b8ab3fa64ee3ac6de7585da0b767c2b6
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Tue Mar 2 12:19:01 2021 +0100
| 
|     [doc] Fix the protocol for archived vs archive naming consistency
| 
* commit fd476e2420cd238511dfb4083270c379f2f34cba
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Mar 3 13:16:07 2021 +0100
| 
|     [OS] Improve formatting and indentation for that!
| 
* commit 7157499cea8288bf553ed017b8ac19ce8cfe0650
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Tue Mar 2 12:36:02 2021 +0100
| 
|     [OS] Move helper inbox functions to helper modules
|     
|     This applies to both source and test code.
|     Also assert more consistent error messages in big_tests.
| 
* commit 526354cd1510f77056407dcd64c0521aaa2d4936
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Fri Feb 26 14:02:45 2021 +0100
| 
|     Attend review
| 
* commit a210f428bf7233eda87a6b949ccd72f341cca19b
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Fri Feb 26 12:30:18 2021 +0100
| 
|     Inbox documentation v2 (#28)
|     
|     * Inbox documentation v2
|     With attended review
| 
* commit d067e9bc04a23d532a2d1156bc4b40725f274038
| Author: Nelson Vides <nelson.vides@erlang-solutions.com>
| Date:   Wed Feb 24 00:31:30 2021 +0100
| 
|     Document XMPP interface to all bkpr inbox extensions
|   

* Inbox documentation v2
With attended review
This applies to both source and test code.
Also assert more consistent error messages in big_tests.
Sometimes an inbox verifier wants to access the outer message, and not
the default inner one, so add more cases based on the arity of the
function. This is a hack for the extension tests.
This suite just has every single scenario covered by the extension, it
is very exhaustive and I tried to write the code in an organised and
predictable way, full of comments describing the intention, spec
annotations, and what not. I'm not reflecting here how did this came to
happen, just the final state of the test-suite.
I'm making the new values just binaries, to be transparent in their
meaning, mod_inbox should just put more childrens in the xml-stanza,
without knowing what are they.
Note that I'm modifying only the pgsql schema, and I'm not touching
mssql nor mysql schemas, as in bkpr we're using pgsql alone.
Note that I'm modifying only the pgsql query, and I'm not touching
mod_inbox_rdbms_mssql nor mod_inbox_rdbms_mysql, as in bkpr we're using
pgsql alone.
There's a bunch of hardcoded calls to mod_inbox_bkpr, for selecting more
fields, filtering from more patterns, and returning more values, that I
tried to keep out of the base mod_inbox_rdbms, that might suffer
modifications in open source, keeping all bkpr logic just in
mod_inbox_bkpr.

The most challenging part is the tuple returned from the sql driver,
there's no way to pattern-match a variable-length tuple and tell the
extensions to parse all the suffix, I had to change the tuple size and
hardcode the extended fields.

I considered doing a tuple_to_list and pattern-match on that, but it
would be a performance overkill, I don't think we need to go that far.

Note that, as only the extension knows how the fields were requested,
only the extension knows how to process them and in which order.
As before, mod_inbox tries not to care what are these extra values being
processed, and simply takes them and forwards them to mod_inbox_bkpr for
processing.
This way we can add more flags to the extensions without touching
mod_inbox in the future. The only problem was in the type for the
parameters, where it wasn't accepting the new flags without adding
them there.
The extensions might send more messages, with certain attributes,
that are not desired to be stored on inbox, so the extension needs to
add more filtering for this.
Here it is, all of the actions requested by Beekeeper, implemented.
Also rework a bit how other tests were done
Sometimes things were declared as jid:user() when they were jid:luser(),
some others were passing jid:jid() and others binaries...

They were all modified to expect ready binaries of types jid:luser(),
jid:lserver(), or jid:literal_jid().
If we want to support more backends, the interface between them must be
pretty erlang idiomatic, so keep it integers and booleans on their
interface.

Also, note that the start function was using the wrong key number for
backend, it's the first of a tuple, not the second.

And one more thing, the accumulator contains the timestamp of the
incoming message, so we can skip calculating more timestamps along the
way.
Avoid calculating a new timestamp that can be off from the one when the
original message was received, and instead reuse that which was already
created when the message was received. Save computation and potentially
save clock miss-syncs.
@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #3067 (7d5414d) into master (8b30cbb) will increase coverage by 0.08%.
The diff coverage is 93.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3067      +/-   ##
==========================================
+ Coverage   78.77%   78.85%   +0.08%     
==========================================
  Files         379      380       +1     
  Lines       31137    31269     +132     
==========================================
+ Hits        24527    24658     +131     
- Misses       6610     6611       +1     
Impacted Files Coverage Δ
src/inbox/mod_inbox_rdbms_mssql.erl 100.00% <ø> (ø)
src/inbox/mod_inbox_rdbms_mysql.erl 100.00% <ø> (ø)
src/inbox/mod_inbox_rdbms_pgsql.erl 100.00% <ø> (ø)
src/rdbms/mongoose_rdbms.erl 64.08% <ø> (ø)
src/rdbms/rdbms_queries.erl 90.24% <ø> (ø)
src/rdbms/mongoose_rdbms_odbc.erl 77.77% <66.66%> (-0.53%) ⬇️
src/rdbms/mongoose_rdbms_mysql.erl 89.65% <85.71%> (-1.65%) ⬇️
src/inbox/mod_inbox.erl 90.30% <90.00%> (-0.23%) ⬇️
src/inbox/mod_inbox_rdbms.erl 88.52% <91.04%> (+0.57%) ⬆️
src/inbox/mod_inbox_utils.erl 93.24% <96.55%> (+0.26%) ⬆️
... and 16 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 8b30cbb...7d5414d. 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.

Lots and lots of good changes! I have some comments, mostly regarding the docs.

big_tests/tests/inbox_extensions_SUITE.erl Outdated Show resolved Hide resolved
big_tests/tests/inbox_extensions_SUITE.erl Show resolved Hide resolved
big_tests/tests/inbox_extensions_SUITE.erl Outdated Show resolved Hide resolved
big_tests/tests/inbox_extensions_SUITE.erl Outdated Show resolved Hide resolved
big_tests/tests/inbox_extensions_SUITE.erl Show resolved Hide resolved
src/inbox/mod_inbox_entries.erl Outdated Show resolved Hide resolved
src/inbox/mod_inbox_entries.erl Outdated Show resolved Hide resolved
src/inbox/mod_inbox_entries.erl Outdated Show resolved Hide resolved
src/inbox/mod_inbox_rdbms.erl Show resolved Hide resolved
src/inbox/mod_inbox_utils.erl Outdated Show resolved Hide resolved
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 attending all the comments! It looks great now.

Comment on lines +156 to +157
dynamic_modules:stop(Host, mod_inbox),
dynamic_modules:stop(Host, mod_muc_light),
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 refactor this with save_modules and restore_modules in the future, together with inbox_SUITE.

@chrzaszcz chrzaszcz merged commit b63783b into master Apr 9, 2021
@chrzaszcz chrzaszcz deleted the bkpr_inbox branch April 9, 2021 07:40
@leszke leszke added this to the 4.2.0 milestone Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants