gnodet-bot commented on code in PR #29821:
URL: https://github.com/apache/camel/pull/29821#discussion_r4585981261


##########
components/camel-spiffe/src/main/docs/spiffe-component.adoc:
##########
@@ -482,3 +482,40 @@ include::spring-boot:partial$starter.adoc[]
   cannot assert an identity by setting a header - and it requires mutual TLS, 
failing closed when the peer presented
   no verified certificate. The verified id it publishes is the 
`CamelSpiffePeerId` exchange *property*, never a header,
   so it likewise cannot be injected by an inbound message.
+
+== Producer readiness and identity observations
+
+Enable producer health checks with `camel.health.producersEnabled=true` before 
starting the route. The component
+also supports `healthCheckProducerEnabled` to disable its checks. A check is 
registered with the producer and removed
+when it stops. For each enabled check, a dedicated SDK-managed Workload API 
client maintains one streaming observer;

Review Comment:
   🔤 **Style (passive voice):** "A check is registered with the producer and 
removed when it stops." — rewrite in active voice.
   
   ```suggestion
   also supports `healthCheckProducerEnabled` to disable its checks. The 
producer registers a check on start and removes it on stop.
   ```



##########
components/camel-spiffe/src/main/java/org/apache/camel/component/spiffe/SpiffeProducer.java:
##########
@@ -37,6 +46,57 @@ public SpiffeEndpoint getEndpoint() {
         return (SpiffeEndpoint) super.getEndpoint();
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        SpiffeConfiguration configuration = getEndpoint().getConfiguration();
+        if (configuration.getWorkloadApiClient() != null) {
+            // A supplied client need not use the configured/default socket, 
and has no watcher unsubscribe API.
+            return;
+        }
+        healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(
+                getEndpoint().getCamelContext(), "producers", 
WritableHealthCheckRepository.class);
+        if (healthCheckRepository != null) {
+            producerHealthCheck = new SpiffeProducerHealthCheck(
+                    getEndpoint().getId() + "-" + 
HEALTH_CHECK_IDS.incrementAndGet(), configuration.getOperation(),
+                    configuration.getHealthCheckExpiryThreshold());
+            
producerHealthCheck.setEnabled(getEndpoint().getComponent().isHealthCheckProducerEnabled());
+            healthCheckRepository.addHealthCheck(producerHealthCheck);
+            if (healthCheckRepository.isEnabled() && 
producerHealthCheck.isEnabled()) {
+                try {
+                    // A separate SDK-managed client makes the subscription 
cancellable on producer stop, even
+                    // when the endpoint remains cached or has other 
producers. No client is created by health calls.
+                    healthClient = 
SpiffeEndpoint.createWorkloadApiClient(configuration.getSpiffeSocketPath());
+                    producerHealthCheck.observe(healthClient);
+                } catch (Exception e) {
+                    producerHealthCheck.unavailable();
+                    if (healthClient != null) {
+                        healthClient.close();
+                        healthClient = null;
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (producerHealthCheck != null) {
+            producerHealthCheck.close();
+            healthCheckRepository.removeHealthCheck(producerHealthCheck);
+            producerHealthCheck = null;
+        }
+        try {
+            WorkloadApiClient client = healthClient;
+            healthClient = null;
+            if (client != null) {
+                client.close();
+            }
+        } finally {
+            super.doStop();
+        }

Review Comment:
   ⚠️ **Resource leak:** `producerHealthCheck.close()` and 
`removeHealthCheck()` run outside the `try/finally`, so if either throws, 
`healthClient.close()` and `super.doStop()` are skipped.
   
   Move the health-check cleanup inside the same `try` block:
   
   ```suggestion
           try {
               if (producerHealthCheck != null) {
                   producerHealthCheck.close();
                   healthCheckRepository.removeHealthCheck(producerHealthCheck);
                   producerHealthCheck = null;
               }
               WorkloadApiClient client = healthClient;
               healthClient = null;
               if (client != null) {
                   client.close();
               }
           } finally {
               super.doStop();
           }
   ```



##########
components/camel-spiffe/src/main/docs/spiffe-component.adoc:
##########
@@ -482,3 +482,40 @@ include::spring-boot:partial$starter.adoc[]
   cannot assert an identity by setting a header - and it requires mutual TLS, 
failing closed when the peer presented
   no verified certificate. The verified id it publishes is the 
`CamelSpiffePeerId` exchange *property*, never a header,
   so it likewise cannot be injected by an inbound message.
+
+== Producer readiness and identity observations
+
+Enable producer health checks with `camel.health.producersEnabled=true` before 
starting the route. The component
+also supports `healthCheckProducerEnabled` to disable its checks. A check is 
registered with the producer and removed
+when it stops. For each enabled check, a dedicated SDK-managed Workload API 
client maintains one streaming observer;
+stopping the producer closes that client and cancels its observer, even when 
the endpoint remains cached. Health
+calls read an immutable metadata snapshot and never fetch credentials, contact 
the API, or start another observer.
+Producer checks remain disabled globally by default, and no observer client is 
opened while they are disabled.
+If producer checks are enabled dynamically after route startup, restart the 
route to start its observer.
+
+The observation depends on the endpoint's configured operation:
+
+* `fetchX509Svid` observes the default workload X.509 identity. Readiness 
requires an available, unexpired SVID outside
+  `healthCheckExpiryThreshold` (default 60000 milliseconds, a duration such as 
`5m` is accepted). Set the threshold to
+  zero to require only that it has not expired. Health details include the 
observed expiry, remaining validity, and whether the identity is approaching 
expiry.
+* `fetchJwtSvid` and `validateJwtSvid` observe JWT trust bundles. Readiness 
requires a non-empty bundle update. Bundles
+  have no expiry timestamp, so the check makes no expiry claim and does not 
mint or validate a token. In particular,
+  it does not prove that a particular audience can be issued or that an 
incoming token will validate.
+
+Both report the most recent update timestamp and the state of the watch 
(`not-started`, `starting`, `watching`, `failed`
+or `stopped`). These are SDK callback observations, not an independently 
measured connection heartbeat; `lastUpdate` is
+the local observation time, not the SPIRE credential's issuance time. The 
check measures whether the identity the
+Workload API last delivered is valid and not about to expire, not whether the 
agent is reachable right now: the SDK
+reconnects to an unreachable agent on its own, with unlimited retries and 
without telling the watch, so an agent outage
+shows up only as an SVID that is no longer refreshed and comes within 
`healthCheckExpiryThreshold` of its expiry.

Review Comment:
   🔤 **Style (run-on sentence):** This sentence (~70 words, colon splice + 
multiple subordinates) is hard to parse. Consider splitting:
   
   > "The check measures whether the identity the Workload API last delivered 
is valid and not about to expire, not whether the agent is reachable right now: 
the SDK reconnects to an unreachable agent on its own, with unlimited retries 
and without telling the watch, so an agent outage shows up only as an SVID that 
is no longer refreshed and comes within `healthCheckExpiryThreshold` of its 
expiry."
   
   Suggested split:
   ```suggestion
   The check measures whether the identity the Workload API last delivered is 
valid and not about to expire,
   not whether the agent is reachable right now. The SDK reconnects to an 
unreachable agent on its own, with
   unlimited retries and without telling the watch, so an agent outage shows up 
only as an SVID that is no
   longer refreshed and comes within `healthCheckExpiryThreshold` of its expiry.
   ```



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