Skip to content

Question about the order of SentinelGatewayFilter in Spring Cloud Gatewayย #764

Closed

Description

@fangjian0423

Issue Description

Type: bug report

Describe what happened

// LoadBalancerClientFilter#filter
if (instance == null) {
    throw NotFoundException.create(properties.isUse404(),
        "Unable to find instance for " + url.getHost());
}

The order of LoadBalancerClientFilter is higher than SentinelGatewayFilter. So it won't invoke SentinelGatewayFilter after LoadBalancerClientFilter throw NotFoundException if there is no healthy instance.

image

Is it necessary to set the higher order for SentinelGatewayFilter?

There is another case:

image

Spring Cloud Gateway will using NoLoadBalancerClientFilter to replace of LoadBalancerClientFilter if there is no xx-discovery-starter in pom.

This case has the same problem.

Activity

  1. sczyh30 commented on May 16, 2019

    @sczyh30
    Member

    Yes, the order of the filters should be well arranged. In the demo we set the order of SentinelGatewayFilter to -1. Maybe we can put it ahead (the highest precedence?).

  2. fangjian0423 commented on May 16, 2019

    @fangjian0423
    ContributorAuthor

    @sczyh30

    It seems we should implement org.springframework.core.Ordered interface, not the org.springframework.core.annotation.Order annotation.

  3. cui1100 commented on Jun 13, 2019

    @cui1100

    @sczyh30
    I copy the SentinelGatewayFilter and Ordered before my filters,bu even though the sentinel limit the flow ,my filters would excute ,then it throws exception of Blocked by Sentinel?
    How could i modify the SentinelGatewayFilter.java ?

  4. evilester commented on Jun 26, 2019

    @evilester

    spring-cloud-gateway-starter-ahas-sentinel:1.0.1

    SentinelGatewayAutoConfiguration.java
    @bean
    @order(-1)
    public GlobalFilter sentinelGatewayFilter() {
    return new SentinelGatewayFilter();
    }

    Odrer is invalid here

    FilteringWebHandler.java
    public Mono handle(ServerWebExchange exchange) {
    Route route = exchange.getRequiredAttribute(GATEWAY_ROUTE_ATTR);
    List gatewayFilters = route.getFilters();

    	List<GatewayFilter> combined = new ArrayList<>(this.globalFilters);
    	combined.addAll(gatewayFilters);
    	// TODO: needed or cached?
    	AnnotationAwareOrderComparator.sort(combined); //Here not 
    
    	if (logger.isDebugEnabled()) {
    		logger.debug("Sorted gatewayFilterFactories: " + combined);
    	}
    

    image

    Maybe SentinelGatewayFilter need the delegation of OrderedGatewayFilter and SentinelGatewayFilter should implement org.springframework.core.Ordered

  5. added
    area/integrationsIssues or PRs related to integrations with open-source components
    on Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/integrationsIssues or PRs related to integrations with open-source componentskind/questionCategory issues related to questions or problems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions