allthingssecurity opened a new pull request, #29901: URL: https://github.com/apache/camel/pull/29901
# Description [CAMEL-26769](https://issues.apache.org/jira/browse/CAMEL-26769), part of [CAMEL-26630](https://issues.apache.org/jira/browse/CAMEL-26630) (exchange sanitizer), on top of the `camel-sanitizer` module of [CAMEL-26714](https://issues.apache.org/jira/browse/CAMEL-26714) (#29409). Uses rule R2 ([CAMEL-26768](https://issues.apache.org/jira/browse/CAMEL-26768), #29664) and R1 "still pending" ([CAMEL-26751](https://issues.apache.org/jira/browse/CAMEL-26751)). Touches `sanitizer.adoc` like #29892 (different section); either can merge first. Step 5 of the "Order of work" of `design/exchange-sanitizer.adoc`, as its "Using it" section describes: a `sanitizer` dev console, `camel get sanitizer` and `camel run --sanitizer`. Until now the violations and the still pending warnings are only in the log and, from Java, in `Sanitizer.get(camelContext)`. The console and the command show both rules (R1, the callback of a step; R2, the commit of a consumer) and the still pending warnings of R1. Nothing from the other steps (R3, R4). **R2 in a run.** Since #29664, `camel.sanitizer.checks` is `callback` (R1) by default, and `callback,commit` only in a test (`@CamelSanitizer` or the CI switch), because R2 costs 2 to 4 times R1 per message. `camel run --sanitizer` keeps that default: it does not pass `checks=callback,commit`. That is what the design says for `camel run` ("Using it": "R1; R2 with `camel.sanitizer.checks=callback,commit`, as it is on by default only in tests"), so the help of `--sanitizer`, the sanitizer page and `camel-jbang-managing.adoc` say that `--prop camel.sanitizer.checks=callback,commit` turns R2 on in the run too. Without R2, the console has no `commits`, and `camel get sanitizer --report` says `R2 not checked (camel.sanitizer.checks=callback,commit)` instead of a count of 0. ## What it adds - **The `sanitizer` dev console** (`SanitizerDevConsole` in camel-sanitizer; read-only, the default of `@DevConsole`; no options). In JSON: ```json {"enabled": true, "calls": 42, "commits": 7, "total": 2, "rules": {"R1": 1, "R2": 1}, "kinds": {"COMPLETED_TWICE": 0, "THREW_BEFORE_CALLBACK": 1, "...": 0, "COMMIT_NEVER_RUN": 1}, "violations": [{"rule": "R1", "kind": "THREW_BEFORE_CALLBACK", "title": "process threw before calling the callback", "exchangeId": "...", "routeId": "orders", "stepId": "price", "processor": "com.acme.PriceLookup", "report": "Exchange sanitizer: process threw before calling the callback (R1)\n exchange ..."}, {"rule": "R2", "kind": "COMMIT_NEVER_RUN", "title": "commit never ran", "exchangeId": "...", "routeId": "files", "processor": "com.acme.FileCommit", "report": "..."}], "pendingCalls": 1, "stillPending": 1, "stillPendingWarnings": ["Exchange sanitizer: callback still pending (R1, a warning)\n exchange ..."]} ``` `total` counts every violation reported, also those past the first 1000 that the sanitizer counts but does not keep; `violations` lists the kept ones in the order they were reported, each with the full report as logged (threads, stacks, the class and message of what was thrown, the usual fix). When the sanitizer is off it is `{"enabled": false, "reason": "..."}`, and the reason says profile `prod` when that is why. `commits` (the commits followed) is there only when R2 is checked; a violation of R2 found where no step ran (a commit that never ran, seen at the done event of its exchange) has no `stepId`, and its `processor` is the class of the commit. `pendingCalls` (the calls pending now), `stillPending` (the warnings so far) and `stillPendingWarnings` (the first 1000, as logged) are there when the still pending warning is on (it needs the `callback` check and a `pendingTimeout` above 0). As text it is the report that is logged when the context stops, followed by the still pendi ng warnings. The report holds ids, names, threads, stacks and the class and message of an exception, never bodies or headers (a test checks that a body and a header of the failed exchange are in neither form); an exception message can still carry message data, as the design says. Like every dev console, it is served over HTTP only when the developer consoles are switched on (`camel.management.devConsoleEnabled`, `insecure:dev`, with Camel Main). - **The counts per rule** use `Violation.getRule()` of R2 (`R1`, or `R2` for the commit kinds); every rule and every kind is listed, also with a count of 0. - **`camel get sanitizer`** (written with aesh, as the other commands of the CLI now are): a table of the violations of the running integrations (PID, NAME, RULE, VIOLATION, ROUTE, STEP, PROCESSOR, EXCHANGE); `--report` shows, per integration, the counts per rule and kind, the commits followed (or that R2 is not checked), the still pending warnings counted and the calls pending now, each violation's report with its stacks, and the still pending warnings; `--json` for both; `--sort` and `--watch` as the other `get` commands. Notes on stderr say why an integration shows nothing (the sanitizer is off and why; no violations, with the calls checked; an integration that did not answer in time), how many violations are counted but not listed, and how many calls were reported still pending (see `--report`), and, when no integration has it, `No running integration has camel-sanitizer: run it with camel run --sanitizer`. An integration whose status says Camel before 4.24 is not asked (it ca nnot have camel-sanitizer, and an older connector would let the request time out). - **`camel run --sanitizer`** (also `camel dev` and `camel debug`) adds camel-sanitizer, as `--chaos` adds camel-chaos; `--dep camel:sanitizer` works as before. With profile `dev`, the default of `camel run`, it is on and checks R1 (R2 with `--prop camel.sanitizer.checks=callback,commit`, see above); with `--profile=prod` the run says up front `camel-sanitizer stays off with profile prod`. - JBang and `--runtime=main` (exported or an existing Camel Main project): the dependency is added. - `--runtime=spring-boot`: plain `camel-sanitizer` (there is no starter; for an existing project, with the version the Camel Spring Boot BOM is imported with), and the run passes `-Dcamel.sanitizer.enabled=true` unless the profile is `prod`, as CAMEL-26479 (#29411) settled for `--chaos`. It is an argument of the run, not a property of the exported project. - `--runtime=quarkus`: refused for now with a usage error (`Run Camel Quarkus with --sanitizer is not supported yet (use --runtime=jbang, main or spring-boot)`): there is no Camel Quarkus extension to add to an existing Quarkus project (`--chaos` uses `camel-quarkus-chaos` there), and the sanitizer is not tested with Camel Quarkus yet. A follow-up can lift it the way CAMEL-26479 did for chaos. - **Docs**: the "In development" section of the sanitizer page (console, commands, JSON fields), `camel-jbang-managing.adoc` ("Exchange sanitizer"), the limitation line in `camel-jbang-running.adoc`, and in the design the Spring Boot / Quarkus sentence and "Done" for step 5. ## Where this differs from the design or from camel-chaos (on purpose) - **An action, not the status file.** `camel get chaos` reads the chaos console from the status file that the CLI connector writes every second. The sanitizer report can list 1000 violations, each with stacks of 32 frames, which is megabytes to write every second for nothing. So `camel get sanitizer` asks for the console through a new `sanitizer` action of the CLI connector when it runs, as `camel get timeline` does. A TUI tab could use the same action later; if a cheap "has the sanitizer" signal is wanted in the status (for the TUI or `camel ask`), a small summary (`enabled`, `total`) could be added there, not the violations. - **Quarkus refused** (see above), where `--chaos` now works with Quarkus. - **The calls still pending**, which the design lists in the console, are there now that R1 "still pending" (CAMEL-26751) is merged: the warnings and how many calls are pending now. The calls still pending when the context stopped are only in the log (the console answers while the context runs). - **No dropped counts in the JSON.** When a bound is reached ("checks incomplete": pending calls or commits no longer followed), the text form says so in its first line; the JSON has no field for it yet. A follow-up can add `pendingDropped` / `commitsDropped` if `camel get sanitizer --report` should show it. - **No options on the console.** `camel get sanitizer` without `--report` still receives the reports; a `report=false` option as on the chaos console could be added if the size matters with `--watch`. ## Tests - camel-core `SanitizerDevConsoleTest` (the console is resolved by its id, as the registry does): JSON and text for a context with a violation (counts per rule and kind, the report with the exception and the stack, no body or header), a violation of R2 (a commit that never ran: rule `R2`, no step, the class of the commit), still pending warnings (a processor that never calls back, `pendingTimeout` 200ms: counted, listed, in the text, not a violation), no violations, profile `dev` outside a test (R1 only: no `commits`, as with `camel run --sanitizer`), off with profile `prod`, read-only. - camel-cli-connector `LocalCliConnectorSanitizerActionTest`: the `sanitizer` action end to end with camel-sanitizer on (profile `dev`, a processor that throws) and off (profile `prod`). - camel-jbang-core `ListSanitizerTest` (the answer goes through JSON text, so numbers are `BigDecimal` as in a real reply): table, JSON, report (with R2 not checked, and with the commits and the still pending warnings), report as JSON, counted but not listed, no violations, off, an integration that did not answer, no camel-sanitizer, an integration before 4.24 not asked, a violation of R2 without a step, still pending warnings without violations; `ListSanitizerActionTest`: the real request against the fake integration of the action tests; `RunTest` (the WARN with profile `prod`), `CommandInputErrorsTest` (Quarkus refused), `RunExportGoldenTest` (new `sanitizer` run and `maven-spring-boot-sanitizer` cases), `CliHelpGoldenTest` / `CliParseGoldenTest` (the `--sanitizer` option, `camel get sanitizer`). - camel-jbang-run `ProjectRunnerTest`: Spring Boot exported (dependency and JVM argument, not in `application.properties`) and with profile `prod` (dependency, no JVM argument), an existing Spring Boot project (version of the BOM) and an existing Camel Main project. Local runs (offline): - The sanitizer tests of camel-core (with `SanitizerDevConsoleTest`, the load balancer and `shareUnitOfWork` tests), camel-management, camel-main and camel-test-main-junit6: 246/246 (camel-core 231, with `SanitizerDevConsoleTest` 8) without and with the CI switch (`-Psanitizer`). camel-cli-connector `LocalCliConnectorSanitizerActionTest` + `LocalCliConnectorChaosActionTest` and camel-jbang-run `ProjectRunnerTest`: 2 + 19 + 21, all pass. - camel-jbang-core: `ListSanitizerTest` 14, `ListSanitizerActionTest` 2, `ListChaosTest` 21, `RunTest` 27, `CommandInputErrorsTest` 24, `CliHelpGoldenTest` / `CliParseGoldenTest` (match without update; the generated commands metadata and pages are unchanged by the build): all pass. `RunExportGoldenTest`: the `sanitizer` and `maven-spring-boot-sanitizer` cases pass; 18 other export and Maven-run cases fail in my offline environment only (on-demand downloads: no Java/XML DSL loader, unresolved versions), as on the first version. # 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): [CAMEL-26769](https://issues.apache.org/jira/browse/CAMEL-26769). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not from the root. The modules above were built offline with the formatter and import-sort plugins. Committed: the dev console metadata of camel-sanitizer, the catalog (`dev-consoles/sanitizer.json`, `dev-consoles.properties`, `dev-consoles-openapi.json`, `docs/sanitizer.adoc`), the jbang commands metadata and pages (with the new `camel-jbang-get-sanitizer.adoc`), the `cli-help` / `cli-parse` goldens and the two new golden expected files. # 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 PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
