clowdr-app / clowdr

Midspace (formerly Clowdr) is a completely open-source virtual conference platform. Host complex events with hundreds of authors and presenters. Midspace includes automated livestreams, video chat, text chat, randomised networking and much more.
https://www.midspace.app/
GNU Affero General Public License v3.0
60 stars 20 forks source link

πŸ—ƒπŸ“¦πŸŒ³ Feature/usage and quotas #410

Closed EdNutting closed 2 years ago

EdNutting commented 2 years ago

What's new

This PR introduces Usage and Quotas. A Quota defines limits of consumption of key aspects of a conference (including all subconferences).

Once the limits have been proven in production we will then layer our checkout flow on top, including UI for displaying quotas and usage, and ways to purchase additional quota.

Quotas

Quotas (/limits) are:

Measuring usage

Consumption of streaming and video-chat event minutes is measured by regular calls to the idempotent updateEventUsage Postgres function (via the GQL API). Consumption of video-chat outside of events is measured by tracking registrant's connections to video chats (via Redis) and regular aggregating the totals via the Actions service.

Enforcing the quota

Postgres triggers are used to enforce the remaining quota on the relevant tables. The Actions service checks video-chat consumption prior to granting a connection token.

Other major changes

  1. The merge of the changes to presence tracking to use ping-based rather than perfect-connection-tracking.
    • This requires Redis to be flushed of all PresenceList:* keys because the type has changed from hashset to ordered set
  2. The removal of the room.Participant table
    • Room participants are now tracked in Redis.
    • Vonage connections are also now tracked in Redis (though Vonage Streams continue to be tracked in Postgres)
    • This enables efficient tracking of connections, connection duration and total consumption
    • This enables more efficient fetching of the list of people connected to a room
    • This will be significantly more reliable even if the main Postgres database suffers load issues at the start of an event (when everyone is joining).
    • This will reduce load on Postgres (inserts and deletes coupled with many selects was creating a perfect storm for Postgres)
  3. Enabling of server-side query caching in Hasura (by adding @cached to many of the frontend queries)
    • Our work on the next branch (recently merged) was heavily focused on making user's queries overlap, even in the Hasura session variable values.
    • This work is what enables us to make use of Hasura's server-side caching
      1. As a result of ready, low-impact access to the count of connected participants to a room (via Redis - see (2)), the Capacity field of Rooms is now respected when someone tries to connect to a room.
        • The corresponding field in the Admin UI is now shown again
      2. Program rooms are now either streaming rooms or non-streaming rooms.
        • This is determined by whether any streaming event is scheduled in a room
        • The default video chat is not shown in a streaming room
        • Postgres insert/update triggers prevent the formation of events from different mode-classes (streaming vs non-streaming) in the same room

Other minor changes

  1. Commenting out the Shuffle Queue Algorithm selection in the Admin UI, since this has never yet been finished
  2. Renamed "Shuffle" to "Networking" in the admin landing page

Deployment

Instructions for how to deploy these changes to production. Please tick (i.e. put an 'x' in) the boxes for the actions that are necessary.

Testing

This is the first time we are introducing proper automated testing. The tests are contained within /tests/usage-and-quotas and can be executed using pnpm test (and various other options - see package file).

Tests are built using the Vitest framework and require an env file and Hasura to be running locally. Each test executes sequentially due to the problem of certain conflicting database update calls that apply to all conferences at once (and so would affect concurrent tests at random).

Tests cover all aspects of the changes within the database: the tables, views, restrictive triggers and update usage function.

Four of the tests are skipped by default as they run for 60-seconds each, which would slow down routine testing. They should be enabled for testing prior to submitting a PR.

EdNutting commented 2 years ago

N.B. Use "Squash and merge" on this PR