Skip to content

Migrate audit log to batched logging system #8542

@HyeockJinKim

Description

@HyeockJinKim

Objective

Migrate audit log creation from direct DB writes to the batched logging system.

Implementation Details

Repository Changes

  1. Update AuditLogDBSource
    • Add bulk_create() method using BulkCreator
    • Keep existing create() for backward compatibility
async def bulk_create(
    self, 
    creators: Sequence[Creator[AuditLogRow]]
) -> list[AuditLogData]:
    async with self._db.begin_session() as db_sess:
        result = await execute_bulk_creator(db_sess, BulkCreator(specs=[c.spec for c in creators]))
        return [row.to_dataclass() for row in result.rows]
  1. Update AuditLogRepository
    • Route create() calls to queue manager
    • Add flush() method for manual flush operations

Service Changes

  1. Update AuditLogService
    • Change create() to enqueue instead of direct DB write
    • Return immediately without waiting for DB write

Integration

  • Wire LogQueueManager into AuditLogService
  • Configure batch writer for audit logs
  • Set Redis backup enabled for audit logs (critical)

Testing

  • Test audit log enqueueing
  • Test batch creation with multiple entries
  • Test flush on interval and threshold
  • Integration tests with real DB

Migration Strategy

  • Feature flag for gradual rollout
  • Monitor queue depth and flush latency
  • Rollback plan if issues detected

Acceptance Criteria

  • Audit logs written in batches
  • No functional regression
  • Reduced DB transaction count (target: 90%)
  • All tests passing

JIRA Issue: BA-4234

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Story.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions