Neymar-10-JR opened a new pull request, #7848:
URL: https://github.com/apache/shenyu/pull/7848

   Closes #7702.
   
   Concurrent requests currently check completed usage before forwarding, so an 
in-flight burst can all observe the same remaining budget. This adds an 
explicit `reservationEnabled` policy with a configured per-request 
completion-token estimate. With a 20-token available budget and 10-token 
estimates, only two of three overlapping requests are forwarded; the third 
receives HTTP 429. Existing rules retain their completed-usage threshold by 
default.
   
   ### Changes
   
   - Atomically reserve and reconcile capacity in Redis using immutable fixed 
windows selected with Redis time. Retries are idempotent; stale admission 
cannot recreate an expired window, and late completion cannot charge a new 
window.
   - Compose settlement and cancellation cleanup with the reactive request 
lifecycle. Release confirmed unforwarded requests; hold unknown upstream usage 
until reliable settlement or window expiry. Reported zero is distinct from 
absent usage.
   - Validate opt-in settings in Admin before persistence/publication 
(including imports), and at the gateway cache boundary, using one shared 
contract. Add matching form fields and boolean dictionary choices to 
fresh-install and upgrade SQL.
   - Report estimated reservations, reliable reported usage and bounded 
lifecycle/rejection events through the existing metrics plugin. Add a required 
Redis-backed CI job and document policy boundaries.
   
   ### Validation
   
   - 232 related tests passed, with zero failures, errors or skips, including 
50 real Redis tests across independent clients, the metrics module suite and 
Admin write-boundary/seed tests.
   - Checkstyle, scoped Apache RAT checks and `git diff --check` passed. Oracle 
seed tests use the real Oracle DDL with H2 Oracle identifier folding and 
caught/fixed a quoted-identifier regression.
   - The Maven command configured in the new CI job was replayed locally:
   
   ```bash
   ./mvnw -B -ntp -pl 
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-token-limiter,shenyu-plugin/shenyu-plugin-metrics,shenyu-admin
 -am test 
'-Dtest=AiTokenLimiterHandleTest,TokenBudget*Test,RedisTokenBudgetStore*Test,AiTokenLimiterPlugin*Test,AiTokenLimiterRuleHandlerTest,AiTokenLimiterReservation*Test,AiTokenBudgetMetricsTest,AiTokenReservationConfigurationTest,AiTokenLimiterRuleHandleValidatorTest,RuleServiceTest,MetricsPluginTest,MetricsReporterTest,PrometheusMetricsRegisterTest,PrometheusMetricsServiceTest,MetricTest'
 -Dsurefire.failIfNoSpecifiedTests=false -DskipTests=false 
-Dshenyu.test.redis.port=16379 -DskipRemoteResources=true -Djacoco.skip=true 
-Dmaven.javadoc.skip=true
   ```
   
   Full-repository `./mvnw clean install -Dmaven.javadoc.skip=true` has not 
been run. GitHub Actions and native database matrix results are pending; local 
SQL tests use H2, not native database engines.
   
   ### Boundaries
   
   Reservations constrain estimates, not exact future consumption. Usage above 
an estimate is recorded in full; unknown usage can reduce available capacity 
until expiry. Request markers expire with their window and do not have a 
separate cardinality cap. The existing bounded response parser is retained: 
unsupported or unparseable usage, including its documented 
large-body/fragmentation limits, conservatively retains capacity. No claim of a 
hard actual-token limit or full streaming-parser replacement is made.
   
   Make sure that:
   
   - [ ] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide/).
   - [x] You submit test cases (unit or integration tests) that back your 
changes.
   - [ ] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to