allthingssecurity opened a new pull request, #30840: URL: https://github.com/apache/camel/pull/30840
# Description [CAMEL-27458](https://issues.apache.org/jira/browse/CAMEL-27458) The polling consumer (without `useKclConsumers`) reads the shards of the list that its shard monitor gets with `ListShards` every `shardMonitorInterval` (since CAMEL-24197 also with a configured `shardId`, which called `DescribeStream` in each poll before). When `ListShards` fails from the start and keeps failing (the IAM role has no `kinesis:ListShards` permission, the stream name is wrong and Kinesis answers `ResourceNotFoundException`, or the calls stay throttled), the list stays empty. Every poll then read nothing and still ended as a successful poll: it called `forceConsumerAsReady()` and the error counter stayed 0. The consumer health check reported the consumer ready and UP, forever, while no record was read; the only sign was the WARN "Exception getting latest shard list" of the shard monitor. With a configured `shardId` the poll logged that the shard is not in the list, returned 0, and the consumer was still ready. `Kinesis2ConsumerHealthCheckStaticCredsIT` and `Kinesis2ConsumerHealthCustomClientIT` expect readiness DOWN for a stream that does not exist. Before this change they passed only because they check before the first poll; now the consumer is DOWN for that case for as long as `ListShards` fails. Change, in `Kinesis2Consumer`: - the shard monitor keeps the error of its last `ListShards` (a volatile field, set in the existing `catch (Exception)`, cleared when a `ListShards` returns); - while no shard has been listed, a poll fails with an `IllegalStateException` ("Cannot list the shards of stream <name>: <error>") whose cause is that error. The error counter, the consumer health check (DOWN, with the error as reason, as for a failed `GetRecords`) and the back-off options (`backoffErrorThreshold`, `backoffMultiplier`) then work as for any failed poll. The consumer health check is a readiness check only, as for every polling consumer, so liveness is not affected (a missing permission does not make Kubernetes restart the pod). Like any failed poll it goes to the exception handler of the consumer (with `bridgeErrorHandler`, to the error handler of the route), so it is logged at each poll unless back-off is configured, as a `GetRecords` failure is; - without an error yet (the first `ListShards` is still running), the poll returns 0, and `isConsumerReady()` is false until the shards have been listed, so a first `ListShards` slower than the initial delay of the poll no longer makes the consumer ready on an empty list; - once the shards are listed nothing changes. A later `ListShards` failure keeps the consumer reading the shards it knows and it stays UP (the existing health check only sees the polls, and failing the polls there would stop reading shards that still work); - `ShardMonitor` is package-private so that the test runs it. Upgrade guide 4.24: new entry "camel-aws2-kinesis - the consumer is not ready before it has listed the shards". Not changed here: - a `ListShards` call of the async client (`listShards(request).get()`) waits without a timeout. The SDK's own read and acquire timeouts apply, so a real call normally completes or fails. - after a stop and start of the same consumer instance, a monitor run of the previous start that is still in progress can publish its older list after the new monitor's list; the next run corrects it. A route restart creates a new consumer. - an `Error` thrown in one run of the shard monitor stops the monitor for good, without a log line; that has its own ticket and pull request. Tests, new `KinesisConsumerShardListHealthTest` (3, mocked `KinesisClient`, the test runs the polls with `run()` and the monitor with `ShardMonitor.run()`, no sleep): - `readinessIsDownWithTheFailureUntilTheShardsAreListed`: `listShards` throws `AccessDeniedException`; after two polls readiness is DOWN with the error as cause (and the check is not a liveness check), `getRecords` was never called; once `listShards` answers, the next poll reads the shard and readiness is UP; - `readinessIsDownWithTheFailureForAConfiguredShardId`: the same with `shardId` set and `ResourceNotFoundException`; - `notReadyWhileTheFirstListShardsIsInProgress`: the first `ListShards` blocks; a poll leaves readiness DOWN with error counter 0; after the list arrives the next poll makes it UP. Without the change all 3 tests fail (readiness UP where DOWN is expected). With it the camel-aws2-kinesis unit tests pass (67 run, plus the 1000 seeds of the DST test, 0 failures), and the new class passes 20 of 20 runs. The ITs need LocalStack and were not run locally (CI runs them). The local offline build used AWS SDK 2.57.11 (as on main). The change merges cleanly with the branch of the sibling ticket, and the merged consumer passes both new test classes and the consumer tests 5 of 5 runs. Backport: main only; the consumer ready/UP state is user visible, and the fixed-`shardId` path that reads the cached list exists since 4.22. # 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-27458](https://issues.apache.org/jira/browse/CAMEL-27458). # 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. (I built camel-aws2-kinesis and the core modules with the formatter and import-sort plugins and ran the camel-aws2-kinesis unit tests. I did not run the full root build.) # 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]
