Skip to content

Task 3-2: Monitor Redis Session Repository Health

Phase: 3 - Resilience Priority: Low Module: authentication Depends on: Không có Reference: docs/BountyHunter-Backend/details/feature-authentication/SPEC.md

Background

Session management dùng Redis. Nếu Redis unavailable, tất cả authenticated requests đều fail. Không có health check hay circuit breaker cho session repository.

Tasks

DI / Config note: Task này chỉ thay đổi cấu hình YAML — không cần inject thêm Java bean. Tuy nhiên, để Spring Boot tự động expose Redis health, đảm bảo: 1. Dependency spring-boot-starter-actuator có trong pom.xml/build.gradle của module authentication. 2. Dependency spring-session-data-redis (hoặc spring-boot-starter-data-redis) đã được include — Spring Boot sẽ tự phát hiện RedisConnectionFactory bean và expose health indicator tương ứng. 3. File application-common.yaml đúng là file config được load cho module này (kiểm tra spring.config.import hoặc tên profile).

  • [ ] Thêm Redis health check vào /actuator/health:

    # application-common.yaml (authentication module)
    management:
      health:
        redis:
          enabled: true
      endpoints:
        web:
          exposure:
            include: health,metrics
    

  • [ ] Verify RedisConnectionFactory health được report trong actuator response

  • [ ] Set alert nếu Redis health = DOWN (trong monitoring dashboard)
  • [ ] Document Redis TTL config cho session keys:
  • Session TTL: xem config spring.session.redis.flush-mode và TTL setting
  • Auth code TTL: xem expireAuthCode field usage

Verification / Acceptance Criteria

  • [ ] Config valid: application-common.yaml parse thành công — không có YAML syntax error; application khởi động bình thường sau khi thêm config.
  • [ ] Health endpoint: GET /actuator/health trả về HTTP 200 với component redis trong response body khi Redis đang UP.
  • [ ] Redis DOWN detection: Dừng Redis → GET /actuator/health trả HTTP 503 với redis.status=DOWN (hoặc overall status = DOWN/degraded tùy cấu hình).
  • [ ] Metrics exposed: GET /actuator/metrics liệt kê các metric liên quan (bao gồm metric từ task-2-2 nếu đã implement).
  • [ ] Session TTL documented: TTL của session key và auth code key được ghi rõ trong comment của config file.

Files to Modify

  • authentication/src/main/resources/application-common.yaml