Fix BalancerUtil to pick up all Clusters: port changes from f57e1b6 to 7.X#2952
Conversation
|
/ok-to-test |
📝 WalkthroughWalkthrough
ChangesStream-Based Balancer Discovery Consolidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
This pull request needs "/ok-to-test" from an authorized committer. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java (1)
131-133: ⚡ Quick winConsider short-circuiting for existence check.
collectBalancers(router).isEmpty()materializes the entire list just to check if at least one balancer exists. Using a stream withfindFirst()oranyMatch()would short-circuit on the first match.♻️ Proposed short-circuit implementation
public static boolean hasLoadBalancing(Router router) { - return !collectBalancers(router).isEmpty(); + return allFlows(router) + .flatMap(List::stream) + .anyMatch(LoadBalancingInterceptor.class::isInstance); }🤖 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 `@core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java` around lines 131 - 133, The current hasLoadBalancing method calls collectBalancers(router).isEmpty(), which builds the full list; change hasLoadBalancing to short-circuit by scanning for the first matching balancer instead of materializing the list—use a stream-based anyMatch/findFirst over the router’s interceptor/rule sources (so hasLoadBalancing returns true as soon as one balancer is found). Keep references to the existing methods: update hasLoadBalancing to avoid calling collectBalancers(router) and instead perform a short-circuiting search (anyMatch/findFirst) over the router’s interceptors/rules to detect a balancer.
🤖 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.
Nitpick comments:
In
`@core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java`:
- Around line 131-133: The current hasLoadBalancing method calls
collectBalancers(router).isEmpty(), which builds the full list; change
hasLoadBalancing to short-circuit by scanning for the first matching balancer
instead of materializing the list—use a stream-based anyMatch/findFirst over the
router’s interceptor/rule sources (so hasLoadBalancing returns true as soon as
one balancer is found). Keep references to the existing methods: update
hasLoadBalancing to avoid calling collectBalancers(router) and instead perform a
short-circuiting search (anyMatch/findFirst) over the router’s
interceptors/rules to detect a balancer.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b7f9df70-7dab-481a-ac1a-f1d2722266dc
📒 Files selected for processing (1)
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java
Summary by CodeRabbit