<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Sentinel Dashboard(基于1.8.1)流控規則持久化到Nacos——涉及部分Sentinel Dashboard源碼改造

      前言

        之前雖然也一直在使用sentinel實現限流熔斷功能,但卻沒有好好整理之前看的源碼與資料,今天有時間將之前自己整理過的資料寫成一篇博文,或者是是一篇關于Sentinel(基于目前最近版本1.8,如果沒有特殊說明,都指最新1.8版本)持久化Nacos的指南,因為我發現網上的一些博文雖然有參考價值但卻沒有好好完善好細節,一知半解,或者版本比較老不具備參考價值。比如說為什么要做這一步,這一步需要完成什么具體工作等等。所以盡我所能,詳細介紹下手把手整合Sentinel與Nacos,實現Sentinel Dashboard控制臺到Nacos配置中心的流控規則通信并下發規則到具體應用

        前提是要對Sentinel Dashboard跟Nacos有一定的了解,具體可以查看官方wiki參考資料也是來源于此,再加上對sentinel-dashboard源碼參考改造

      博文中源碼已上傳至github(https://github.com/Jian0110/learning-cloudalibaba),歡迎小伙伴們star...


       

      一、準備工作

      1、Sentinel Dashboard持久化

        我們首先需要知道:在Sentinel Dashboard中配置規則之后重啟應用就會丟失,所以實際生產環境中需要配置規則的持久化實現,Sentinel提供多種不同的數據源來持久化規則配置,包括file,redis、nacos、zk。

        這就需要涉及到Sentinel Dashboard的規則管理及推送功能:集中管理和推送規則sentinel-core 提供 API 和擴展接口來接收信息。開發者需要根據自己的環境,選取一個可靠的推送規則方式;同時,規則最好在控制臺中集中管理。

        而規則管理推送主要有以下三種模式:

            

                      (以上部分文字跟截圖來源自官方wiki)

        很明顯,我們需要的是第三種Push模式,即Sentinel Dashboard統一管理配置(有良好的UI界面,為什么不能統一管理呢,明顯比Nacos編寫json要專業),然后將規則統一推送到Nacos并持久化(生成配置文件),最后客戶端監聽Nacos(這一部了解使用過Nacos的話應該很熟,采用ConfigService.getConfg()方法獲取配置文件),下發配置生成Rule。如下圖(虛線部分不推薦):

              

        換句話說就是實現Sentinel Dashboard與Nacos之間的相互通信:

      • Sentinel Dashboard界面配置流控規則---發布/推送--->Nacos生成配置文件并持久化;
      • 通過Nacos配置文件修改流控規則---拉取--->Sentinel Dashboard界面顯示最新的流控規則。

        需要注意的是:

      • 在Nacos控制臺上修改流控制,雖然可以同步到Sentinel Dashboard,但是Nacos此時應該作為一個流控規則的持久化平臺,所以正常操作過程應該是開發者在Sentinel Dashboard上修改流控規則后同步到Nacos,遺憾的是目前Sentinel Dashboard不支持該功能
      • 試想下,如果公司沒有統一在Sentinel Dashboard或Nacos中二選一進行配置,而是一會在Sentinel Dashboard配置,一會在Nacos配置。那么就會出現很嚴重的問題(流控規則達不到預期,配置數據不一致),所以推薦使用Sentinel Dashboard統一界面進行配置管理流控規則

      正因為Sentinel Dashboard當前版本(截至目前為止是1.8.1-SNAPSHOT)暫不支持,但是可以通過改造部分源碼實現此功能,具體請看下面介紹。

      2、Sentinel Dashboard流控規則源碼改造須知

      首先通過git拉取下載源碼,導入idea工程,解析maven后觀察sentinel-dashboard模塊目錄結構

      git clone https://github.com/alibaba/Sentinel.git

      github可能會很慢,如果只是研究源碼了解的話,有需要源碼打包的話,可以評論或私信發給你壓縮包。

      改造前,我們所要了解實現Sentinel Dashboard與Nacos相互通信需要經歷哪些流程或者說是缺少哪些流程,我們才好對癥下藥,根據我的理解我歸納總結出一下幾點

      (1)流控規則Controller入口

        Sentinel Dashboard的流控規則下的所有操作,都會調用Sentinel-Dashboard源碼中的FlowControllerV1類,這個類中包含流控規則本地化的CRUD操作;

                      

       在com.alibaba.csp.sentinel.dashboard.controller.v2包下存在一個FlowControllerV2;類,這個類同樣提供流控規則的CURD,與V1不同的是,它可以實現指定數據源的規則拉取和發布

              

        官方說明:

        從 Sentinel 1.4.0 開始,我們抽取出了接口用于向遠程配置中心推送規則以及拉取規則:

      • DynamicRuleProvider<T>: 拉取規則
      • DynamicRulePublisher<T>: 推送規則

        以 Nacos 為例,若希望使用 Nacos 作為動態規則配置中心,用戶可以提取出相關的類,然后只需在 FlowControllerV2 中指定對應的 bean 即可開啟 Nacos 適配

      @Autowired
      @Qualifier("flowRuleNacosProvider")
      private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
      @Autowired
      @Qualifier("flowRuleNacosPublisher")
      private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;

      所以根據官網說明,我們知道,FlowControllerV2依賴兩個非常重要的類

      • DynamicRuleProvider:動態規則的拉取,從指定數據源中獲取控制后在Sentinel Dashboard中展示。
      • DynamicRulePublisher:動態規則發布,將在Sentinel Dashboard中修改的規則同步到指定數據源中。

      只需要擴展這兩個類,然后集成Nacos來實現Sentinel Dashboard規則同步

      (2)Sentinel Dashboard前端sidebar.html頁面入口

      在目錄resources/app/scripts/directives/sidebar找到sidebar.html,里面有關于V1版本的請求入口:

      <li ui-sref-active="active" ng-if="!entry.isGateway">
          <a ui-sref="dashboard.flowV1({app: entry.app})">
            <i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控規則</a>
      </li>

       對應的JS請求如下,可以看到請求就是V1版本的Controller,那么之后的改造需要重新對應V2版本的Controller

      .state('dashboard.flowV1', {
              templateUrl: 'app/views/flow_v1.html',
              url: '/flow/:app',
              controller: 'FlowControllerV1',
              resolve: {
                loadMyFiles: ['$ocLazyLoad', function ($ocLazyLoad) {
                  return $ocLazyLoad.load({
                    name: 'sentinelDashboardApp',
                    files: [
                      'app/scripts/controllers/flow_v1.js',
                    ]
                  });
                }]
              }
            })

      (3)Sentinel Dashboard缺少Nacos配置

      在源碼中雖然官方提供了test示例(即test目錄)下關于Nacos等持久化示例,但是具體的實現還需要一些細節,比如在Sentinel Dashboard配置Nacos的serverAddr、namespace、groupId,并且通過Nacos獲取配置文件獲取服務列表等。

                      

      例如:NacosConfig中ConfigFactory.createConfigService("localhost")并沒有實現創建具體的nacos config service,而是默認localhost

      @Configuration
      public class NacosConfig {
      
          @Bean
          public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
              return JSON::toJSONString;
          }
      
          @Bean
          public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
              return s -> JSON.parseArray(s, FlowRuleEntity.class);
          }
      
          @Bean
          public ConfigService nacosConfigService() throws Exception {
              return ConfigFactory.createConfigService("localhost");
          }
      }

      application.properties文件中也沒有Nacos的相關配置

      #spring settings
      spring.http.encoding.force=true
      spring.http.encoding.charset=UTF-8
      spring.http.encoding.enabled=true
      
      #cookie name setting
      server.servlet.session.cookie.name=sentinel_dashboard_cookie
      
      #logging settings
      logging.level.org.springframework.web=INFO
      logging.file=C:\\Users\\Administrator/logs/csp/sentinel-dashboard.log
      logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
      #logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
      
      #auth settings
      auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version
      auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png
      # If auth.enabled=false, Sentinel console disable login
      auth.username=sentinel
      auth.password=sentinel
      
      # Inject the dashboard version. It's required to enable
      # filtering in pom.xml for this resource file.
      sentinel.dashboard.version=1.8.1-SNAPSHOT

      (4)流控規則配置文件約束

      在NacosConfigutils已經指定了默認的流控規則配置文件的groupId等,但是如果需要指定的話這里也需要修改

      public final class NacosConfigUtil {
      
      
          /**
           * 流控規則配置文件默認在SENTINEL_GROUP組、DATA_ID以-flow-rules結尾
           */
          public static final String FLOW_DATA_ID_POSTFIX = "-flow-rules";
          public static final String GROUP_ID = "SENTINEL_GROUP";
          // 省略
      
      }

      這樣我們在Sentinel客戶端就可以這么配置指定流控規則配置文件約束了

      spring.cloud.sentinel.datasource.flow.nacos.server-addr=127.0.0.1:8848
      spring.cloud.sentinel.datasource.flow.nacos.data-id=${spring.application.name}-flow-rules
      spring.cloud.sentinel.datasource.flow.nacos.group-id=SENTINEL_GROUP
      spring.cloud.sentinel.datasource.flow.nacos.data-type=json
      spring.cloud.sentinel.datasource.flow.nacos.rule-type=flow

       

      二、改造Sentinel Dashboard源碼實現Nacos持久化

      有了以上的須知以及改造前準備工作之后,我們可以開始進行改造源碼,其中需要修改部分都會做相關注釋

      1、在pom.xml文件中去掉test scope注釋

      這是因為官方提供的Nacos持久化用例都是在test目錄下,所以scope需要去除test,要sentinel-datasource-nacos包的支持。之后將修改好的源碼放在源碼主目錄下,而不是繼續在test目錄下。

       <!-- for Nacos rule publisher sample -->
              <dependency>
                  <groupId>com.alibaba.csp</groupId>
                  <artifactId>sentinel-datasource-nacos</artifactId>
                  <!--<scope>test</scope>-->
              </dependency>

      2、修改前端路由配置(sidebar.html)

      找到resources/app/scripts/directives/sidebar/sidebar.html文件修改,修改flowV1為flow,去掉V1,這樣的話會調用FlowControllerV2接口

        <!--<li ui-sref-active="active" ng-if="!entry.isGateway">
                  <a ui-sref="dashboard.flowV1({app: entry.app})">
                    <i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控規則</a>
                </li>-->
                <!-- 修改為flow,直接調用FlowControllerV2 -->
                <li ui-sref-active="active" ng-if="!entry.isGateway">
                  <a ui-sref="dashboard.flow({app: entry.app})">
                    <i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控規則</a>
                </li>

      這樣就可以通過js跳轉至FlowControllerV2了

            .state('dashboard.flow', {
                templateUrl: 'app/views/flow_v2.html',
                url: '/v2/flow/:app',
                controller: 'FlowControllerV2',
                resolve: {
                    loadMyFiles: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'sentinelDashboardApp',
                            files: [
                                'app/scripts/controllers/flow_v2.js',
                            ]
                        });
                    }]
                }
            })

      3、創建nacos配置

      (1)流控配置文件約束

      我們采用官方的約束,即 默認 Nacos 適配的 dataId 和 groupId 約定如下:

      • groupId: SENTINEL_GROUP
      • 流控規則 dataId: {appName}-flow-rules,比如應用名為 appA,則 dataId 為 appA-flow-rules

      所以不需要修改NacosConfigUtil.java了,但這是展示是為了步驟的完整性。

      (2)創建讀取nacos配置的NacosPropertiesConfiguration文件并且application.properties指定配置

      package com.alibaba.csp.sentinel.dashboard.rule.nacos;
      
      import org.springframework.boot.context.properties.ConfigurationProperties;
      
      @ConfigurationProperties(prefix = "sentinel.nacos")
      public class NacosPropertiesConfiguration {
          private String serverAddr;
          private String dataId;
          private String groupId = "SENTINEL_GROUP"; // 默認分組
          private String namespace;
         // 省略 getter/setter  
      }

      然后配置sentinel-dashboar/resources/application.properties中配置nacos配置,以為sentinel.nacos為前綴:

      # nacos config server
      sentinel.nacos.serverAddr=127.0.0.1:8848
      sentinel.nacos.namespace=
      sentinel.nacos.group-id=SENTINEL-GROUP

      (3)改造NacosConfig,創建NacosConfigService

      @EnableConfigurationProperties(NacosPropertiesConfiguration.class)
      @Configuration
      public class NacosConfig {
      
          @Bean
          public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
              return JSON::toJSONString;
          }
      
          @Bean
          public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
              return s -> JSON.parseArray(s, FlowRuleEntity.class);
          }
      
          @Bean
          public ConfigService nacosConfigService(NacosPropertiesConfiguration nacosPropertiesConfiguration) throws Exception {
              Properties properties = new Properties();
              properties.put(PropertyKeyConst.SERVER_ADDR, nacosPropertiesConfiguration.getServerAddr());
              properties.put(PropertyKeyConst.NAMESPACE, nacosPropertiesConfiguration.getNamespace());
              return ConfigFactory.createConfigService(properties);
      //        return ConfigFactory.createConfigService("localhost");
          }
      }

      NacosConfig主要做兩件事:

      1) 注入Convert轉換器,將FlowRuleEntity轉化成FlowRule,以及反向轉化

      2) 注入Nacos配置服務ConfigService

      4、動態實現從Nacos配置中心獲取流控規則——重寫FlowRuleNacosProvider與FlowRuleNacosPublisher類

      重寫FlowRuleNacosProvider類

      @Service("flowRuleNacosProvider")
      public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleEntity>> {
          public static final Logger log = LoggerFactory.getLogger(FlowRuleNacosProvider.class);
      
          @Autowired
          private ConfigService configService;
          @Autowired
          private Converter<String, List<FlowRuleEntity>> converter;
      
      
          /**
           * 1)通過ConfigService的getConfig()方法從Nacos Config Server讀取指定配置信息
           * 2)通過轉為converter轉化為FlowRule規則
           * @param appName
           * @return
           * @throws Exception
           */
          @Override
          public List<FlowRuleEntity> getRules(String appName) throws Exception {
              String rules = configService.getConfig(appName + NacosConfigUtil.FLOW_DATA_ID_POSTFIX,
                  NacosConfigUtil.GROUP_ID, 3000);
              log.info("obtain flow rules from nacos config:{}", rules);
              if (StringUtil.isEmpty(rules)) {
                  return new ArrayList<>();
              }
              return converter.convert(rules);
          }
      }

      重寫FlowRuleNacosPublisher類:

      @Service("flowRuleNacosPublisher")
      public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRuleEntity>> {
          public static final Logger log = LoggerFactory.getLogger(FlowRuleNacosPublisher.class);
          @Autowired
          private ConfigService configService;
          @Autowired
          private Converter<List<FlowRuleEntity>, String> converter;
      
      
          /**
           * 通過configService的publishConfig()方法將rules發布到nacos
           * @param app app name
           * @param rules list of rules to push
           * @throws Exception
           */
          @Override
          public void publish(String app, List<FlowRuleEntity> rules) throws Exception {
              AssertUtil.notEmpty(app, "app name cannot be empty");
              if (rules == null) {
                  return;
              }
              log.info("sentinel dashboard push rules: {}", rules);
              configService.publishConfig(app + NacosConfigUtil.FLOW_DATA_ID_POSTFIX,
                  NacosConfigUtil.GROUP_ID, converter.convert(rules));
          }
      }

      5、復制到源碼主目錄下

        之后需要將上述文件(com.alibaba.csp.sentinel.dashboard.test.rule.nacos)復制到com.alibaba.csp.sentinel.dashboard.rule.nacos目錄下,即去掉test目錄,這樣是以內源碼中Nacos等持久化的配置都是在test中,打包jar的時候并不會打包進去,所以需要copy到主源碼目錄下。

                    

      6、修改FlowControllerV2類,使用@Qulifier將上面配置的兩個類注入進來

      @RestController
      @RequestMapping(value = "/v2/flow")
      public class FlowControllerV2 {
      
          private final Logger logger = LoggerFactory.getLogger(FlowControllerV2.class);
      
          @Autowired
          private InMemoryRuleRepositoryAdapter<FlowRuleEntity> repository;
      
          /*@Autowired
          @Qualifier("flowRuleDefaultProvider")
          private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
          @Autowired
          @Qualifier("flowRuleDefaultPublisher")
          private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;*/
          /**
           * 修改默認publisher/provider為Nacos
           * 使用@Qualifier指定bean
           */
          @Autowired
          @Qualifier("flowRuleNacosProvider")
          private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
          @Autowired
          @Qualifier("flowRuleNacosPublisher")
          private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
      
          // 省略      
      }

      7、mvn clean package打包

      先install sentinel-parent保證依賴包已經install到本地repository

      之后打包sentinel-dashboard模塊,執行mvn clean package命令,打包成jar包

      如果以上步驟嫌麻煩,或者中間過程哪里有問題,可以私信我直接要jar包。

      三、流控規則持久化測試

      1、編寫Sentinel客戶端

      (1)創建springboot應用,編寫pom文件如下:

      <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
              <maven.compiler.source>1.8</maven.compiler.source>
              <maven.compiler.target>1.8</maven.compiler.target>
              <sentinel.version>1.8.1-SNAPSHOT</sentinel.version>
          </properties>
          <dependencies>
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
              </dependency>
              <!--  sentinel核心庫 -->
              <dependency>
                  <groupId>com.alibaba.csp</groupId>
                  <artifactId>sentinel-core</artifactId>
                  <version>${sentinel.version}</version>
              </dependency>
              <!-- 通過nacos持久化流控規則 -->
              <dependency>
                  <groupId>com.alibaba.csp</groupId>
                  <artifactId>sentinel-datasource-nacos</artifactId>
                  <version>${sentinel.version}</version>
              </dependency>
              <!--  sentinel AspectJ 的擴展用于自動定義資源 -->
              <dependency>
                  <groupId>com.alibaba.csp</groupId>
                  <artifactId>sentinel-annotation-aspectj</artifactId>
                  <version>${sentinel.version}</version>
              </dependency>
              <!-- sentinel 整合spring cloud alibaba -->
              <dependency>
                  <groupId>com.alibaba.cloud</groupId>
                  <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
                  <version>2.1.2.RELEASE</version>
              </dependency>
      
              <!-- sentinel客戶端與dashboard通信依賴 -->
              <dependency>
                  <groupId>com.alibaba.csp</groupId>
                  <artifactId>sentinel-transport-simple-http</artifactId>
                  <version>${sentinel.version}</version>
              </dependency>
          </dependencies>

      (2)配置nacos,配置sentinel dashboard datasource信息:

        1)bootstrap.properties中配置Nacos Config Server

      spring.cloud.nacos.config.server-addr=127.0.0.1:8848

        2)application.properties配置sentinel dashboard datasource

      server.port=6003
      spring.application.name=sentinel
      management.endpoints.web.exposure.include=*
      spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
      spring.cloud.sentinel.transport.dashboard=127.0.0.1:6005
      #指定csp.sentinel.api.port時需要配置,否則默認8719
      #spring.cloud.sentinel.transport.port=6007
      
      # sentinel nacos配置
      spring.cloud.sentinel.datasource.flow.nacos.server-addr=127.0.0.1:8848
      spring.cloud.sentinel.datasource.flow.nacos.data-id=${spring.application.name}-flow-rules
      spring.cloud.sentinel.datasource.flow.nacos.group-id=SENTINEL_GROUP
      spring.cloud.sentinel.datasource.flow.nacos.data-type=json
      spring.cloud.sentinel.datasource.flow.nacos.rule-type=flow

      (3)編寫SayHelloController,指定/hello資源節點

      package com.cloud.controller;
      
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RestController;
      
      @RestController
      public class SayHelloController {
      
          @RequestMapping("/hello")
          public String sayHello(){
              return "hello Jian";
          }
      }

      2、啟動Nacos

      我使用的是win10下啟動nacos,之后登錄Nacos

      查看起初是沒有${spring.application.name}-flow-rules配置文件,也沒有SENTINEL-GROUP分組;

      但是服務列表會sentinel客戶端實例:

      分配的虛擬IP與port

      3、啟動sentinel dashboard控制臺

      (1)啟動sentinel dashboard

       找到target/sentinel-dashboard.jar,執行命令:

      java -Dserver.port=6005 -Dcsp.sentinel.dashboard.server=localhost:6006 -Dproject.name=sentinel-dashboard -Dcsp.sentinel.api.port=6007 -jar target/sentinel-dashboard.jar

      具體的啟動參數介紹:

        -Dserver.port=6005 控制臺端口,sentinel控制臺是一個spring boot程序。客戶端配置文件需要填對應的配置,如:spring.cloud.sentinel.transport.dashboard=192.168.1.102:8718
        -Dcsp.sentinel.dashboard.server=localhost:6007 控制臺的地址,指定控制臺后客戶端會自動向該地址發送心跳包。
        -Dproject.name=sentinel-dashboard  指定Sentinel控制臺程序的名稱
        -Dcsp.sentinel.api.port=8719 可選項,客戶端提供給Dashboard訪問或者查看Sentinel的運行訪問的參數,默認8719

      其它啟動配置項,具體查看官方wiki

      (2)登錄sentinel dashboard配置流控規則

       1)輸入localhost:6005訪問sentinel dashboard控制臺(登錄用戶/密碼默認sentinel)

       2)選擇sentinel菜單-流控規則-新增流控規則-輸入配置-新增

        

         如圖所示,我們選擇QPS閾值類型,并且count為2,流控模式為默認的直接模式,流控效果快速失敗(這些配置具體含義參看官網wiki)  

      注意:一開始可能會空白頁面,這可能是由于機器時間機制導致的,此時可能還未發送心跳,加之sentinel控制臺默認的又是懶加載模式(可去除該設置),所以最好是我們訪問sentinel客戶端的/hello接口然后刷新頁面,即訪問:http://192.168.1.156:6003/hello(ip:port是由Nacos分配的虛擬地址)

      4、訪問/hello接口

      不停刷新訪問/hello接口,觀察sentinel dashboard界面中的實時監控。看到有通過QPS與拒絕QPS的實時監控情況,說明該sentinel客戶端已成功接入sentinel dashboard。

      5、測試Sentinel Dashboard流控規則到Nacos的持久化

      (1)確認Sentinel Dashboard是否能正確發布流控規則到Nacos

        在Sentinel Dashboard針對sentinel客戶端的/hello資源節點已經配置了流控規則

        

        此時Nacos會對此次流控規則生成持久化配置文件,切換到Nacos-配置列表查看確實存在分組SENTINEL_GROUP下的sentinel-flow-rules配置文件

        

        點擊查看具體內容,發現關鍵信息都是正確的,說明Sentinel Dashboard發布到Nacos通信已經打通

        

      (2)確認Sentinel Dashboard從nacos拉取流控規則配置是否成功

        修改分組SENTINEL_GROUP下的sentinel-flow-rules配置文件,修改count(QPS數)為5,然后點擊發布

        

        發布后切換到Sentinel Dashboard查看/hello資源點的流控規則的閾值是否發生變化

        

        明顯已經發生變化,因為Sentinel Dashboard是懶加載模式,所以刷新后后臺才有日志輸出:

      2020-12-15 19:40:11.499  INFO 11196 --- [nio-6005-exec-8] c.a.c.s.d.r.nacos.FlowRuleNacosProvider  : obtain flow rules from nacos config:[{"app":"sentinel","clusterConfig":{"acquireRef
      useStrategy":0,"clientOfflineTime":2000,"fallbackToLocalWhenFail":true,"resourceTimeout":2000,"resourceTimeoutStrategy":0,"sampleCount":10,"strategy":0,"thresholdType":0,"windowInterva
      lMs":1000},"clusterMode":false,"controlBehavior":0,"count":2.0,"gmtCreate":1608026073444,"gmtModified":1608026073444,"grade":1,"id":2,"ip":"169.254.102.85","limitApp":"default","port":
      8720,"resource":"/hello","strategy":0}]
      2020-12-15 19:51:22.612  INFO 11196 --- [nio-6005-exec-9] c.a.c.s.d.r.nacos.FlowRuleNacosProvider  : obtain flow rules from nacos config:[{"app":"sentinel","clusterConfig":{"acquireRef
      useStrategy":0,"clientOfflineTime":2000,"fallbackToLocalWhenFail":true,"resourceTimeout":2000,"resourceTimeoutStrategy":0,"sampleCount":10,"strategy":0,"thresholdType":0,"windowInterva
      lMs":1000},"clusterMode":false,"controlBehavior":0,"count":5.0,"gmtCreate":1608026073444,"gmtModified":1608026073444,"grade":1,"id":2,"ip":"169.254.102.85","limitApp":"default","port":
      8720,"resource":"/hello","strategy":0}]

        這說明Sentinel Dashboard能從nacos成功拉取流控規則配置

       (3)驗證流控規則是否生效

        此時我們的QPS閾值為5,也就是說1s之間內我們需要超過訪問5次,則會被sentinel限流。不斷訪問/hello資源節點,觀察返回

        

        返回Blocked By Sentinel(flow limiting)說明限流規則已經生效此時實時監控上也會出現通過的QPS數目為5

        

       

      posted @ 2020-12-15 20:15  JJian  閱讀(13105)  評論(47)    收藏  舉報
      主站蜘蛛池模板: 人妻激情偷乱一区二区三区| 国产精品久久久久久久9999| 亚洲岛国成人免费av| 欧美福利电影A在线播放| 日本高清无卡码一区二区久久| 在线a亚洲老鸭窝天堂| 换着玩人妻中文字幕| 成人免费无遮挡无码黄漫视频| 亚洲毛片多多影院| 少妇久久久被弄到高潮| 亚洲毛片多多影院| 91精品国产一二三产区| 国产又爽又大又黄a片| 欧美裸体xxxx极品| 久久久无码精品国产一区| 久久国产精品精品国产色婷婷| av在线播放国产一区| 精品人妻av区乱码| 精品国产一区二区三区大| 日韩中文字幕v亚洲中文字幕| 精品国产一区二区色老头| 国产午夜A理论毛片| 羞羞影院午夜男女爽爽免费视频| 成人一区二区三区在线午夜| 午夜精品久久久久久| 成人亚洲a片v一区二区三区动漫| 1024你懂的国产精品| 亚洲爽爆av一区二区| 亚洲日韩国产精品第一页一区| 国产毛片精品av一区二区 | 丰满少妇69激情啪啪无| 久久精品夜色国产亚洲av| 99蜜桃在线观看免费视频网站| 美日韩精品综合一区二区| 普兰店市| 亚洲大尺度无码无码专线| 国产精品99久久免费| 无码国内精品人妻少妇| 女人扒开的小泬高潮喷小| 肉大捧一进一出免费视频| 少妇人妻综合久久中文字幕|