Skip to content

Task 3-2: Alert khi Queue Lag Vượt Ngưỡng Critical

Phase: 3 - Observability Priority: Medium Depends on: task-3-1 Reference: docs/BountyHunter-Backend/details/feature-prize-allocation/SPEC.md

Background

PRIZE và PRIZE_FOR_STREAMER queues có concurrency 1-1. Nếu processing chậm hoặc listener down, queue sẽ lag và room creation bị delay — nhưng không có alert.

Tasks

DI Note: BatchQueueMonitorService cần inject broker connection để query queue depth — xác nhận method getQueueDepth(String queue) đã tồn tại hoặc cần implement mới (dùng JMX DestinationStatistics hoặc ActiveMQ REST API). @Scheduled yêu cầu @EnableScheduling trên @Configuration class trong batch module.

  • [ ] Define thresholds per queue và add specific alerts:

    // Trong BatchQueueMonitorService:
    private static final Map<String, Long> QUEUE_THRESHOLDS = Map.of(
        "queue-prize-allocation-PRIZE", 20L,              // low threshold vì concurrency=1-1
        "queue-prize-allocation-PRIZE_FOR_STREAMER", 20L,
        "queue-prize-allocation-UNLIMITED", 500L,         // higher ok vì concurrency=20-100
        "queue-prize-allocation-MISSION", 100L,
        "queue-prize-allocation-GACHA", 100L
    );
    
    @Scheduled(fixedDelay = 15000)  // check every 15s
    public void checkPrizeQueueLags() {
        QUEUE_THRESHOLDS.forEach((queue, threshold) -> {
            Long depth = getQueueDepth(queue);  // verify method tồn tại
            if (depth != null && depth > threshold) {
                LOGGER.error("[PRIZE_QUEUE_LAG] queue={} depth={} threshold={} - ACTION REQUIRED",
                    queue, depth, threshold);
                // Optional: alertingService.sendAlert(...)
            }
        });
    }
    

  • [ ] Verify getQueueDepth() method: nếu chưa có → implement bằng JMX hoặc ActiveMQ statistics plugin

  • [ ] Externalize thresholds vào config nếu cần tune per environment

Verification / Acceptance Criteria

  • [ ] checkPrizeQueueLags() chạy mỗi 15s (verify qua logs)
  • [ ] Khi PRIZE queue depth > 20 → log ERROR [PRIZE_QUEUE_LAG]
  • [ ] Khi UNLIMITED queue depth > 500 → log ERROR [PRIZE_QUEUE_LAG]
  • [ ] Normal depth (below threshold) → không log error
  • [ ] @Scheduled không overlap: dùng fixedDelay (không phải fixedRate)

Files to Modify

  • batch/src/main/java/com/figpop/batch/service/BatchQueueMonitorService.java