Skip to content

[#328] Resolve "add event log"

aguestuser requested to merge 328-add-event-log into master

Closes #328 (closed)

context

  • we would like to record metrics about channels and users that will persist after channels are destroyed or users leave all channels
  • to do this, we want to add an events append-only log to the db and use it to log the following events:
    • every time a channel is created or destroyed, append a channel_created or channel_destroyed event (with timestamp and hashed channel phone number) to the event log
    • every time a unique user is created or destroyed, append a user_created or user_destroyed event (with timestamp and hashed member phone number) to the log

changes

foundation-laying:

  • create events table & model (w/ fields for id, event, and phoneNumberHash)
  • add util.sha256Hash to hash phone number
  • add sha256 validation (to ensure we never add unhashed phone numbers to log. this is extra important since a user will have a reasonable expectation that after completely leaving our service there is no trace of their phone number left in our db)

implement logging:

  • provide eventRepository.log which accepts an event type and a phone number, then creates an event log for the sha-256 hash of the phone number
  • for channel events: it's simple!
    • log CHANNEL_CREATED anytime a channel is created (in registrar.channel.create)
    • log CHANNEL_DESTROYED anytime a channel is destroyed (either in registrar.phoneNumber.destroy or phoneNumber.recycle)
  • for member events: it's more complicated! users might have multiple memberships, so we want to only:
    • log MEMBER_CREATED if the user does not have any other memberships yet
    • log MEMBER_DESTROYED if the user does not have any other memberships left
    • to do this, add logIfLastMembership/logIfFirstMembership to event repository (and expect to call them after creating or destroying a membership)
      • use logIfFirstMembership to log MEMBER_CREATED if only one membership exists with a number
      • call it from ACCEPT / JOIN / ADD handlers in dispatcher.commands.execute
      • use logIfLastMembership to log MEMBER_DESTROYED if no memberships remain with a number
      • call it from LEAVE / REMOVE handlers in dispatcher.commands.execute

cleaning up:

  • add backfill script to retroactively create event log entries for all existing channels and memberships (so it will be safe to recycle channels without fear of losing all memory of them!)
  • add a GOTCHA comment to help future implementors help avoid double counting users
Edited by aguestuser

Merge request reports

Loading