[REFAC#503] rate_limit 로그에 label 필드 추가 — throttled 호스트/IP 사후 추적 가능 - #514
Conversation
) - NewRateLimiter 시그니처 확장: (rph, burst, label string) — label 은 throttle 로그의 추적 식별자 - TokenBucketRateLimiter 가 label 필드 보존 - 3개 Debug 로그 모두에 label 필드 emit: - "rate limit reached, waiting for token" - "rate limit wait completed" - "rate limit wait context done" - IP registry 의 단일 production 호출처 (ip_registry.go:130) 갱신 — IP 그대로 label 로 전달 - 테스트 호출처 12곳 일괄 갱신 (간단 "test" label) - 단위 테스트 4건 신규: label emit 검증 (Reached / Completed / ContextCancelled) + EmptyLabel 도 필드 부착 검증 운영 회복: 라이브에서 'rate=0.028' 등 극단 throttle 로그가 어느 호스트/IP 인지 즉시 식별 가능. PR #509 머지 후 라이브 51분 동안 137회 throttle 발화에서 host 정보 부재로 디버깅 출발점 부재했던 문제 해소. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR adds a ChangesRate limiter label tracking for IP throttling identification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a label field to the TokenBucketRateLimiter to improve log traceability, allowing for the identification of specific IPs or hosts being throttled. The NewRateLimiter constructor signature was updated to include this label, and the Wait method now includes it in debug logs. Related tests and the IP registry were updated to support this change, and new test cases were added to verify label emission. I have no feedback to provide as there were no review comments.
There was a problem hiding this comment.
Pull request overview
이 PR은 TokenBucketRateLimiter의 throttle 관련 Debug 로그에 추적 식별자(label: host/IP 등)를 포함시켜, 운영 환경에서 어떤 대상이 rate limit에 걸렸는지 사후 추적 가능하도록 observability를 보강합니다.
Changes:
TokenBucketRateLimiter에label필드를 추가하고,NewRateLimiter(requestsPerHour, burst, label string)로 생성자 시그니처를 확장- throttle 관련 3개 Debug 로그에
label필드 emit - 프로덕션 호출부(
IPRateLimiterRegistry) 및 테스트 호출부에서 신규 시그니처로 갱신, label 로그 검증 테스트 추가
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/processor/fetcher/rate_limiter/token_bucket.go | limiter에 label 저장 및 throttle 로그에 label 필드 추가(생성자 시그니처 변경 포함) |
| internal/processor/fetcher/rate_limiter/ip_registry.go | IP 기반 registry에서 limiter 생성 시 IP를 label로 전달 |
| test/internal/processor/fetcher/rate_limiter/token_bucket_test.go | 생성자 호출 갱신 + throttle 로그에 label이 포함되는지 단위 테스트 4건 추가 |
| test/internal/processor/fetcher/rate_limiter/ip_registry_test.go | 생성자 호출 시그니처 변경 반영 |
Comments suppressed due to low confidence (1)
internal/processor/fetcher/rate_limiter/token_bucket.go:103
ctx_err필드에error값을 그대로 넣으면 zerolog JSON marshal 결과가{}로 찍혀 실제 에러 문자열이 남지 않을 가능성이 큽니다(예:context.Canceled).ctx_err에는ctxErr.Error()같은 문자열을 넣거나,log.WithError(ctxErr)를 사용해 표준error필드로 기록하도록 변경하는 게 로그 추적에 더 안전합니다.
case <-ctx.Done():
ctxErr := ctx.Err()
log.WithFields(map[string]interface{}{
"label": r.label,
"wait_count": waitCount,
"rate": r.rate,
"burst": r.burst,
"ctx_err": ctxErr,
}).Debug("rate limit wait context done")
연관 이슈
구현 내용
라이브 회차에서 관측된
rate limit reached, waiting for token로그 137회 발화에host/ip정보 부재 — 어느 호스트가 throttled 인지 디버깅 출발점 없던 observability 갭 보강.변경 사항
1)
pkg//internal/시그니처 확장internal/processor/fetcher/rate_limiter/token_bucket.go:TokenBucketRateLimiter에label string필드 추가NewRateLimiter(rph, burst int, label string)— 신규 인자 추가 (issue 본문 옵션 A)2) 3개 Debug 로그 모두에
label필드 emitrate limit reached, waiting for tokenrate limit wait completedrate limit wait context done3) Production 호출처 갱신
internal/processor/fetcher/rate_limiter/ip_registry.go:130:같은 IP 의 모든 host 가 limiter 를 공유하므로 host 보다 IP 가 정확한 식별자.
4) 테스트 호출처 12곳 일괄 갱신
token_bucket_test.go11곳 +ip_registry_test.go1곳 모두"test"label 로 갱신.단위 테스트 4건 신규
TestRateLimiter_Wait_LogsLabelOnReached— wait 시작 로그에 IP label emitTestRateLimiter_Wait_LogsLabelOnCompleted— wait 완료 로그에 host label emitTestRateLimiter_Wait_LogsLabelOnContextCancelled— ctx cancel 로그에 label emitTestRateLimiter_EmptyLabel_StillEmits— 빈 label 도 JSON 필드 부착 ("label":"")운영 회복
라이브에서
rate=0.028(≈ 1req/36s) 의 극단 throttle 이 발화하더라도 다음과 같이 즉시 식별 가능:{ "level": "debug", "label": "203.0.113.42", "rate": 0.028, "burst": 10, "wait_ms": 34935, "message": "rate limit reached, waiting for token" }CI / 머지 게이트 점검
변경 영향 범위
internal/processor/fetcher/rate_limiter(시그니처 변경)Low— 시그니처 변경이지만 production 호출처는 1곳 (ip_registry), 그 외는 모두 test. 로그 추가만 (분기/동작 무변경).Required Status Checks
Commit LintPR Title LintLinked Issue CheckFormat CheckBuildTestLint롤백 계획
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Refactor
Tests