davsclaus opened a new pull request, #29389:
URL: https://github.com/apache/camel/pull/29389

   ## Description
   
   [CAMEL-26719](https://issues.apache.org/jira/browse/CAMEL-26719): step 4 of 
the stage 2 order decided on 
[CAMEL-26607](https://issues.apache.org/jira/browse/CAMEL-26607?focusedCommentId=18140177&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-18140177)
 (S2-3): a condition on the message.
   
   **Stacked on #29388** (CAMEL-26718), which is stacked on #29387 and #29386. 
Retarget this PR to `main` once those have merged.
   
   ```
   endpoint=http:stock* error status=503 when="${header.country} == 'ES'"
   route=orders error rate=0.1 when="${header.priority} == 'high'"
   endpoint=kafka:orders* duplicate when="${body} contains 'refund'"
   ```
   
   ### How the condition works
   
   - The condition is in the simple language. A `<language>:` prefix (such as 
`groovy:`) is reserved for later, and refused for now.
   - `ChaosManager` turns it into a predicate once, when the rule is added, 
with the simple language of the context. A condition that is not valid simple 
is refused, with the message of the simple language.
   - The hooks check the condition after the target (and `in=`), and before 
`fires(now)`. So `matches`, `rate` and `until=<count>` count only the messages 
that meet the condition, and a seed gives the same faults for the same matching 
messages.
   - It works at the send, reply, dead letter channel, route entry and step 
hooks.
   
   ### Where it is refused
   
   - A poll has no message. Without `at=`, a rule with `when=` leaves out the 
polls of its target.
   - `at=poll`, `stall` and `lifecycle` refuse `when=`.
   
   ### The body
   
   - A condition on the body (`${body}`, `${bodyAs(...)}`, `jsonpath`, `jq`, 
`xpath`) reads a stream body from the stream cache, and resets the cache after 
the check. So the route still reads the whole body.
   - A reply that is a raw stream (`at=reply`) is cached first.
   - Such a condition is refused when stream caching is off. At the route entry 
the body is cached already, because the stream caching advice of the route runs 
before its policies.
   
   ### A condition that throws
   
   A condition that throws counts as not met, and is counted under 
`skippedReasons`. It does not fail the exchange.
   
   ### Also in this PR
   
   - The rule in plain words says it: "fail every send to http:stock* with HTTP 
status 503, when ${header.country} == 'ES'".
   - The chaos model has the new option (type `predicate`, language `simple`). 
The chaos screen keeps `when=` out of the fault column.
   - `chaos.adoc` gets a section "A condition on the message", and its catalog 
copy is updated.
   - A `chaos-add` help example: `--rule='endpoint=http:stock* error 
when="${header.country} == \"ES\""'`. Simple refuses an unquoted text, so this 
is the form that works inside single quotes in a shell. The example is written 
`$${...}` in the source, because picocli expands `${...}` in help text. The CLI 
help golden is updated.
   
   ## Tests
   
   - camel-chaos: 761 tests, all green.
     - The new `ChaosWhenTest` covers:
       - a condition on a header;
       - the rate and `until` count only the messages that meet it;
       - the route entry and a step;
       - a stream body is still read whole after the check;
       - a stream reply is cached first;
       - a condition that throws is counted as skipped;
       - invalid simple is refused;
       - the CLI quoting form.
     - The new `ChaosWhenNoStreamCachingTest` covers the refusal of a condition 
on the body.
     - `ChaosMainTest` adds a condition in `camel.chaos.rules`.
     - Parser, describe and model cases were added.
   - camel-jbang-plugin-tui: the Chaos* tests (47) pass.
   - camel-jbang-core: `CliHelpGoldenTest` and `CamelChaosActionTest` pass.
   
   I did not check this against a running integration: that needs the core jars 
of #29386.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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