spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
808 stars 540 forks source link

Expected behaviour with Consul Service Discovery and queryPassing=true #771

Open liammacisaac opened 2 years ago

liammacisaac commented 2 years ago

When using a basic configuration to support consul service discovery, we're seeing some inconsistent behaviour when using the queryPassing setting. An example configuration is shown below.

spring:
    cloud:
        consul:
            config:
                failFast: false
            enabled: true
            host: localhost
            port: 8500
            discovery:
                register: false
                enabled: true
                registerHealthCheck: false
                instanceId: ${spring.application.name}:${random.value}
                query-passing: true       
        gateway:     
            discovery:
                locator:
                    enabled: true
                    predicates:
                    - name: Path
                      args:
                        pattern: "'/services/' + serviceId + '/**'"
                    filters:
                    -   name: RewritePath
                        args:
                            regexp: "'/services/' + serviceId + '/(?<remaining>.*)'"
                            replacement: "'/${remaining}'"

When queryPassing is false, we observe:

When queryPassing is true and the service is up before gateway, we observe:

When queryPassing is true and the service is started after gateway, we observe:

My initial thoughts on this are that we should be doing one of the following:

spencergibb commented 2 years ago

There used to be filters for load balancing with ribbon. We should add those back so health check can be only used for loadbalancing. https://github.com/spring-cloud/spring-cloud-consul/tree/2.2.x/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters

See also #712

nkvaratskhelia commented 2 years ago

@spencergibb As explained above, the spring.cloud.consul.discovery.query-passing=true parameter works inconsistently. Is there currently any other way to exclude unhealthy services from gateway load balancing?