feat(school): 학교 클라이언트에 rate limiter 적용#281
Conversation
📝 WalkthroughWalkthroughAdds Resilience4j rate limiting to SchoolClient by annotating three deprecated methods with Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant SchoolClient
participant RateLimiterAspect as RateLimiter (Resilience4j)
participant ExternalAPI
Caller->>SchoolClient: call getSchools(...)
SchoolClient->>RateLimiterAspect: aspect intercepts call
alt within limit
RateLimiterAspect->>SchoolClient: proceed
SchoolClient->>ExternalAPI: perform request
ExternalAPI-->>SchoolClient: response
SchoolClient-->>Caller: return response
else limit exceeded or timeout
RateLimiterAspect-->>SchoolClient: trigger fallback
SchoolClient-->>Caller: return fallback (empty/null) and log warning
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Summary of ChangesHello @huhdy32, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 외부 학교 클라이언트에 Rate Limiter를 적용하여 외부 API 호출을 제어하고 과도한 요청으로 인한 서비스 장애를 방지하는 것을 목표로 합니다. Resilience4j 라이브러리를 활용하여 특정 메서드에 Rate Limiter를 설정하고, 제한을 초과할 경우 정의된 폴백 메서드를 통해 안정적으로 처리하도록 구현되었습니다. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이 PR은 외부 NEIS API에 대한 과도한 호출을 방지하기 위해 Resilience4j를 사용하여 SchoolClient에 rate limiter를 도입합니다. Rate limit이 적용된 함수들에 대해 폴백 메서드가 추가되었으며, 이 메서드들은 rate limit을 초과했을 때 경고를 로깅하고 기본 응답을 반환합니다. 변경 사항은 논리적이며 rate limiting 패턴을 올바르게 구현했습니다. 제 리뷰에는 새로운 메서드의 파라미터에 final을 사용하여 코드 일관성을 개선하고, 폴백 응답을 생성할 때 null 사용을 피하는 제안이 포함되어 있습니다. 또한 rate limiter와 폴백 메커니즘이 예상대로 작동하는지 확인하기 위한 테스트 케이스를 추가할 것을 권장합니다.
...ternal/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java
Show resolved
Hide resolved
...ternal/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java
Show resolved
Hide resolved
...ternal/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java
Show resolved
Hide resolved
...ternal/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java
Show resolved
Hide resolved
...al/mathrank-school/src/test/java/kr/co/mathrank/client/external/school/SchoolClientTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In
@client/external/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java:
- Line 45: Update all production call sites to use the public wrapper methods on
SchoolClient (getSchoolResponse and getSchoolsResponse) instead of directly
invoking the deprecated, rate-limited methods (getSchool and getSchools) so the
centralized error handling in RestClientResponseDecorator (which decorates the
deprecated methods) is applied; change callers in ProblemReadQueryService,
SchoolLocationManager, RankReadController, MemberDetailQueryController, and
SchoolQueryService to call getSchoolResponse/getSchoolsResponse, and after
verifying all callers use the wrappers you may move the @RateLimiter annotation
from the deprecated methods into the wrapper methods if desired.
In
@client/external/mathrank-school/src/test/java/kr/co/mathrank/client/external/school/SchoolClientTest.java:
- Around line 16-18: Add the resilience4j rate limiter settings used in tests
into production properties so SchoolClient uses the same limits in runtime:
create or update the module's production application.properties and add the
three keys resilience4j.ratelimiter.instances.neiceApi.limit-refresh-period=1s,
resilience4j.ratelimiter.instances.neiceApi.limit-for-period=100, and
resilience4j.ratelimiter.instances.neiceApi.timeout-duration=1s; keep the
instance name neiceApi (it is referenced by the @RateLimiter annotations in
SchoolClient and used by MemberDetailQueryController and RankReadController).
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client/external/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.javaclient/external/mathrank-school/src/test/java/kr/co/mathrank/client/external/school/SchoolClientTest.java
🧰 Additional context used
🧬 Code graph analysis (1)
client/external/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java (2)
client/mathrank-client-config/src/main/java/kr/co/mathrank/client/config/RestClientResponseDecorator.java (1)
Slf4j(12-27)domain/mathrank-problem-domain/src/main/java/kr/co/mathrank/domain/problem/service/SchoolLocationManager.java (1)
Slf4j(14-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
🔇 Additional comments (2)
client/external/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java (2)
14-14: LGTM: Required imports and logging added correctly.The imports for
@RateLimiterand@Slf4jare necessary for the rate limiting functionality and fallback logging.Also applies to: 23-23, 25-25
89-92: Remove this review comment — the concern is unfounded.
SchoolResponse.getSchoolInfo()explicitly checks for null at line 16 and safely returns an empty list whenschoolInfois null. NoNullPointerExceptionwill occur when callers invokegetSchoolInfo()on the fallback response.Likely an incorrect or invalid review comment.
...ternal/mathrank-school/src/main/java/kr/co/mathrank/client/external/school/SchoolClient.java
Show resolved
Hide resolved
...al/mathrank-school/src/test/java/kr/co/mathrank/client/external/school/SchoolClientTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
client/external/mathrank-school/build.gradle (1)
3-4: Version 2.2.0 is stable and secure; consider upgrading to 2.3.0 if you want to stay current.The dependencies are appropriate for implementing rate limiting with Resilience4j annotations. Version 2.2.0 (released Sep 2024) has no known security vulnerabilities. However, 2.3.0 is now available; upgrading is optional but recommended if you want to track the latest stable release.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
client/external/mathrank-school/build.gradle
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.