imDwAaY opened a new pull request, #7886:
URL: https://github.com/apache/shenyu/pull/7886
### Motivation
Fixes #7706.
`ScaleService.executeScaling()` evaluated a time-window policy only at the
moment it was called. Its only callers are startup and the post-commit policy
update path, so an enabled policy whose `beginTime` was still in the future
never activated when the window opened. The window end was equally unhandled,
and an enabled time-window policy shadowed lower-priority policies even outside
its window.
### Modification
- `TaskSchedulerManager.registerOnceTask(...)`: one-shot scheduling. The
wrapper publishes the future and registry entry before execution, and removes
its own entry before running the task so a callback that triggers
reconciliation cannot cancel or interrupt itself.
- `ScaleService` now reconciles on every evaluation:
- cancels stale boundary tasks, then schedules an activation task for a
still-future window;
- applies the target and schedules a deactivation task when inside the
window;
- selects only policies eligible at the current instant, treating a null
begin/end as unbounded, so a time-window policy yields to lower-priority
policies outside its window;
- caches the applied `(policyId, num)` target and updates it only when the
Kubernetes call succeeds, avoiding repeated writes and allowing failed requests
to be retried;
- uses an injectable `Clock` for deterministic tests.
- `KubernetesScaler.scaleByNum` now reports whether the request succeeded.
### Tests
- `ScaleServiceTest`: future window schedules activation; an open window
applies and schedules deactivation; repeated reconciliation is idempotent; an
expired window falls back to a fixed policy; unbounded windows; the activation
callback applies at window start; a new window re-applies after a period with
no active policy.
- `TaskSchedulerManagerTest`: a one-shot task fires exactly once and is
removed from the registry.
Verification:
- `./mvnw -pl shenyu-admin -am -DskipTests -Drat.skip=true
-Djacoco.skip=true -Dmaven.javadoc.skip=true install` — success
- `./mvnw -pl shenyu-admin test
-Dtest='ScaleServiceTest,TaskSchedulerManagerTest,KubernetesScalerTest'` — 16
tests, 0 failures
- `./mvnw -pl shenyu-admin validate` — 0 checkstyle violations
--
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]