[ https://issues.apache.org/jira/browse/CAMEL-12448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16439425#comment-16439425 ]
ASF GitHub Bot commented on CAMEL-12448: ---------------------------------------- lburgazzoli closed pull request #2296: CAMEL-12448 - camel-consul: filter health checks by service id URL: https://github.com/apache/camel/pull/2296 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java index e7cfd5f7430..74b7c006c35 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java @@ -99,7 +99,11 @@ private ServiceDefinition newService(String serviceName, CatalogService service, service.getServiceAddress(), service.getServicePort(), meta, - new DefaultServiceHealth(serviceHealthList.stream().allMatch(this::isHealthy)) + new DefaultServiceHealth( + serviceHealthList.stream() + .filter(h -> ObjectHelper.equal(h.getService().getId(), service.getServiceId())) + .allMatch(this::isHealthy) + ) ); } } diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java index 2523ad74017..119e85b68fd 100644 --- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java +++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java @@ -21,6 +21,7 @@ import com.orbitz.consul.AgentClient; import com.orbitz.consul.Consul; +import com.orbitz.consul.model.agent.ImmutableRegCheck; import com.orbitz.consul.model.agent.ImmutableRegistration; import com.orbitz.consul.model.agent.Registration; import org.apache.camel.cloud.ServiceDefinition; @@ -44,7 +45,12 @@ public void setUp() throws Exception { client = Consul.builder().build().agentClient(); registrations = new ArrayList<>(3); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 6; i++) { + Registration.RegCheck c = ImmutableRegCheck.builder() + .ttl("1m") + .status(i < 3 ? "passing" : "critical") + .build(); + Registration r = ImmutableRegistration.builder() .id("service-" + i) .name("my-service") @@ -53,6 +59,7 @@ public void setUp() throws Exception { .addTags("key1=value1") .addTags("key2=value2") .port(9000 + i) + .check(c) .build(); client.register(r); @@ -76,7 +83,7 @@ public void testServiceDiscovery() throws Exception { List<ServiceDefinition> services = discovery.getServices("my-service"); assertNotNull(services); - assertEquals(3, services.size()); + assertEquals(6, services.size()); for (ServiceDefinition service : services) { assertFalse(service.getMetadata().isEmpty()); @@ -85,6 +92,7 @@ public void testServiceDiscovery() throws Exception { assertTrue(service.getMetadata().containsKey("a-tag")); assertTrue(service.getMetadata().containsKey("key1")); assertTrue(service.getMetadata().containsKey("key2")); + assertTrue(service.getPort() < 9003 ? service.getHealth().isHealthy() : !service.getHealth().isHealthy()); } } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > camel-consul - service health state calculated from all services with same > name > ------------------------------------------------------------------------------- > > Key: CAMEL-12448 > URL: https://issues.apache.org/jira/browse/CAMEL-12448 > Project: Camel > Issue Type: Bug > Components: camel-consul > Affects Versions: 2.21.0 > Reporter: Vadim R > Priority: Major > > In Consul catalog registered two instances of one service. Health check for > first instance have "passed" state, and for second instance - "critical". > Camel returns both service instances with healty checks, which method > "isHealthy" returns "false". > I've make some changes in ConsulServiceDiscoveryTest to show up this bug, and > fix it in ConsulServiceDiscovery. -- This message was sent by Atlassian JIRA (v7.6.3#76005)