Skip to content

[BE][Data][FIX] Audit/LLM trace API foundation #59

Description

@yoonki1207

목표

  • MVP1에서 필요한 audit skeleton과 LLM trace 조회 API를 완성한다.
  • 기존 audit_logs, workflow_runs, workflow_node_runs, llm_usage_logs를 재사용한다.
  • 새 audit table이나 dashboard aggregate table을 만들지 않는다.

관련 Linear

구현 범위:

작업 내용
Audit action 정리 workflow execute, permission denied, llm call에 필요한 action을 기존 audit 체계에 맞춘다.
Workflow execute audit execute 시작/성공/실패 또는 최소 성공/실패 이벤트를 남긴다.
Permission denied audit 권한 실패 metadata에 resource/action/effective permission을 남긴다.
LLM trace query run id와 node id 기준으로 llm_usage_logs를 조회한다.
Run detail 확장 run detail 응답 또는 별도 endpoint에서 node별 LLM usage를 반환한다.
Latency 정합성 코드에서는 ORM 속성 latency_ms를 쓰고, 물리 column atency_ms는 MVP1에서 rename하지 않는다.
Audit pagination MVP1 UI/API에서 audit list를 사용한다면 MBA-38, MBA-39를 함께 처리한다. 사용하지 않으면 후순위로 둔다.

구현 방법

  1. audit_logs는 canonical audit table로 유지한다.
  2. audit_logs.status에는 dev enum 기준 success 또는 failure만 저장한다.
  3. allow/deny/warn/block 같은 정책 결과는 audit_metadata.policy_result에 저장한다.
  4. LLM trace API는 raw query 또는 SQLAlchemy query로 기존 table을 조인한다.
  5. trace 조회는 workflow read 권한을 통과한 user만 가능하게 한다.
  6. llm_usage_logs.latency_ms ORM 속성은 그대로 쓰고, DB physical column rename은 별도 schema 변경으로 미룬다.

권장 API 후보

GET /api/v1/workflows/{workflow_id}/runs/{run_id}/llm-traces
GET /api/v1/workflows/{workflow_id}/runs/{run_id}/llm-traces?node_id={node_id}

또는 기존 GET /api/v1/workflows/{workflow_id}/runs/{run_id} 응답에 llm_usage_logs 요약을 포함한다. 둘 중 하나만 선택해서 중복 API를 만들지 않는다.

Acceptance Criteria

  • workflow 실행 성공/실패가 audit에 남는다.
  • 권한 차단이 audit에 남는다.
  • LLM node 실행 후 run_id 기준으로 model/token/cost/latency/status를 조회할 수 있다.
  • 여러 LLM node가 있어도 node_id로 구분된다.
  • trace API는 workflow read 권한 없이는 거부된다.
  • latency_ms 사용 코드가 physical atency_ms column 때문에 깨지지 않는다.

Out of Scope

  • 조직 전체 audit 관리자 페이지
  • raw trace payload permission 완성
  • RAG retrieval trace
  • dashboard aggregate table

참고 사항

MVP-01-기반 문서

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

Priority

None yet

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions