Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentinel 链路流控模式失效 #1213

Closed
xinmingguo-hm opened this issue Dec 20, 2019 · 5 comments
Closed

Sentinel 链路流控模式失效 #1213

xinmingguo-hm opened this issue Dec 20, 2019 · 5 comments

Comments

@xinmingguo-hm
Copy link

@xinmingguo-hm xinmingguo-hm commented Dec 20, 2019

我现在使用的是 spring-cloud-alibaba 2.1.0.RELEASE版本, 控制台用的是1.7.1版本,目前遇到的问题是流控规则-流控模式-链路模式不生效
I am using spring cloud Alibaba version 2.1.0.release, and the console version 1.7.1. The current problem is that the flow control rule flow control mode link mode is not effective

code:
Snipaste_2019-12-20_18-09-04

configure:
Snipaste_2019-12-20_18-04-54

Snipaste_2019-12-20_18-06-31

在这种配置下,目前message1和message2 都限制失败
In this configuration, the current message1 and message2 restrictions fail

@sczyh30

This comment has been minimized.

Copy link
Member

@sczyh30 sczyh30 commented Dec 20, 2019

Since 1.6.3, the web CommonFilter would unify the web entrance context, so the entrance flow control does not take effect. Sentinel 1.7.0 (~SCA 2.1.1.RELEASE) introduced an init parameter for the CommonFilter: WEB_CONTEXT_UNIFY, to control the context. You could set it to false when adding the FilterRegistration.

/**
* If enabled, use the URL path as the context name, or else use the default
* {@link WebServletConfig#WEB_SERVLET_CONTEXT_NAME}. Please pay attention to the number of context (EntranceNode),
* which may affect the memory footprint.
*
* @since 1.7.0
*/
public static final String WEB_CONTEXT_UNIFY = "WEB_CONTEXT_UNIFY";

See also #1024 for the background.


从 1.6.3 版本开始,Sentinel Web filter 默认收敛所有 URL 的入口 context,因此链路限流不生效。1.7.0 版本开始(对应 SCA 2.1.1.RELEASE),我们在 CommonFilter 引入了 WEB_CONTEXT_UNIFY 这个 init parameter,用于控制是否收敛 context。将其配置为 false 即可根据不同的 URL 进行链路限流。

@xinmingguo-hm

This comment has been minimized.

Copy link
Author

@xinmingguo-hm xinmingguo-hm commented Dec 20, 2019

可不可以这样理解:1.6.3 版本无法使用链路限流,1.7.0之后,可以通过配置开启链路限流?
能不能给出一个配置的事例

@lazzman

This comment has been minimized.

Copy link

@lazzman lazzman commented Dec 23, 2019

在spring-cloud-alibaba v2.1.1.RELEASE及前,sentinel1.7.0及后,关闭URL PATH聚合需要通过下面方式:

  1. 配置文件中关闭sentinel的CommonFilter实例化spring.cloud.sentinel.filter.enabled=false
  2. 添加一个配置类,自己构建CommonFilter实例
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterContextConfig {

    /**
     * @NOTE 在spring-cloud-alibaba v2.1.1.RELEASE及前,sentinel1.7.0及后,关闭URL PATH聚合需要通过该方式,spring-cloud-alibaba v2.1.1.RELEASE后,可以通过配置关闭:spring.cloud.sentinel.web-context-unify=false
     * 手动注入Sentinel的过滤器,关闭Sentinel注入CommonFilter实例,修改配置文件中的 spring.cloud.sentinel.filter.enabled=false
     * 入口资源聚合问题:https://github.com/alibaba/Sentinel/issues/1024 或 https://github.com/alibaba/Sentinel/issues/1213
     * 入口资源聚合问题解决:https://github.com/alibaba/Sentinel/pull/1111
     */
    @Bean
    public FilterRegistrationBean sentinelFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CommonFilter());
        registration.addUrlPatterns("/*");
        // 入口资源关闭聚合
        registration.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
        registration.setName("sentinelFilter");
        registration.setOrder(1);
        return registration;
    }

}

spring-cloud-alibaba v2.1.1.RELEASE后,可以通过配置关闭

spring.cloud.sentinel.web-context-unify=false

@sczyh30

This comment has been minimized.

Copy link
Member

@sczyh30 sczyh30 commented Dec 23, 2019

It will be supported to configure this in Spring config file with Spring Cloud Alibaba Sentinel. The relevant issue: alibaba/spring-cloud-alibaba#1138

@xinmingguo-hm

This comment has been minimized.

Copy link
Author

@xinmingguo-hm xinmingguo-hm commented Dec 24, 2019

配置了, 好使的, 多谢各位大神的支持.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.