feat: add computation quotas check#1013
Conversation
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (24)
📝 WalkthroughWalkthroughAdds per-computation quota types and REST operations, enforces quotas before computation запуск, tracks active operations, releases quotas on completion, and updates configuration and tests for the new quota API. ChangesQuota model and REST integration
Computation quota lifecycle
Sequence Diagram(s)sequenceDiagram
participant Client
participant StudyController
participant StudyService
participant UserAdminService
participant ConsumerService
Client->>StudyController: run computation
StudyController->>StudyService: assertOnQuotasAvailability(computationType, userId)
StudyService->>UserAdminService: get current and maximum quotas
StudyController->>StudyService: start computation
StudyService->>UserAdminService: startOperationWithQuota(...)
ConsumerService->>UserAdminService: endOperationWithQuota(...)
ConsumerService-->>Client: computation status/result notification
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
03724ef to
05ec476
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/test/java/org/gridsuite/study/server/utils/TestUtils.java (2)
239-264: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicated
removeServeEventsMatchingpair across the two teardown helpers.Consider extracting a small private helper (e.g.
removeQuotaServeEvents(WireMockServer)) to avoid repeating the same two lines inassertWiremockServerRequestsEmptyThenShutdownandassertWiremockServerRequestsEmptyThenClear.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/org/gridsuite/study/server/utils/TestUtils.java` around lines 239 - 264, The two teardown helpers, assertWiremockServerRequestsEmptyThenShutdown and assertWiremockServerRequestsEmptyThenClear, repeat the same removeServeEventsMatching calls for the quota start/end URLs. Extract that duplicated logic into a small private helper such as removeQuotaServeEvents(WireMockServer) and call it from both methods so the quota-event cleanup is centralized and easier to maintain.
112-140: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winNarrow the quota-skip regex to avoid masking legitimate GET
/quota/maxverification.
"/v1/users/.*/quota/.*"also matches a GET.../quota/maxrequest, not just the start/end tracking calls it's meant to filter out. This differs from the preciseUserAdminServerStubs.QUOTA_START_URL_PATTERN/QUOTA_END_URL_PATTERN(which require a/startor/endsuffix) already imported in this file. If a future MockWebServer-based test needs to verify the max-quota check call, this broader filter would silently skip it.♻️ Suggested fix reusing the precise patterns
do { recordedRequest = Objects.requireNonNull(server.takeRequest(TIMEOUT, TimeUnit.MILLISECONDS)); // skip quota start/end requests that are auto-handled and not part of test assertions - } while (recordedRequest.getPath() != null && recordedRequest.getPath().matches("/v1/users/.*/quota/.*")); + } while (recordedRequest.getPath() != null + && (recordedRequest.getPath().matches(UserAdminServerStubs.QUOTA_START_URL_PATTERN) + || recordedRequest.getPath().matches(UserAdminServerStubs.QUOTA_END_URL_PATTERN)));Apply the same change in
getRequestsDone.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/org/gridsuite/study/server/utils/TestUtils.java` around lines 112 - 140, The quota-request filtering in TestUtils.assertRequestMatches and getRequestsDone is too broad and can accidentally skip legitimate GET /quota/max calls. Replace the generic "/v1/users/.*/quota/.*" match with the precise quota start/end patterns already available in this file via UserAdminServerStubs.QUOTA_START_URL_PATTERN and UserAdminServerStubs.QUOTA_END_URL_PATTERN, and apply the same narrowing in both helper methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/gridsuite/study/server/service/ConsumerService.java`:
- Around line 402-405: The quota release path in ConsumerService’s handler only
checks userId before calling userAdminService.endOperationWithQuota, so it can
pass a null resultUuid and build a malformed quota URL. Update the free-quota
block to require both userId and resultUuid before invoking
endOperationWithQuota, matching the guard already used in the stopped handler,
and keep the call to OperationType.mapFromComputationType(computationType)
unchanged.
---
Nitpick comments:
In `@src/test/java/org/gridsuite/study/server/utils/TestUtils.java`:
- Around line 239-264: The two teardown helpers,
assertWiremockServerRequestsEmptyThenShutdown and
assertWiremockServerRequestsEmptyThenClear, repeat the same
removeServeEventsMatching calls for the quota start/end URLs. Extract that
duplicated logic into a small private helper such as
removeQuotaServeEvents(WireMockServer) and call it from both methods so the
quota-event cleanup is centralized and easier to maintain.
- Around line 112-140: The quota-request filtering in
TestUtils.assertRequestMatches and getRequestsDone is too broad and can
accidentally skip legitimate GET /quota/max calls. Replace the generic
"/v1/users/.*/quota/.*" match with the precise quota start/end patterns already
available in this file via UserAdminServerStubs.QUOTA_START_URL_PATTERN and
UserAdminServerStubs.QUOTA_END_URL_PATTERN, and apply the same narrowing in both
helper methods.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bd8f74b1-33af-4c41-a8f8-f55735d4b2f6
📒 Files selected for processing (24)
src/main/java/org/gridsuite/study/server/controller/StudyController.javasrc/main/java/org/gridsuite/study/server/dto/OperationType.javasrc/main/java/org/gridsuite/study/server/dto/UserProfileInfos.javasrc/main/java/org/gridsuite/study/server/error/StudyBusinessErrorCode.javasrc/main/java/org/gridsuite/study/server/service/ConsumerService.javasrc/main/java/org/gridsuite/study/server/service/StudyService.javasrc/main/java/org/gridsuite/study/server/service/UserAdminService.javasrc/main/resources/config/application.yamlsrc/test/java/org/gridsuite/study/server/NetworkModificationTest.javasrc/test/java/org/gridsuite/study/server/NodeSequenceTest.javasrc/test/java/org/gridsuite/study/server/ShortCircuitTest.javasrc/test/java/org/gridsuite/study/server/StateEstimationTest.javasrc/test/java/org/gridsuite/study/server/StudyControllerDynamicMarginCalculationTest.javasrc/test/java/org/gridsuite/study/server/StudyControllerDynamicSecurityAnalysisTest.javasrc/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.javasrc/test/java/org/gridsuite/study/server/StudyServiceTest.javasrc/test/java/org/gridsuite/study/server/VoltageInitTest.javasrc/test/java/org/gridsuite/study/server/dto/OperationTypeTest.javasrc/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.javasrc/test/java/org/gridsuite/study/server/service/StudyServiceDynamicSimulationTest.javasrc/test/java/org/gridsuite/study/server/service/UserAdminServiceTest.javasrc/test/java/org/gridsuite/study/server/utils/TestUtils.javasrc/test/java/org/gridsuite/study/server/utils/wiremock/UserAdminServerStubs.javasrc/test/resources/application-default.yml
e8a8de9 to
4de5dc8
Compare
feat: fix tests feat: add test
4de5dc8 to
b4accf1
Compare
etiennehomer
left a comment
There was a problem hiding this comment.
Not enough time to test and to review UT
But i'm ok with the global design
5997533 to
8ba7287
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/org/gridsuite/study/server/service/ConsumerService.java (1)
514-524: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract
userIdonce to avoid redundancy.The
userIdis currently being extracted from the headers in two separate places. You can declare it once before the condition to improve readability and avoid the redundant lookup.♻️ Proposed refactor
- if (computationType == LOAD_FLOW) { - String userId = (String) msg.getHeaders().get(HEADER_USER_ID); - handleLoadFlowSuccess(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), resultUuid, userId); - } - - // free quota - String userId = msg.getHeaders().get(HEADER_USER_ID, String.class); + String userId = msg.getHeaders().get(HEADER_USER_ID, String.class); + + if (computationType == LOAD_FLOW) { + handleLoadFlowSuccess(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), resultUuid, userId); + } + + // free quota if (userId != null) { userAdminService.endOperationWithQuota(userId, QuotaType.mapFromComputationType(computationType), resultUuid); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/org/gridsuite/study/server/service/ConsumerService.java` around lines 514 - 524, In the surrounding computation-success flow, extract the typed userId from msg headers once before the LOAD_FLOW condition, then reuse it for handleLoadFlowSuccess and the quota cleanup block. Remove the duplicate declaration while preserving the existing null check and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/gridsuite/study/server/dto/QuotaType.java`:
- Line 22: Rename the QuotaType enum constant BALANCE_ADJUSTEMENT to
BALANCE_ADJUSTMENT and update all references to use the corrected spelling
consistently.
---
Nitpick comments:
In `@src/main/java/org/gridsuite/study/server/service/ConsumerService.java`:
- Around line 514-524: In the surrounding computation-success flow, extract the
typed userId from msg headers once before the LOAD_FLOW condition, then reuse it
for handleLoadFlowSuccess and the quota cleanup block. Remove the duplicate
declaration while preserving the existing null check and behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 95646310-6cd4-4a1f-b82d-90f49d303d9e
📒 Files selected for processing (10)
src/main/java/org/gridsuite/study/server/dto/QuotaType.javasrc/main/java/org/gridsuite/study/server/dto/UserProfileInfos.javasrc/main/java/org/gridsuite/study/server/service/ConsumerService.javasrc/main/java/org/gridsuite/study/server/service/StudyService.javasrc/main/java/org/gridsuite/study/server/service/UserAdminService.javasrc/test/java/org/gridsuite/study/server/NodeSequenceTest.javasrc/test/java/org/gridsuite/study/server/StudyServiceTest.javasrc/test/java/org/gridsuite/study/server/dto/QuotaTypeTest.javasrc/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.javasrc/test/java/org/gridsuite/study/server/service/UserAdminServiceTest.java
🚧 Files skipped from review as they are similar to previous changes (6)
- src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java
- src/test/java/org/gridsuite/study/server/service/UserAdminServiceTest.java
- src/main/java/org/gridsuite/study/server/dto/UserProfileInfos.java
- src/main/java/org/gridsuite/study/server/service/UserAdminService.java
- src/test/java/org/gridsuite/study/server/StudyServiceTest.java
- src/main/java/org/gridsuite/study/server/service/StudyService.java
8ba7287 to
96c6a8b
Compare
|



PR Summary