Skip to content

Fix BalancerUtil to pick up all Clusters: port changes from f57e1b6 to 7.X#2952

Merged
predic8 merged 4 commits into
masterfrom
BalancerUtil-fix
May 22, 2026
Merged

Fix BalancerUtil to pick up all Clusters: port changes from f57e1b6 to 7.X#2952
predic8 merged 4 commits into
masterfrom
BalancerUtil-fix

Conversation

@christiangoerdes
Copy link
Copy Markdown
Collaborator

@christiangoerdes christiangoerdes commented May 22, 2026

Summary by CodeRabbit

  • Refactor
    • Streamlined discovery of load balancers and clusters by unifying flows across router and global configuration sources with improved deduplication.
    • Standardized lookup behavior for load balancers and their interceptors, with consistent case-insensitive matching.
    • Improved error messages for lookup failures and simplified presence checks for load balancing.

Review Change Stack

@christiangoerdes
Copy link
Copy Markdown
Collaborator Author

/ok-to-test

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

BalancerUtil is refactored to consolidate balancer and cluster discovery through a new stream-based helper (allFlows) that aggregates flows from the router's rule manager and optional registry/bean factory sources. Collection methods now deduplicate results and support extended sources; lookup methods use the same aggregation with case-insensitive matching and formatted error messages.

Changes

Stream-Based Balancer Discovery Consolidation

Layer / File(s) Summary
Stream aggregation helper
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java
New allFlows(Router) helper constructs a stream of interceptor flows by aggregating from the router's rule manager, optional registry, and optional bean factory, then flattens into a single flow stream.
Collection methods refactoring
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java
collectBalancers() uses the new allFlows() helper, filters for LoadBalancingInterceptor, removes nulls, deduplicates via distinct(), and returns an immutable list. collectClusters() aggregates clusters from all discovered balancers and also includes clusters from Balancer beans found in registry/bean factory, with deduplication applied to the combined result.
Lookup methods modernization
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java
lookupBalancer() and lookupBalancerInterceptor() are updated to search across aggregated flows, perform case-insensitive name matching, and throw RuntimeException with String.formatted() error messages when no match is found. hasLoadBalancing() now returns whether collectBalancers(router) is non-empty.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • rrayst

Poem

I nibble through flows in a tunnel so deep,
Merging branches and lists while others sleep,
Streams hum like carrots in orderly rows,
Deduped and tidy — the balancer grows,
A rabbit's small cheer for code that springs leaps. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references a specific commit hash (f57e1b6) and version line (7.X) to be ported, and accurately describes the main change: fixing BalancerUtil to pick up all Clusters. It is clear and directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BalancerUtil-fix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@membrane-ci-server
Copy link
Copy Markdown

This pull request needs "/ok-to-test" from an authorized committer.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java (1)

131-133: ⚡ Quick win

Consider short-circuiting for existence check.

collectBalancers(router).isEmpty() materializes the entire list just to check if at least one balancer exists. Using a stream with findFirst() or anyMatch() 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

📥 Commits

Reviewing files that changed from the base of the PR and between fc0ea8b and 7f59445.

📒 Files selected for processing (1)
  • core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java

@predic8 predic8 merged commit b6622e0 into master May 22, 2026
5 checks passed
@predic8 predic8 deleted the BalancerUtil-fix branch May 22, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

balancerHealthMonitor doesn't work with 7.2.1 when balancer is defined with chain component

2 participants