Migration request failed from evergreen - {"result":{"code":"BG10004","type":"Cupix::Errors::BadGate
RCA: Migration request failed from evergreen - BG10004 BadGateway
Overview#
What Happened#
2026-05-26 04:46 UTC에 cupixworks-api (production, us-west-2)에서 Evergreen 마이그레이션 서비스로의 요청이 실패했다. Evergreen이 Tesla API로 facility 정보를 조회하려 했으나, 만료/무효한 API 토큰으로 인해 401 Unauthorized 응답을 받아 BG10004 에러가 반환되었다.
Quick Facts#
| Field | Value |
|---|---|
| exception.class | Cupix::Errors::BadGateway |
| exception.message | Migration request failed from evergreen - Unable to retrieve facility info: 401 Unauthorized |
| top_frame | app/operations/migration_operation.rb:64 |
| deploy | production-us-west-2-20260526T0443Z0-dd7bd097-cupixworks |
| env | production, us-west-2 |
Timeline#
- 2026-05-26T04:43:00Z — cupixworks-api 신규 배포 (
dd7bd097) - 2026-05-26T04:45:59.331Z — Evergreen(
cupixworks-migration-service-api)가 Tesla API에 facility 조회 시도, 401 응답 수신 - 2026-05-26T04:46:00.489Z — Tesla(cupixworks-api)에서 Evergreen 응답의 BG10004 에러 로깅
- 2026-05-26T06:30:36.128Z — 동일 패턴의 두 번째 인증 실패 발생 (BG10001, import 경로)
Error Log#
Migration request failed from evergreen - {"result":{"code":"BG10004","type":"Cupix::Errors::BadGateway","reason":"Failed to fetch facility info from tesla server","message":"Unable to retrieve facility info: 401 Unauthorized"}}
Impact#
- Service:
cupixworks-api - 발생 횟수: 1
- 최초 발생: 2026-05-26T04:46:00.489Z
- 최근 발생: 2026-05-26T04:46:00.489Z
사용자 영향: facility 간 마이그레이션 요청 1건 실패. 마이그레이션을 요청한 사용자는 작업을 완료할 수 없었을 것이다. 동일 인증 실패가 이후에도 반복 발생(06:30 UTC)하여 Evergreen 서비스의 Tesla 콜백 전체가 영향받을 수 있다.
Root Cause Summary#
Evergreen 마이그레이션 서비스(cupixworks-migration-service-api)가 Tesla API에서 facility 정보를 조회할 때 사용하는 API 토큰(Y3nBhAX9WKbDK9fNdqME69jvrIXjBfPJ)이 무효하다. Evergreen은 https://api.dev.cupix.works (dev 환경 엔드포인트)를 호출하고 있으며, Tesla는 AUTH10008 "Invalid API token"으로 거부했다. 이는 Evergreen 서비스의 환경 설정 문제로, production Tesla 환경과 통신해야 할 때 dev 환경 엔드포인트와 만료된 토큰을 사용하고 있는 것이 근본 원인이다.
Technical Analysis#
Code Path#
- Entry point:
app/controllers/api/v1/migrations_controller.rb:20—POST /api/v1/migrations요청 수신 - Migration operation:
app/operations/migration_operation.rb:60-61— Evergreen API로 마이그레이션 요청 전송
begin
response = Cupix::HttpClient.post("#{$EVERGREEN[:api_endpoint]}/api/v1/migrations?fields=id", body, { 'x-cupix-auth': $EVERGREEN[:api_key] })
JSON.parse(response)
rescue RestClient::Exception => e
Cupix::Logger.error("Migration request failed from evergreen - #{e.response}", class: self.class.name, function: __method__, error: e.response)
raise Cupix::Errors::BadGateway.new(code: 'BG10001', reason: 'Migration request failed from evergreen', message: JSON.parse(e.response))
end
- Evergreen config (production):
config/environments/production.rb:204-207— Evergreen 엔드포인트 설정
$EVERGREEN = {
api_key: ENV['EVERGREEN_API_KEY'],
api_endpoint: 'https://migration.cupixapis-dev.com'
}
- Failure point: Evergreen 서비스 내부 —
fetch_facility_info함수에서 Tesla API 호출 시 401 수신
실행 흐름:
- Tesla가
https://migration.cupixapis-dev.com/api/v1/migrations에 POST 요청 (x-cupix-auth 헤더로 인증) - Evergreen이 요청을 수신하고, migration 생성 전 facility 정보 검증을 위해 Tesla API를 콜백
- Evergreen이
https://api.dev.cupix.works/api/v1/facilities/6476에 API 토큰Y3nBhAX9WKbDK9fNdqME69jvrIXjBfPJ로 요청 - Tesla가 AUTH10008 "Invalid API token"으로 거부
- Evergreen이 BG10004 에러를 Tesla에 반환
- Tesla가 RestClient::Exception을 catch하고 에러 로깅
핵심 문제: Evergreen 서비스가 api.dev.cupix.works (dev 환경)를 호출하고 있으며, 사용 중인 API 토큰도 무효하다. Production Tesla(cupixworks-api)는 https://migration.cupixapis-dev.com을 호출하는데, 이 Evergreen 인스턴스가 dev 환경으로 설정되어 있어 production Tesla에 올바르게 콜백하지 못한다.
Log Evidence#
Tesla(cupixworks-api) 에러 로그:
service:cupixworks-api status:error @environment:production "Migration request failed from evergreen"
{
"message": "Migration request failed from evergreen - {\"result\":{\"code\":\"BG10004\",\"type\":\"Cupix::Errors::BadGateway\",\"reason\":\"Failed to fetch facility info from tesla server\",\"message\":\"Unable to retrieve facility info: 401 Unauthorized\"}}",
"function": "create_migration_request",
"host": "ip-10-1-144-228.us-west-2.compute.internal",
"deploy": "production-us-west-2-20260526T0443Z0-dd7bd097-cupixworks",
"timestamp": "2026-05-26T04:46:00.489Z"
}
Evergreen(cupixworks-migration-service-api) 에러 로그 — 1초 전 (04:45:59.331Z):
service:cupixworks-migration-service-api status:error
Failed to fetch facility info from https://api.dev.cupix.works/api/v1/facilities/6476?fields=id,key,name,team - {"result":{"code":"AUTH10008","type":"Cupix::Errors::Unauthorized","reason":"Invalid API token: Y3nBhAX9WKbDK9fNdqME69jvrIXjBfPJ","message":"Invalid API token: Y3nBhAX9WKbDK9fNdqME69jvrIXjBfPJ"}}
[Migration] Server 500 error - {:code=>"BG10004", :reason=>"Failed to fetch facility info from tesla server", :message=>"Unable to retrieve facility info: 401 Unauthorized"}
동일 패턴 재발 (06:30:36 UTC):
Export invoke failed from tesla - 401 Unauthorized
[Migration] Server 500 error - {:code=>"BG10001", :reason=>"Import invoke failed from tesla", :message=>"tesla authentication fail"}
Hypotheses Considered#
| # | Hypothesis | Evidence for | Evidence against | Verdict |
|---|---|---|---|---|
| H1 | Evergreen 서비스가 dev 환경 엔드포인트(api.dev.cupix.works)와 만료된 API 토큰으로 Tesla에 콜백하여 인증 실패 |
Evergreen 로그에서 https://api.dev.cupix.works 호출 확인, AUTH10008 "Invalid API token" 응답 확인, 06:30에도 동일 패턴 재발 |
— | Confirmed |
| H2 | Tesla 배포(04:43Z) 시 EVERGREEN_API_KEY가 변경되어 Evergreen이 Tesla로부터 인증 거부 | 배포 시점이 에러 3분 전 | Tesla→Evergreen 방향의 인증은 정상 작동 (Evergreen이 요청을 수신하여 처리 시작), 실패는 Evergreen→Tesla 콜백 방향에서 발생 | Rejected |
| H3 | Facility ID 6476이 존재하지 않아 404 발생 | — | 에러 코드가 AUTH10008 (인증 실패)이지 404가 아님, 토큰 자체가 무효하다고 명시 | Rejected |
Fix Recommendation#
즉시 조치 (Critical)#
- Evergreen 서비스(
cupixworks-migration-service-api)의 환경 설정에서 Tesla API 콜백 URL과 API 토큰을 확인 및 갱신 - Evergreen이 production Tesla(
api.cupix.works또는 해당 리전 엔드포인트)를 호출하도록 설정 변경 필요 - API 토큰
Y3nBhAX9WKbDK9fNdqME69jvrIXjBfPJ를 production에서 유효한 토큰으로 교체
단기 개선 (1주 이내)#
- Evergreen 서비스의 환경별 설정 관리 체계 검토 — production Evergreen이 dev Tesla 엔드포인트를 참조하는 구성 오류가 왜 발생했는지 확인
- Tesla의
$EVERGREEN[:api_endpoint]가migration.cupixapis-dev.com으로 되어 있는데, 이것이 실제로 production Evergreen인지, dev Evergreen인지 명확히 구분하는 네이밍 정리 필요
장기 개선 (재발 방지)#
- 서비스 간 인증 토큰의 유효성을 주기적으로 검증하는 health check 추가
- Evergreen↔Tesla 간 콜백 URL을 하드코딩하지 않고, migration 요청 시
callback_url을 명시적으로 전달하는 방식으로 변경 검토 - 환경 설정에
-devsuffix가 포함된 URL이 production에서 사용되지 않도록 CI/CD 단계에서 검증하는 guard 추가
Monitoring#
- Evergreen 콜백 실패 모니터링:
service:cupixworks-migration-service-api status:error "Failed to fetch facility info"
- Tesla 마이그레이션 에러 모니터링:
service:cupixworks-api status:error "Migration request failed from evergreen"
- AUTH10008 에러 빈도 추적 (토큰 무효화 감지):
service:cupixworks-api "AUTH10008"
Risk Assessment#
- Risk level: medium
- 예상 복잡도: trivial (Evergreen 서비스의 환경 변수 수정으로 해결 가능)