Skip to content

feat(audit): Outbox 기반 감사 이벤트 전달과 Workflow 실행 연계 구현 - #490

Merged
hojun-lee99 merged 10 commits into
devfrom
feature/implement-audit-outbox
Jul 16, 2026
Merged

feat(audit): Outbox 기반 감사 이벤트 전달과 Workflow 실행 연계 구현#490
hojun-lee99 merged 10 commits into
devfrom
feature/implement-audit-outbox

Conversation

@hojun-lee99

Copy link
Copy Markdown
Contributor

변경 사항

  • 감사 이벤트를 Celery에 바로 전달하는 대신, 요청 트랜잭션 안에서 audit_event_outbox에 저장하도록 변경했습니다.
  • Outbox 배송 워커에 lease, 재시도, 최대 시도 횟수, dead letter 처리를 구현했습니다.
  • 권한 변경과 Outbox 저장이 같은 DB 세션에서 원자적으로 처리되도록 수정했습니다.
  • 성공한 Outbox 이벤트는 민감 데이터가 남지 않도록 payload를 제거합니다.
  • AuditLog에 workflow_run_id, workflow_node_run_id 연계 필드를 추가했습니다.
  • Workflow 연계 시 감사 이벤트와 Workflow가 같은 조직인지 검증합니다.
  • 관련 DB migration, 문서, 서비스 및 스키마 테스트를 추가했습니다.

관련 이슈

Closes #

변경 유형

  • 버그 수정
  • 새로운 기능
  • 리팩토링
  • 문서 수정
  • 기타

테스트

  • 로컬에서 테스트 완료
  • 기존 테스트 통과 확인

테스트 결과:

  • Gateway 권한 API 테스트: 75 passed
  • Audit Outbox 서비스 테스트: 12 passed
  • Log System 감사 작업 테스트: 28 passed
  • 빈 로컬 DB에서 Alembic upgrade head 성공
  • 로컬 DB revision과 코드 migration head가 a9b0c1d2e3f4로 일치함

스크린샷 (UI 변경 시)

해당 없음 — UI 변경이 없습니다.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d157b146ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +109 to +113
audit_organization_id = _to_uuid(metadata.get("organization_id"))
if audit_organization_id is None:
audit.workflow_run_id = None
audit.workflow_node_run_id = None
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 조직 메타데이터가 없는 실행 감사도 run 연결을 보존하세요

일반 수동/API workflow 완료 경로에서는 _schedule_audit_organization_id()가 scheduler 실행이 아니면 None을 반환해 _record_workflow_execute_audit()workflow_run_id만 metadata에 넣고 organization_id는 넣지 않습니다. 이 새 검증은 그런 기존 workflow.execute payload를 모두 여기서 workflow_run_id=None으로 지워 버리므로, 가장 흔한 사용자 실행 감사가 typed run FK 없이 저장되어 감사 목록/상세에서 실행 기록과 연결되지 않습니다. workflow_run_id가 있으면 Run→Workflow에서 조직을 확인해 보존하거나 producer가 사용자 실행에도 organization_id를 넘기도록 맞춰야 합니다.

Useful? React with 👍 / 👎.

AuditEventOutbox.lease_expires_at <= now,
)
.with_for_update(skip_locked=True)
.all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 만료 lease 복구도 배치 한도를 적용하세요

Log worker 장애나 재시작 중 leased 상태로 만료된 audit outbox row가 많이 쌓이면, 다음 beat 실행이 여기서 모든 stale row를 한 번에 조회·잠금·갱신합니다. process_due_events(limit=...)의 한도는 신규 lease에만 적용되어 대량 backlog에서는 singleton beat task가 오래 점유되고 정상 pending 배송까지 밀릴 수 있으므로, stale lease 복구도 동일하게 제한하거나 별도 batch size로 끊어 처리해야 합니다.

Useful? React with 👍 / 👎.

Comment on lines +117 to +121
run = db.get(WorkflowRun, audit.workflow_run_id)
if run is None:
audit.workflow_run_id = None
audit.workflow_node_run_id = None
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 아직 저장 중인 WorkflowRun correlation을 재시도하세요

Workflow Engine은 run id를 먼저 만들고 log.create_run을 비동기로 보낸 뒤 노드 실행 audit도 같은 workflow_run_id로 남길 수 있는데, log queue 지연/재시도 중 Outbox worker가 먼저 이 row를 처리하면 db.get(WorkflowRun, ...)가 아직 None입니다. 현재는 이를 영구 orphan처럼 처리해 correlation을 지우고 AuditLog를 성공 commit하므로, 이후 log.create_run이 정상 저장되어도 RAG/LLM 노드 audit은 실행 기록에 연결되지 않습니다; missing run은 짧게 retry하거나 생산자가 run 저장 이후에만 outbox를 확정해야 합니다.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant