feat: save audit logs to postgres (M2-10911) - #2076
Merged
Merged
Conversation
divbzero
requested changes
Jun 22, 2026
divbzero
left a comment
Contributor
There was a problem hiding this comment.
@sricharan-varanasi This looks very good overall. I just had one main suggestion of changing from .any(applet_id) to .contains(applet_id). Please take a look to see if that make sense to you too.
Separately, I also want to try this branch of code locally before we merge the database migration. Thank you!
divbzero
approved these changes
Jun 24, 2026
divbzero
left a comment
Contributor
There was a problem hiding this comment.
Thanks @sricharan-varanasi the changes look good! I’ve spun it up locally and confirmed that audit events are logged to the PostgreSQL database and can be exported successfully. Ready to merge after removing ix_audit_logs_event_action from upgrade/downgrade database migration scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
🔗 Jira Ticket M2-10911
Moves audit log storage from OpenSearch to our Postgres database.
Changes include:
audit_logstable (+ migration) using a hybrid layout: a few indexed columns (event_id,event_timestamp,event_action,event_outcome,user_id,applet_ids) plus a JSONBpayloadholding the full event document.AuditLogCRUDinstead of OpenSearch. Insert is idempotent (ON CONFLICT (event_id) DO NOTHING) so retries don't duplicate rows.🪤 Peer Testing
Requires services up:
docker compose up -d postgres postgres-arb redis rabbitmqanduv run alembic upgrade head.Trigger an audited action (e.g. view answers / export) as an owner.
Expected outcome: a row appears in
audit_logswith the correctevent_action,user_id,applet_idsand fullpayload;event_outcome = success.Hit a data-access endpoint with a non-existent applet id, e.g.
GET /answers/applet/<random-uuid>/data.Expected outcome:
404, and afailurerow inaudit_logswitherror.type = AppletNotFoundError.Call
GET /audit/applets/{applet_id}/eventsas an owner/manager.Expected outcome: returns that applet's events, same shape as before, filtered by date range / paginated.