← Back to Pull requests

[ISSUE #7913] Start Kubernetes scaling only on the cluster master #7964

Closed
unknown closed this pull request without merging on Oct 23, 2026 03:18 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 14:34 UTC
Author

Problem

In clustered Admin mode every replica starts Kubernetes scaling independently. ScaleTaskInitializer is a CommandLineRunner, so each Admin loads the scaling policy and registers its own time-window and metric tasks. Master election in ShenyuClusterService owns the upstream and instance check services but never adopts scaling, so followers keep actuating after the lease moves and every replica competes to change the gateway Deployment replicas.

Fixes #7913.

Change

  • ScaleService now has an active gate. executeScaling() is a no-op until start() is called; stop() cancels the dynamic task and both window tasks and clears the applied target.

  • ScaleTaskInitializer is replaced by ScaleLifecycleService, which reloads the policy/rule caches from the database and starts or stops scaling. Activation and deactivation are synchronized.

  • ShenyuClusterService starts scaling after winning the master lease and stops it on the exception path and in finally (normal lease loss or shutdown).

  • ShenyuStandaloneService starts and stops scaling in start() / shutdown(), preserving the previous standalone behavior.

  • /scale/policy and /scale/rule are added to the cluster forward-list, so policy and rule changes issued against a follower are forwarded to the current master instead of being applied locally by a non-owner.
  • Tests

  • ScaleServiceTest: inactive reconciliation is a no-op; start() activates and reconciles; stop() cancels all tasks and is idempotent.

  • ScaleLifecycleServiceTest: caches reload on every activation; stop() delegates.

  • ShenyuClusterServiceTest: the master lifecycle calls start/stop, the error path stops twice safely, and no start happens when the lease is not won.

  • ShenyuStandaloneServiceTest: start/shutdown delegation order.
  • All 26 targeted tests pass and checkstyle reports 0 violations (Java 17).

    Known gaps (out of scope)

  • MetricsMonitor.addObserver() has no production caller, so the policy-3 observer path remains unwired. This predates this change.

  • On a normal lease loss the existing code still does not close the upstream/instance check services; this change only ensures scaling is stopped.
  • Diff: 276 lines (+207 / -69) across 3 files Reviewer: Aias00 Review duration: 2204m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.63) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 276 lines diff across 3 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.336
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.063
    Real PR Conversation Timeline
    1 comments
    "Review active on #7964"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.7% (MEDIUM) · Higher = larger blast radius
    62.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.8% · Safe to merge
    24.8%
    Repository