ES /docs

[429] {"error":{"root_cause":[],"type":"search_phase_execution_exception","reason":"","phase":"fetch

Fix Plan: Elasticsearch circuit_breaking_exception — search_phase_execution_exception (reduce_aggs)

Changes#

tesla: app/controllers/concerns/searchable_controller.rb#

  • What: MAX_BUCKET_SIZE_OF_AGGREGATIONS 상수 값을 5000에서 500으로 변경
  • Why: 5,000개 bucket의 terms/composite aggregation이 동시 요청 시 ES JVM heap(7.5GB 한도)을 초과하여 circuit_breaking_exception을 유발. 500으로 축소하면 aggregation 메모리 사용량이 1/10로 감소하여 circuit breaker 발동 위험을 크게 줄임
  • Lines: 5

tesla: app/repositories/base_repository.rb#

  • What: search 메서드의 rescue 체인에서 StandardError 이전에 Elasticsearch::Transport::Transport::Errors::TooManyRequests를 별도로 catch하여, circuit breaker 에러임을 명확히 로깅하고 적절한 에러 코드(429 기반)로 클라이언트에 반환
  • Why: 현재 429 TooManyRequests 에러가 StandardError catch에 의해 BG10002 Bad Gateway로 변환되어 원인 정보가 손실됨. 명시적 rescue를 추가하면 circuit breaker 관련 에러를 구분하여 디버깅과 모니터링이 가능해짐
  • Lines: 83-92

Acceptance Criteria#

  • MAX_BUCKET_SIZE_OF_AGGREGATIONS 값이 500으로 변경됨
  • Elasticsearch::Transport::Transport::Errors::TooManyRequestsStandardError보다 먼저 rescue됨
  • TooManyRequests rescue 블록에서 Cupix::Logger.error로 circuit breaker 관련 메시지를 로깅함
  • TooManyRequests rescue 블록에서 Cupix::Errors::BadGateway가 아닌 적절한 에러(예: Cupix::Errors::System 또는 별도 에러 코드)를 raise함
  • 기존 BadRequestStandardError rescue 체인이 그대로 유지됨

Tests#

  • 기존 테스트: spec/repositories/base_repository_spec.rb (있을 경우)
  • 신규 테스트: 없음 (최소 변경 원칙)