Task 2-2: Alert khi Queue Lag Vượt Ngưỡng
Phase: 2 - Stability Priority: Medium Module:
batchDepends on: task-2-1 Reference:docs/BountyHunter-Backend/details/feature-game-room-management/SPEC.md
Background
Room creation enqueue vào prize allocation queues. Nếu queue lag cao, room creation sẽ bị delay nhưng không có alert nào.
Tasks
DI Note (quyết định thiết kế): Có 2 lựa chọn: - Option A: Thêm method vào
BatchQueueMonitorServicehiện có (nếu đã cógetQueueDepth()method) - Option B: TạoRoomQueueMonitorServicemới annotated với@Service(nếuBatchQueueMonitorServicequá lớn hoặc không có sẵngetQueueDepth())Kiểm tra
BatchQueueMonitorServicetrước, chọn option phù hợp. Nếu tạo class mới, cần@EnableSchedulingở Application class (kiểm tra xem đã có chưa).
- [ ] Kiểm tra
BatchQueueMonitorServicexem có methodgetQueueDepth(String queue)hay tương đương không -
[ ] Thêm threshold-based alert cho các queues liên quan đến room:
// Trong BatchQueueMonitorService hoặc RoomQueueMonitorService // Clarification: PRIZE_FOR_STREAMER dùng cùng threshold với PRIZE vì cả 2 đều xử lý paid prizes private static final long PRIZE_QUEUE_LAG_THRESHOLD = 50; private static final long UNLIMITED_QUEUE_LAG_THRESHOLD = 200; @Scheduled(fixedDelay = 30000) // check mỗi 30 giây public void checkRoomQueues() { checkQueueLag("queue-prize-allocation-PRIZE", PRIZE_QUEUE_LAG_THRESHOLD); checkQueueLag("queue-prize-allocation-PRIZE_FOR_STREAMER", PRIZE_QUEUE_LAG_THRESHOLD); checkQueueLag("queue-prize-allocation-UNLIMITED", UNLIMITED_QUEUE_LAG_THRESHOLD); } private void checkQueueLag(String queue, long threshold) { Long depth = getQueueDepth(queue); // reuse method hiện có hoặc implement mới if (depth != null && depth > threshold) { LOGGER.warn("[QUEUE_LAG] Queue {} depth={} exceeds threshold={}", queue, depth, threshold); } } -
[ ] Nếu tạo
RoomQueueMonitorServicemới: đảm bảo injectJmsTemplatehoặc connection factory tương tự nhưBatchQueueMonitorServiceđể lấy queue depth
Verification / Acceptance Criteria
- [ ]
@Scheduled(fixedDelay = 30000)được trigger mỗi 30 giây (verify qua log) - [ ] Khi queue
queue-prize-allocation-PRIZEdepth > 50, log[QUEUE_LAG]xuất hiện với đúng queue name và depth - [ ] Khi queue
queue-prize-allocation-UNLIMITEDdepth > 200, log[QUEUE_LAG]xuất hiện - [ ] Khi queue depth dưới threshold, không có log warning
- [ ] Nếu
getQueueDepth()trả vềnull(queue không tồn tại hoặc lỗi kết nối), không throw exception — method bỏ qua silently - [ ] Service compile và start được mà không lỗi (scheduling bean được đăng ký)
- [ ] Unit test: mock
getQueueDepthtrả về giá trị > threshold → verify log warning
Files to Modify
batch/src/main/java/com/figpop/batch/service/BatchQueueMonitorService.java