davsclaus commented on code in PR #29388:
URL: https://github.com/apache/camel/pull/29388#discussion_r4503569606


##########
components/camel-chaos/src/main/java/org/apache/camel/component/chaos/ChaosTargets.java:
##########
@@ -71,11 +73,70 @@ static String check(CamelContext camelContext, ChaosRule 
rule) {
         if (rule.lifecycle != null) {
             return null;
         }
-        return switch (rule.target) {
+        String answer = switch (rule.target) {
             case ENDPOINT, COMPONENT -> checkEndpoints(camelContext, rule);
             case ROUTE -> checkRoutes(camelContext, rule);
             case STEP -> checkSteps(camelContext, rule);
         };
+        return answer == null && rule.in != null ? checkIn(camelContext, rule) 
: answer;
+    }
+
+    /**
+     * Why a rule with {@code in=} finds nothing to fire at in its routes: no 
route matches {@code in=}, or its target
+     * matches nothing inside those routes (a send, a step, or the poll of the 
consumer of the route). A send inside a
+     * route that one of them calls ({@code direct:}) is in that other route.
+     */
+    private static String checkIn(CamelContext camelContext, ChaosRule rule) {
+        List<Route> routes = new ArrayList<>();
+        TreeSet<String> ids = new TreeSet<>();
+        for (Route route : camelContext.getRoutes()) {
+            ids.add(route.getRouteId());
+            if (rule.matchesIn(route.getRouteId())) {
+                routes.add(route);
+            }
+        }
+        if (routes.isEmpty()) {
+            return "in=" + rule.in + " matches no route of the context now, so 
the rule fires 0 times; the routes are: "
+                   + some(ids);
+        }
+        String in = (routes.size() == 1 ? "route " : "routes ") + rule.in + " 
(in=" + rule.in + ")";
+        if (rule.target == ChaosRule.Target.STEP) {
+            TreeSet<String> steps = new TreeSet<>();
+            for (Route route : routes) {
+                for (Processor processor : route.filter("*")) {
+                    String id = processor instanceof IdAware idAware ? 
idAware.getId() : null;
+                    if (id != null) {
+                        if (rule.matchesId(id)) {
+                            return null;
+                        }
+                        steps.add(id);
+                    }
+                }
+            }
+            return "step=" + rule.pattern + " matches no step of " + in + ", 
so the rule fires 0 times; the steps there"
+                   + " are: " + some(steps);
+        }
+        if (rule.hooks.contains(Hook.DLQ)) {
+            // the dead letter channel is the error handler's, not a send of 
the route
+            return null;
+        }
+        Reach reach;
+        try {
+            reach = reach(camelContext, routes);
+        } catch (RuntimeException e) {

Review Comment:
   Done in 5b2fb896b215: the catch now logs at DEBUG with the `in=` pattern and 
the exception, the same as `reach()`. I kept `RuntimeException` rather than 
narrowing it to `ConcurrentModificationException`: this only feeds a warning, a 
reload can fail in other ways too, and with the debug log a real bug is no 
longer invisible.
   
   _Claude Code on behalf of Claus Ibsen_



##########
components/camel-chaos/src/main/java/org/apache/camel/component/chaos/ChaosTargets.java:
##########
@@ -71,11 +73,70 @@ static String check(CamelContext camelContext, ChaosRule 
rule) {
         if (rule.lifecycle != null) {
             return null;
         }
-        return switch (rule.target) {
+        String answer = switch (rule.target) {
             case ENDPOINT, COMPONENT -> checkEndpoints(camelContext, rule);
             case ROUTE -> checkRoutes(camelContext, rule);
             case STEP -> checkSteps(camelContext, rule);
         };
+        return answer == null && rule.in != null ? checkIn(camelContext, rule) 
: answer;
+    }
+
+    /**
+     * Why a rule with {@code in=} finds nothing to fire at in its routes: no 
route matches {@code in=}, or its target
+     * matches nothing inside those routes (a send, a step, or the poll of the 
consumer of the route). A send inside a
+     * route that one of them calls ({@code direct:}) is in that other route.
+     */
+    private static String checkIn(CamelContext camelContext, ChaosRule rule) {
+        List<Route> routes = new ArrayList<>();
+        TreeSet<String> ids = new TreeSet<>();
+        for (Route route : camelContext.getRoutes()) {
+            ids.add(route.getRouteId());
+            if (rule.matchesIn(route.getRouteId())) {
+                routes.add(route);
+            }
+        }
+        if (routes.isEmpty()) {
+            return "in=" + rule.in + " matches no route of the context now, so 
the rule fires 0 times; the routes are: "
+                   + some(ids);
+        }
+        String in = (routes.size() == 1 ? "route " : "routes ") + rule.in + " 
(in=" + rule.in + ")";
+        if (rule.target == ChaosRule.Target.STEP) {
+            TreeSet<String> steps = new TreeSet<>();
+            for (Route route : routes) {
+                for (Processor processor : route.filter("*")) {
+                    String id = processor instanceof IdAware idAware ? 
idAware.getId() : null;
+                    if (id != null) {
+                        if (rule.matchesId(id)) {
+                            return null;
+                        }
+                        steps.add(id);
+                    }
+                }
+            }
+            return "step=" + rule.pattern + " matches no step of " + in + ", 
so the rule fires 0 times; the steps there"
+                   + " are: " + some(steps);
+        }
+        if (rule.hooks.contains(Hook.DLQ)) {
+            // the dead letter channel is the error handler's, not a send of 
the route
+            return null;
+        }
+        Reach reach;
+        try {
+            reach = reach(camelContext, routes);
+        } catch (RuntimeException e) {

Review Comment:
   Done in 5b2fb896b215: the catch now logs at DEBUG with the `in=` pattern and 
the exception, the same as `reach()`. I kept `RuntimeException` rather than 
narrowing it to `ConcurrentModificationException`: this only feeds a warning, a 
reload can fail in other ways too, and with the debug log a real bug is no 
longer invisible.
   
   _Claude Code on behalf of Claus Ibsen_



-- 
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]

Reply via email to