Skip to content

Dev to main#217

Merged
Iwantcod merged 13 commits into
mainfrom
dev
Mar 13, 2026
Merged

Dev to main#217
Iwantcod merged 13 commits into
mainfrom
dev

Conversation

@Iwantcod
Copy link
Copy Markdown
Member

@Iwantcod Iwantcod commented Mar 13, 2026

개요

관련 BackLog

Resolves: (Backlog Number, ...)

PR 유형

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

PR Checklist

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

Summary by CodeRabbit

  • New Features

    • Added comprehensive policy change history tracking with timestamps for create, update, and delete operations.
    • Integrated MongoDB for storing policy audit history and write events.
    • Added "updated at" timestamp fields to policy responses for better visibility into modification dates.
  • Improvements

    • Streamlined traffic service logging for enhanced clarity.

@Iwantcod Iwantcod requested review from Misu0616 and pjh813 March 13, 2026 05:01
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc2268d5-bbe1-4b77-a519-c4e04cb73d0e

📥 Commits

Reviewing files that changed from the base of the PR and between 7d668e2 and d17c121.

📒 Files selected for processing (24)
  • .gitignore
  • docs/context7-dependencies.yaml
  • src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyActiveResDto.java
  • src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyCateResDto.java
  • src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyResDto.java
  • src/main/java/com/pooli/policy/domain/entity/PolicyHistory.java
  • src/main/java/com/pooli/policy/mapper/AppPolicyMapper.java
  • src/main/java/com/pooli/policy/repository/PolicyHistoryRepository.java
  • src/main/java/com/pooli/policy/service/AdminPolicyServiceImpl.java
  • src/main/java/com/pooli/policy/service/PolicyHistoryService.java
  • src/main/java/com/pooli/policy/service/PolicyHistoryServiceImpl.java
  • src/main/java/com/pooli/policy/service/PolicyWriteAuditService.java
  • src/main/java/com/pooli/policy/service/PolicyWriteEventType.java
  • src/main/java/com/pooli/policy/service/UserPolicyServiceImpl.java
  • src/main/java/com/pooli/traffic/service/TrafficDeductOrchestratorService.java
  • src/main/java/com/pooli/traffic/service/TrafficHydrateRefillAdapterService.java
  • src/main/java/com/pooli/traffic/service/TrafficInFlightDedupeService.java
  • src/main/java/com/pooli/traffic/service/TrafficRecentUsageBucketService.java
  • src/main/java/com/pooli/traffic/service/TrafficStreamConsumerRunner.java
  • src/main/resources/mapper/policy/AppPolicyMapper.xml
  • src/test/java/com/pooli/policy/service/AdminPolicyServiceImplTest.java
  • src/test/java/com/pooli/policy/service/PolicyWriteAuditServiceTest.java
  • src/test/java/com/pooli/policy/service/UserPolicyServiceImplTest.java
  • src/test/java/com/pooli/traffic/service/TrafficStreamConsumerRunnerTest.java

📝 Walkthrough

Walkthrough

This PR introduces a MongoDB-backed policy history and audit logging system, integrating audit trails across policy services. It adds MongoDB dependencies, new PolicyHistory entity and repository, PolicyHistoryService and PolicyWriteAuditService implementations, and incorporates history logging into AdminPolicyServiceImpl and UserPolicyServiceImpl. Concurrently, it refactors traffic service logging by removing traceId from log statements and enhances TrafficStreamConsumerRunner with MDC-based trace context propagation and deduplication handling.

Changes

Cohort / File(s) Summary
MongoDB Infrastructure
docs/context7-dependencies.yaml, src/main/java/com/pooli/policy/domain/entity/PolicyHistory.java, src/main/java/com/pooli/policy/repository/PolicyHistoryRepository.java
Added Spring Data MongoDB dependency configuration; introduced PolicyHistory entity (mapped to policy_history collection) with nested UpdateDetail class for capturing before/after state changes; created PolicyHistoryRepository for MongoDB CRUD operations with String ID type.
History & Audit Services
src/main/java/com/pooli/policy/service/PolicyHistoryService.java, src/main/java/com/pooli/policy/service/PolicyHistoryServiceImpl.java, src/main/java/com/pooli/policy/service/PolicyWriteAuditService.java, src/main/java/com/pooli/policy/service/PolicyWriteEventType.java
Introduced PolicyHistoryService interface and implementation for MongoDB event logging with before/after state diffing via nested map traversal; added PolicyWriteAuditService for transaction-aware audit persistence with snake_case normalization and field-level diffs; created PolicyWriteEventType enum (CREATE, UPDATE, DELETE) for audit events.
DTO Updates
src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyActiveResDto.java, src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyCateResDto.java, src/main/java/com/pooli/policy/domain/dto/response/AdminPolicyResDto.java
Added updatedAt field (LocalDateTime) to response DTOs with Swagger schema annotations; imported LocalDateTime type across classes.
Policy Service Integration
src/main/java/com/pooli/policy/service/AdminPolicyServiceImpl.java, src/main/java/com/pooli/policy/service/UserPolicyServiceImpl.java
Integrated PolicyHistoryService dependency and added history logging across all policy/category create/update/delete operations; modified flows to re-fetch updated entities from DB for response construction and audit logging with before/after state comparison.
Mapper & Repository Queries
src/main/java/com/pooli/policy/mapper/AppPolicyMapper.java, src/main/resources/mapper/policy/AppPolicyMapper.xml
Added new method findEntityById(Long) to retrieve policies without deletion status filtering, complementing existing deletion-aware lookup; added corresponding MyBatis XML select statement.
Traffic Service Logging Refactor
src/main/java/com/pooli/traffic/service/TrafficDeductOrchestratorService.java, src/main/java/com/pooli/traffic/service/TrafficHydrateRefillAdapterService.java, src/main/java/com/pooli/traffic/service/TrafficInFlightDedupeService.java, src/main/java/com/pooli/traffic/service/TrafficRecentUsageBucketService.java
Removed traceId from debug and error log statements across multiple service classes; updated log message templates to exclude trace identifiers while preserving other contextual data.
Traffic Stream Consumer Enhancement
src/main/java/com/pooli/traffic/service/TrafficStreamConsumerRunner.java
Introduced MDC-based traceId handling with put/remove in try-finally blocks; added duplicate-record detection via in-flight dedupe claim; refactored record processing flow to check for existing DONE entries, claim deduplication lock, run orchestrator, persist state idempotently, and acknowledge only after successful persistence.
Test Suite Additions
src/test/java/com/pooli/policy/service/AdminPolicyServiceImplTest.java, src/test/java/com/pooli/policy/service/PolicyWriteAuditServiceTest.java, src/test/java/com/pooli/policy/service/UserPolicyServiceImplTest.java, src/test/java/com/pooli/traffic/service/TrafficStreamConsumerRunnerTest.java
Added mocks for PolicyHistoryService and updated stubs for re-fetched policy/category states in AdminPolicyServiceImplTest; comprehensive unit tests for PolicyWriteAuditService covering update/create diffs, nested field tracking, transaction-aware persistence, and Mongo failure handling; expanded UserPolicyServiceImplTest with new dependencies and multi-scenario policy facet testing; added TrafficStreamConsumerRunnerTest covering MDC initialization and deduplication handling.
Configuration
.gitignore
Added ignore entry for /docs/role-c-step1-validation-test-plan.md.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin Service
    participant DB as RDB/Repository
    participant HS as HistoryService
    participant MR as MongoRepository
    participant MDB as MongoDB

    Admin->>DB: Create/Update/Delete Policy
    activate DB
    DB->>DB: Execute operation
    deactivate DB
    Admin->>DB: Re-fetch updated state
    activate DB
    DB-->>Admin: Return refreshed entity
    deactivate DB
    Admin->>HS: log(tableName, event, targetId, before, after)
    activate HS
    HS->>HS: Extract user from auth
    HS->>HS: Compute diff (before/after)
    HS->>MR: save(PolicyHistory)
    activate MR
    MR->>MDB: Insert audit document
    MDB-->>MR: Confirm
    deactivate MR
    deactivate HS
    Admin-->>Admin: Return response with updatedAt
Loading
sequenceDiagram
    participant Consumer as StreamConsumerRunner
    participant MDC as MDC Context
    participant Dedupe as InFlightDedupeService
    participant Orch as OrchestratorService
    participant Store as Persistence
    participant ACK as Kafka ACK

    Consumer->>MDC: put(TRACE_ID, payload.traceId)
    Consumer->>Store: Check DONE entry exists
    alt DONE exists
        Consumer-->>ACK: Acknowledge record
    else DONE not found
        Consumer->>Dedupe: tryClaim(traceId)
        alt Already claimed
            Consumer-->>Store: Check DONE again
            Consumer-->>ACK: Acknowledge record
        else Claim successful
            Consumer->>Orch: Run 10-tick deduction
            Orch-->>Consumer: Return result
            Consumer->>Store: saveIfAbsent(DONE)
            Consumer-->>ACK: Acknowledge record
            Consumer->>Dedupe: Release lock
        end
    end
    Consumer->>MDC: remove(TRACE_ID)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • [MERGE] dev to main #165: Both PRs modify UserPolicyServiceImplTest and adjust alarm assertion patterns (AlarmCode/AlarmType usage changes).
  • [Merge] Dev to Main #135: Both PRs modify AdminPolicyServiceImplTest, updating policy/category state stubs and test setup logic.
  • [MERGE] dev to main #162: Both PRs integrate into policy service layer (AdminPolicyServiceImpl, UserPolicyServiceImpl) for operational instrumentation.

Suggested labels

feature, test

Suggested reviewers

  • pjh813
  • Misu0616
  • hyeonRS

Poem

🐰 MongoDB records now store our tales,
As policies change, the audit trail never fails.
From create to delete, each step is logged with care,
With before and after states—transparency everywhere! ✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@Misu0616 Misu0616 left a comment

Choose a reason for hiding this comment

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

제발 프론트에게 피드백이 안 왔으면 좋겠어요ㅠㅠ

@Iwantcod Iwantcod merged commit 8feae8c into main Mar 13, 2026
2 of 3 checks passed
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.

2 participants