hypothesis / h

Annotate with anyone, anywhere.
https://hypothes.is/
BSD 2-Clause "Simplified" License
2.96k stars 427 forks source link

Add better logging to `UserDeleteService` #9101

Closed seanh closed 16 hours ago

seanh commented 1 week ago

Demo:

Purging User(id=1) - marked user as deleted
Purging User(id=1) - added purge_user job: Job(id=3, name=<JobName.PURGE_USER: 'purge_user'>, enqueued_at=datetime.datetime(2024, 11, 20, 17, 54, 14, 532500), scheduled_at=datetime.datetime(2024, 11, 20, 17, 54, 14, 532500), expires_at=datetime.datetime(2024, 12, 20, 17, 54, 14, 532500), priority=0, tag='UserDeleteService.delete_user')
Purging User(id=1) - added record of user deletion: UserDeletion(id=1, userid='acct:devdata_user@localhost', requested_at=datetime.datetime(2024, 11, 20, 17, 54, 14, 532500), requested_by='acct:devdata_admin@localhost', tag='admin.users_delete', registered_date=datetime.datetime(2024, 11, 20, 17, 51, 45, 532818), num_annotations=2)
Purging User(id=1) - deleted 1 rows from authticket
Purging User(id=1) - deleted 2 rows from token: 1, 2
Purging User(id=1) - marked annotations as deleted: ZTAldqdoEe-rRre0o_POkw, ZyjywqdoEe-rRsdA2rr4SA
Purging User(id=1) - marked annotation_slims as deleted: 1, 2
Purging User(id=1) - enqueued jobs to delete annotations from Elasticsearch: ZTAldqdoEe-rRre0o_POkw, ZyjywqdoEe-rRsdA2rr4SA
Purging User(id=1) - deleted 1 rows from group: 5
Purging User(id=1) - deleted 1 rows from user: 1
Purging User(id=1) - completed job: Job(id=3, name='purge_user', enqueued_at=datetime.datetime(2024, 11, 20, 17, 54, 14, 532500), scheduled_at=datetime.datetime(2024, 11, 20, 17, 54, 14, 532500), expires_at=datetime.datetime(2024, 12, 20, 17, 54, 14, 532500), priority=0, tag='UserDeleteService.delete_user')

The aim is to add good enough logging to UserDeleteService such that if a user was accidentally deleted (or if a bug caused UserDeleteService to delete stuff that it shouldn't, etc) we'd have enough information in the logs to assess what happened and to recover the accidentally deleted data from a backup of the DB.

The logging should also incidentally make monitoring and debugging generally easier.

Notes: