Skip to content

fix(proxy): attribute upstream error logs to the route that failed - #761

Open
vkehfdl1 wants to merge 1 commit into
devfrom
fix/lh-detail-error-attribution
Open

vkehfdl1 wants to merge 1 commit into
devfrom
fix/lh-detail-error-attribution

Conversation

@vkehfdl1

@vkehfdl1 vkehfdl1 commented Nov 2, 2026

Copy link
Copy Markdown
Member

무엇을 고쳤나

packages/k-skill-proxy/src/server.js의 업스트림 오류 귀인(warn) 로그에서, 실제로 실패한 핸들러와 다른 route가 기록되던 문제를 수정합니다.

  • /v1/lh-notice/detail catch: route: "/v1/korean-stock/trade-info" / "KRX upstream error" → route: "/v1/lh-notice/detail" / "LH upstream error"
  • /v1/lh-notice/search catch: route: "/v1/korean-stock/base-info" → route: "/v1/lh-notice/search" / "LH upstream error"
  • /v1/parking-lots/search catch: route: "/v1/korean-stock/search" → route: "/v1/parking-lots/search" / "parking lots upstream error"
  • KRX /v1/korean-stock/search·base-info·trade-info catch에는 귀인 로그가 아예 없어서, 각 라우트의 실제 route로 warn 로그를 추가

응답 status/body는 변경하지 않았습니다(502 계약 유지).

왜

로그의 KRX upstream error 중 상당수가 실제로는 LH(다른 업스트림) 요청에서 발생해, 24h 집계에서 KRX 502가 과대집계되고 LH 오류가 KRX로 잘못 귀인됩니다(이슈 #641). routeUsage는 실제 라우트를 기록하므로, 상세 error log의 route가 routeUsage의 route와 일치해야 합니다.

검증 (failing-before → passing-after)

packages/k-skill-proxy/test/server.test.js에 로거 캡처 테스트 4개 추가. 수정 전 origin/dev에서 4개 모두 실패, 수정 후 통과:

  • lh-notice detail upstream failure is attributed to /v1/lh-notice/detail, never to KRX
    • before: expected a warn log attributed to /v1/lh-notice/detail, got [{"route":"/v1/korean-stock/trade-info",...}]
  • lh-notice search upstream failure is attributed to /v1/lh-notice/search
  • parking-lots search upstream failure is attributed to /v1/parking-lots/search
  • korean stock trade-info upstream failure is attributed to /v1/korean-stock/trade-info (before: 이 라우트는 로그 자체가 없어 실패)

로컬: node --test → 490 pass / 0 fail / 2 skipped, npm run lint 통과.

live "before" 관찰 (프로덕션은 아직 이 PR 반영 전)

$ curl -sS -m 30 -G 'https://k-skill-proxy.nomadamas.org/v1/lh-notice/detail' \
    --data-urlencode 'panId=2015122300019828' \
    --data-urlencode 'ccrCnntSysDsCd=03' \
    --data-urlencode 'splInfTpCd=051'
{"error":"upstream_error","message":"LH upstream responded with HTTP 403: { ... \"returnReasonCode\": \"30\" ... }","proxy":{"name":"k-skill-proxy","cache":{"hit":false,"ttl_ms":300000}}}
HTTP 502

/v1/lh-notice/search는 동일 시점 HTTP 200으로 정상 동작합니다. 프로덕션 키의 SERVICE_KEY_IS_NOT_REGISTERED_ERROR(returnReasonCode 30)는 별도 ops 이슈로 본 PR 범위가 아니며, 502 응답 계약은 그대로 유지됩니다.

범위

LH detail 실패 로그가 KRX trade-info로, LH search 로그가 KRX base-info로, parking-lots 로그가 KRX search로 잘못 귀인되던 문제를 수정하고, 정작 KRX search/base-info/trade-info 라우트에는 귀인 로그가 없던 것을 각 라우트별로 추가했다. 응답 본문은 변경하지 않았다.

Refs #641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant