spring-cloud / spring-cloud/spring-cloud-gateway

discovery.locator.enabled caused routes.filters invalid

Open
#494 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Spring:
  Cloud:
    Gateway:
       # Setting discovery.locator.enabled=true will invalidate filters
      Discovery:
        Locator:
          Enabled: true
      Routes:
      - id: service_appraisal
        Uri: lb://appraisal
        Predicates:
        - Path=/appraisal/**
        Filters:
        - name: Hystrix
          Args:
            Name: fallbackcmd
            fallbackUri: forward:/fallback
        - name: Retry
          Args:
            Retries: 3
            Statuses: BAD_GATEWAY

The above configuration will cause the filters part to be invalid. Request http://localhost:5678/APPRAISAL/test, the routing result is as follows (Debug result):

2018-08-17 11:25:16.485 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying {_genkey_0=/appraisal/**} to Path

2018-08-17 11:25:16.486 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {_genkey_0=/appraisal/(?<segment>.*), _genkey_1=/${segment}} to RewritePath

2018-08-17 11:25:16.486 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {retries=3, methods=GET, series=SERVER_ERROR} to Retry

2018-08-17 11:25:16.495 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {name=appraisalBack, fallbackUri=forward:/fallback} to Hystrix

2018-08-17 11:25:16.500 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition matched: service_appraisal

2018-08-17 11:25:16.504 TRACE [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.h.p.RoutePredicateFactory        : Pattern "/appraisal/**" matches against value "[path='/appraisal/test']"

2018-08-17 11:25:16.504 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- [server-epoll-10] o.s.c.g.h.RoutePredicateHandlerMapping   : Route matched: CompositeDiscoveryClient_APPRAISAL

2018-08-17 11:25:16.505 DEBUG [gateway,32922115c3c9572f,32922115c3c9572f,false] 24628 --- 
[server-epoll-10] o.s.c.g.h.RoutePredicateHandlerMapping   : Mapping [Exchange: GET http://localhost:5678/appraisal/test] to Route{id='CompositeDiscoveryClient_APPRAISAL', uri=lb://APPRAISAL, order=0, predicate=org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$764/2126809795@568363b4, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$766/160988909@557db8de, order=1}]}

There is no hystrix and retry related filter in the route.

In order to use filter, the current solution is as follows:
Spring:
  Cloud:
    Gateway:
       # Do not enable discovery.locator.enabled
# discovery:
# locator:
# enabled: true
      Routes:
      - id: service_appraisal
        Uri: lb://appraisal
        Predicates:
        - Path=/appraisal/**
        Filters:
        # Solve the path problem
        - RewritePath=/appraisal/(?.*), /$\{segment}
        - name: Hystrix
          Args:
            Name: fallbackcmd
            fallbackUri: forward:/fallback
        - name: Retry
          Args:
            Retries: 3
            Statuses: BAD_GATEWAY

** As configured above, request http://localhost:5678/APPRAISAL/test, the routing result is as follows (Debug result)**:

2018-08-17 11:12:56.245 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying {_genkey_0=/appraisal/**} to Path

2018-08-17 11:12:56.249 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {_genkey_0=/appraisal/(?<segment>.*), _genkey_1=/${segment}} to RewritePath

2018-08-17 11:12:56.251 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {retries=3, methods=GET, series=SERVER_ERROR} to Retry

2018-08-17 11:12:56.257 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition service_appraisal applying filter {name=appraisalBack, fallbackUri=forward:/fallback} to Hystrix

2018-08-17 11:12:56.261 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.r.RouteDefinitionRouteLocator    : RouteDefinition matched: service_appraisal

2018-08-17 11:12:56.264 TRACE [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.h.p.RoutePredicateFactory        : Pattern "/appraisal/**" matches against value "[path='/appraisal/test']"

2018-08-17 11:12:56.264 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.h.RoutePredicateHandlerMapping   : Route matched: service_appraisal

2018-08-17 11:12:56.265 DEBUG [gateway,236d75d5e52a724d,236d75d5e52a724d,false] 22942 --- [server-epoll-10] o.s.c.g.h.RoutePredicateHandlerMapping   : Mapping [Exchange: GET http://localhost:5678/appraisal/test] to Route{id='service_appraisal', uri=lb://appraisal, order=0, predicate=org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$753/812058891@26ce000e, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$755/292731128@29b134c0, order=1}, OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RetryGatewayFilterFactory$$Lambda$762/1603178155@6d4d66e8, order=2}, OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.HystrixGatewayFilterFactory$$Lambda$763/771377733@388eaa81, order=3}]}

The route contains hystrix and retry related filters

Version Information:
        <parent>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-parent</artifactId>
             <version>2.0.3.RELEASE</version>
             <relativePath />
        </parent>
        <properties>
             <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
             <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
             <java.version>1.8</java.version>
             <spring-boot-admin.version>2.0.2</spring-boot-admin.version>
             <spring-cloud.version>Finchley.SR1</spring-cloud.version>
        </properties>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the RouteDefinitionRouteLocator and RoutePredicateHandlerMapping behavior shown in the logs, comparing a configured route with the discovery-generated route when discovery.locator.enabled is true. Reproduce the configuration using the Spring Boot 2.0.3 and Spring Cloud Finchley.SR1 versions given; done when discovery-generated routes retain the configured Hystrix and Retry filters.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.