tmielke opened a new pull request, #27576:
URL: https://github.com/apache/camel/pull/27576
# Description
The CAMEL-24590 fix (4.22.1) correctly shared a single `ManagedRouteGroup`
instance across all routes in a group, fixing broken `failuresHandled` stats.
However, it also broke exchange counting: the group MBean now counts each
exchange **once per member route** instead of **once per exchange**. For
example, a message traversing 2 routes in a group reports `ExchangesCompleted
== 2` instead of `1`.
## Approach
Fix by deduplicating in `ManagedRouteGroup` using the same route stack
level approach that `ManagedCamelContext` already uses (CAMEL-18557). A new
`UnitOfWork.routeStackLevel(Predicate<Route>)` default method filters the route
stack by group name, so an exchange event (process, completed, failed) is only
counted when the current route is the **outermost route of its group** on the
exchange's route stack.
### Production changes (3 files, ~46 lines)
- **`UnitOfWork.java`** — new `default int
routeStackLevel(Predicate<Route>)` method (`@since 4.23`)
- **`DefaultUnitOfWork.java`** — implementation iterating the route stack
under the existing lock
- **`ManagedRouteGroup.java`** — override `processExchange`,
`completedExchange`, `failedExchange` with the group dedup guard
### Test changes (4 files)
- **`ManagedRouteGroupTest.java`** — restore `ExchangesTotal == 1` for
nested group routes
- **`ManagedRouteGroupFailuresHandledTest.java`** — change
`ExchangesCompleted` from 3 to 1
- **`ManagedRouteGroupExchangeCountTest.java`** (new) — 6 scenarios:
nested routes, routing through non-group route, entry from outside the group,
failure path, two groups on one
path, wireTap
- **`DefaultUnitOfWorkRouteStackLevelPredicateTest.java`** (new) — 7 unit
tests for the new predicate-based `routeStackLevel` method
### Documentation changes (3 files)
- **`route-group.adoc`** — clarify once-per-group counting in the
Monitoring section
- **`camel-4x-upgrade-guide-4_22.adoc`** — 4.22.2 note about the
regression fix
- **`camel-4x-upgrade-guide-4_23.adoc`** — upgrade note for users coming
from 4.22.1
## Test plan
- [x] `ManagedRouteGroupTest` — existing test with restored assertions
- [x] `ManagedRouteGroupFailuresHandledTest` — existing test with
corrected exchange count
- [x] `ManagedRouteGroupExchangeCountTest` — new comprehensive exchange
count scenarios
- [x] `DefaultUnitOfWorkRouteStackLevelPredicateTest` — new unit test for
filtered route stack level
- [x] All 9 route group management tests pass
- [x] All 7 UoW unit tests pass
- [ ] Backport to `camel-4.22.x` (the API addition is a `default` method,
so it's additive)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Target
- [x] I checked that the commit is targeting the correct branch (Camel 4
uses the `main` branch)
# Tracking
- [x] If this is a large change, bug fix, or code improvement, I checked
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for
the change (usually before you start working on it).
# Apache Camel coding standards and style
- [x] I checked that each commit in the pull request has a meaningful
subject line and body.
- [x] I have run `mvn clean install -DskipTests` locally from root folder
and I have committed all auto-generated changes.
# AI-assisted contributions
- [x] If this PR includes AI-generated code, commits have proper
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR
description identifies the AI tool used.
--
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]