davsclaus commented on code in PR #29045: URL: https://github.com/apache/camel/pull/29045#discussion_r4459454237
########## components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConsumerHealthCheck.java: ########## @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.azure.cosmosdb; + +import java.util.Map; + +import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.health.HealthCheckResultBuilder; + +/** + * Readiness health check of the Azure Cosmos DB consumer: the initial state of the health checks (DOWN by default) + * while the first attempt to start the change feed processor runs, DOWN with the last start failure and the number of + * failed attempts while it cannot start (the consumer tries again with a backoff until it starts), and UP once it has + * started. + */ +public class CosmosDbConsumerHealthCheck implements HealthCheck { + + private final CosmosDbConsumer consumer; + private final String routeId; + private final State initialState; + private volatile boolean enabled = true; + + public CosmosDbConsumerHealthCheck(CosmosDbConsumer consumer, String routeId) { + this.consumer = consumer; + this.routeId = routeId; + // camel.health.initial-state, as the Debezium consumer check does + HealthCheckRegistry registry = HealthCheckRegistry.get(consumer.getEndpoint().getCamelContext()); + this.initialState = registry != null ? registry.getInitialState() : State.DOWN; + } + + @Override + public String getGroup() { + return "camel"; + } + + @Override + public String getId() { + return routeId != null ? "consumer:azure-cosmosdb-" + routeId : "consumer:azure-cosmosdb"; Review Comment: The id is fine as it is. This check is not registered on its own: `CosmosDbConsumer` hands it out through `HealthCheckAware.getHealthCheck()`, and `ConsumersHealthCheckRepository` wraps it in a `ConsumerHealthCheck` whose id is `"consumer:" + routeId`. That wrapper is what the registry and the test at line 139 see (`consumer:cosmos`). The inner id follows the Kafka pattern (`"consumer:kafka-" + routeId` in `KafkaConsumerHealthCheck`, `"consumer:kafka-share-" + routeId` in camel-kafka-share). The `routeId != null` guard is defensive and harmless, so I am resolving this thread. _Claude Code on behalf of davsclaus_ -- 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]
