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

refactor: Roles out of DB Watcher #32280

Merged
merged 9 commits into from
May 8, 2024

Conversation

ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Apr 22, 2024

As per the updates mentioned in PROJ-7 SCA-4 and ADR #74, this pull request focuses on relocating Roles entity out of DB Watcher service.

Quick context to public readers

In essence, this modification empowers RocketChat's app to directly call listeners through the api.broadcast global function, eliminating the reliance on MongoDB Change Stream data propagation

Why is this beneficial? It provides better control over notifying users by enabling more precise use-case management. Unlike Change Streams, which notify every action on Mongo's documents and sometimes might result in unnecessary duplicate notifications. Moreover, it contributes to the future removal of the DB Watcher deployment, thereby optimizing resource utilization.

Proposed changes

Key changes include:

  • Conditionally incorporating the Roles entity import within DB watchers on application startup based on the dbWatchersDisabled flag.
  • Enabling support for roles.update and roles.create routes to directly trigger the watch.roles listener event, subject to the dbWatchersDisabled flag (please check above section of updated use cases).
Updated use cases.
Use Case Route/Trigger Notes
insertRole POST api/v1/roles.create
updateRole POST api/v1/roles.update
deleteRole POST api/v1/roles.delete

I didn't find references to Meteor's method deleteRoom (apps/meteor/app/authorization/server/methods/deleteRole.ts) so I didn't add listener call there.

Steps to test or reproduce

  1. Start RocketChat's application with the DISABLE_DB_WATCHERS flag set to true.
  2. Perform a POST request to the endpoints api/v1/roles.create, api/v1/roles.update, or api/v1/roles.delete.
  3. Observe the websocket events received. Each event should be of eventName roles, containing all changed fields as well as the updated role identification data.

Further comments

While further exploration might reveal additional use cases regarding DB operations and Roles entity interaction, it's important to note that certain events, such as startup events in RocketChat Enterprise Edition or server setup initiation, are not appropriate for notification via the Listener service. Therefore, they should not be linked to trigger an event through api.broadcast calls.

To maintain consistency and avoid potential regressions, event names and signatures have been kept unchanged on both the client and app sides. This decision streamlines efforts and mitigates the risk of unintended consequences. Additionally, considering time constraints and the absence of tests for this core server component, this direction was chosen as the most pragmatic approach.

Roles model WBS. Used to guide changes discovery.
🔄 Work in progress
✅ Done
➖ Not applicable

Function Status
findByUpdatedDate
addUserRoles
isUserInRoles
removeUserRoles
findOneByIdOrName
findOneByIdOrName
findOneByIdOrName
findOneByIdOrName
findOneByName
findInIds
findInIdsOrNames
findAllExceptIds
findByScope
updateById
findUsersInRole
findUsersInRole
findUsersInRole
findUsersInRole
findCustomRoles
createWithRandomId
canAddUserToRole

Copy link

changeset-bot bot commented Apr 22, 2024

⚠️ No Changeset found

Latest commit: 301e77e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

dionisio-bot bot commented Apr 22, 2024

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@ricardogarim ricardogarim changed the title Refactor/mentions and settings out of db watcher refactor: Roles entity out of DB Watcher service Apr 22, 2024
Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.55%. Comparing base (5d1cb28) to head (301e77e).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #32280      +/-   ##
===========================================
+ Coverage    55.52%   55.55%   +0.02%     
===========================================
  Files         2401     2404       +3     
  Lines        52860    52892      +32     
  Branches     10856    10862       +6     
===========================================
+ Hits         29352    29385      +33     
+ Misses       20907    20905       -2     
- Partials      2601     2602       +1     
Flag Coverage Δ
e2e 54.84% <ø> (+0.06%) ⬆️
unit 73.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@ricardogarim ricardogarim marked this pull request as ready for review April 23, 2024 10:53
@ricardogarim ricardogarim requested review from a team as code owners April 23, 2024 10:53
@ricardogarim ricardogarim marked this pull request as draft April 24, 2024 12:51
@ricardogarim ricardogarim changed the title refactor: Roles entity out of DB Watcher service refactor: Roles out of DB Watcher Apr 29, 2024
@ricardogarim ricardogarim marked this pull request as ready for review April 29, 2024 12:05
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label May 8, 2024
@sampaiodiego sampaiodiego added this to the 6.9 milestone May 8, 2024
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label May 8, 2024
@kodiakhq kodiakhq bot merged commit 0154fac into develop May 8, 2024
45 checks passed
@kodiakhq kodiakhq bot deleted the refactor/mentions-and-settings-out-of-db-watcher branch May 8, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants