Synchronization of Sentinel-Dashboard and apollo rules

1. Why do you need to transform Sentinel:

        The Sentinel-Dashboard console is the portal for unified configuration and management of flow control, fuse and downgrade rules. It provides users with functions such as machine self-discovery, cluster point link self-discovery, monitoring, and rule configuration. On the Sentinel console, we can configure rules and view traffic control effects in real time. Earlier, we also introduced a series of operations such as the construction and deployment of sentinel-dashboard, the integration of sentinel in springcloud for flow control and fusing, and the  persistence of Sentinel rules to the apollo configuration center . In this article, we will introduce how to transform Sentinel to make It is more in line with the requirements of the production environment.

​So         why do you need to revamp Sentinel? The main reason is that all rules can only be modified through the Nacos interface or Apollo interface to get persistent storage, and although the current limiting rules are modified in Sentinel Dashboard, they can take effect, but they will not be persisted to the configuration center. The data stored in these two configuration centers is in a Json format. When more and more rules are stored, the readability and maintainability of the Json configuration will become worse and worse.

        ​So how to transform it? To answer this question, we need to understand how Sentinel manages rules.

1. Sentinel's rule management method:

        Sentinel provides two ways to modify rules. The first is to directly modify (loadRules) through API coding, but the coding method is generally used for testing and demonstration; the second is to modify different data sources through DataSource, and the production environment Generally, this method is used to dynamically manage rules. There are three modes for the management of dynamic rule sources in Sentinel:

(1) Native mode: Sentinel Dashboard pushes rules to Sentinel Client through API and updates them directly to Sentinel Client memory. Because rules are stored in memory, they will be lost as long as the project is restarted, so it is not recommended for production environments

(2) Pull mode: that is, pull mode, Sentinel Client actively polls a rule management center to pull rules regularly, so real-time performance cannot be guaranteed. If the pull is too frequent, it may cause performance problems. The following figure takes the local file data source as an example. The push process is shown in the figure below:

(3) push mode: push mode, which is uniformly pushed by the rule center. Sentinel Client monitors changes at all times by registering listeners, such as using configuration centers such as Nacos, Apollo, ZooKeeper, etc. This method has better real-time and consistency Sexual Guarantee. In the production environment, it is recommended to use the data source in the push mode. The push operation should be managed and pushed by the Sentinel dashboard and the Config Center Dashboard console. It should not be pushed to the configuration center through the Sentinel Client. Configure and update to the local, so the correct way to push the rules should be: Configuration Center Console/Sentinel Console → Configuration Center → Sentinel Client.

2. Sentinel's transformation content:

2.1. Data flow diagram before and after transformation:

        After understanding Sentinel's rule management method, we can definitely understand the reason why we need to transform the original rule management mode into the push mode when using Sentinel in the production environment. The data flow diagram before and after the transformation of Sentinel is as follows:

  • The blue arrow represents the update path of the current limiting rule modified by the configuration center
  • The orange arrow represents the update path of the current limit rule modified by Sentinel Dashboard
  • The green arrow is the public part, that is, the actions that are triggered whether it is modified from the configuration center or from the Sentinel Dashboard.

        It can be clearly seen from the figure that before the integration of the configuration center to store the rules, Sentinel Dashboard and business services can communicate with each other to obtain the latest current limiting rules. After the integration of the configuration center but before the Sentinel-dashboard is transformed, the modification of the configuration center can be refreshed to the business service in real time, and then read by the Sentinel Dashboard, but after the Sentinel dashboard updates these rules to each business service, There is no mechanism for synchronizing rules to the configuration center. However, after the transformation, from the starting point of the two modifications in the above figure, all involved parts can obtain consistent current limiting rules.

2.2. Core transformation points:

From the above figure, we can see that the content we need to modify is as follows:

(1) Sentinel dashboard console:

  • ① Sentinel dashboard console writes rules to apollo/nacos configuration center for persistence
  • ② Sentinel dashboard can update the rules modified by apollo/nacos console in real time

(2)Sentinel Client:

  • ① Sentinel Client updates the rules modified by the apollo/nacos configuration center in real time

Second, the transformation of Sentinel:

This part of the article uses apollo as the configuration center to introduce how to transform Sentinel. The Nacos-based transformation method is recommended to refer to the following articles:

https://www.freesion.com/article/30571440125/

https://www.imooc.com/article/289464

https://github.com/tanjiancheng/alibaba-sentinel-dashboard-nacos

1. The transformation of Sentinel dashboard:

        This article is based on sentinel-dashboard 1.7.2 version, you need to download the official source code to the local for transformation: https://github.com/alibaba/Sentinel/tree/release-1.7/sentinel-dashboard

1.1. Add apollo dependencies and configurations:

        Sentinel-dashboard integrates apollo for persistent configuration of rules. The main way is to write and read through the authorization method of the apollo open platform, so the following dependencies need to be introduced in the pom.xml file:

 <dependency>
     <groupId>com.ctrip.framework.apollo</groupId>
     <artifactId>apollo-openapi</artifactId>
     <version>1.7.0</version>
     <scope>compile</scope>
 </dependency>

        After the introduction, add the configuration of apollo to the configuration file of sentinel-dashboard. The following parts of the article on how to obtain the configuration parameters will be introduced:

# apollo的中配置的appId
app.id=sentinel-rules
# 如果apollo配置中心控制台的访问地址
apollo.meta=http://portal.xxx.net
# token获取方法下文会介绍
apollo.token=ccc082b44f06f2ae9552bf67a710f36c36e6b777
# apollo的登录用户
apollo.user=apollo
# apollo的集群名称 没有的话请使用default
apollo.clusterName=default
# apollo的命名空间 默认使用application,但考虑到该空间需要给所有项目共同使用,因此单独创建了一个公共空间
apollo.namespaceName=EDU001.sentinel-rules

        Next, we transform according to the following two core steps:

(1) Step 1: Add and implement the configuration pull and push interfaces of Provider and Publisher for all rules, instead obtain rule information from apollo, and save the added and modified rules to apollo

(2) Step 2: Introduce the transformed Provider and Publisher interfaces in the Controller layer, and the transformed Provider and Publisher interfaces are responsible for processing operations initiated by sentinel-dashboard Kanban

1.2. Code and storage configuration of rules in Apollo:

(1) The encoding configuration of sentinel rules in apollo:

package com.alibaba.csp.sentinel.dashboard.rule.apollo;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.fastjson.JSON;
import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class ApolloConfig {

    @Value("${apollo.meta}")
    private String portalUrl;
    @Value("${apollo.token}")
    private String token;

    /**
     * 流控规则编码
     */
    @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 Converter<List<DegradeRuleEntity>, String> degradeRuleEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 降级规则解码
     */
    @Bean
    public Converter<String, List<DegradeRuleEntity>> degradeRuleEntityDecoder() {
        return s -> JSON.parseArray(s, DegradeRuleEntity.class);
    }

    /**
     * 授权规则编码
     */
    @Bean
    public Converter<List<AuthorityRuleEntity>, String> authorityRuleEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 授权规则解码
     */
    @Bean
    public Converter<String, List<AuthorityRuleEntity>> authorityRuleEntityDecoder() {
        return s -> JSON.parseArray(s, AuthorityRuleEntity.class);
    }

    /**
     * 系统规则编码
     */
    @Bean
    public Converter<List<SystemRuleEntity>, String> systemRuleEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 系统规则解码
     */
    @Bean
    public Converter<String, List<SystemRuleEntity>> systemRuleEntityDecoder() {
        return s -> JSON.parseArray(s, SystemRuleEntity.class);
    }

    /**
     * 热点规则编码
     */
    @Bean
    public Converter<List<ParamFlowRuleEntity>, String> paramFlowRuleEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 热点规则解码
     */
    @Bean
    public Converter<String, List<ParamFlowRuleEntity>> paramFlowRuleEntityDecoder() {
        return s -> JSON.parseArray(s, ParamFlowRuleEntity.class);
    }

    /**
     * 集群流控规则编码
     */
    @Bean
    public Converter<List<ClusterAppAssignMap>, String> clusterGroupEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 集群流控规则解码
     */
    @Bean
    public Converter<String, List<ClusterAppAssignMap>> clusterGroupEntityDecoder() {
        return s -> JSON.parseArray(s, ClusterAppAssignMap.class);
    }

    /**
     * API管理分组编码
     */
    @Bean
    public Converter<List<ApiDefinitionEntity>, String> apiDefinitionEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * API管理分组解码
     */
    @Bean
    public Converter<String, List<ApiDefinitionEntity>> apiDefinitionEntityDecoder() {
        return s -> JSON.parseArray(s, ApiDefinitionEntity.class);
    }

    /**
     * 网关流控规则编码
     */
    @Bean
    public Converter<List<GatewayFlowRuleEntity>, String> gatewayFlowRuleEntityEncoder() {
        return JSON::toJSONString;
    }

    /**
     * 网关流控规则解码
     */
    @Bean
    public Converter<String, List<GatewayFlowRuleEntity>> gatewayFlowRuleEntityDecoder() {
        return s -> JSON.parseArray(s, GatewayFlowRuleEntity.class);
    }

    @Bean
    public ApolloOpenApiClient apolloOpenApiClient() {
        ApolloOpenApiClient client = ApolloOpenApiClient.newBuilder()
            .withPortalUrl(portalUrl)
            .withToken(token)
            .build();
        return client;
    }
}

(2) The prefix/suffix of the key value stored in Apollo by sentinel rules:

package com.alibaba.csp.sentinel.dashboard.rule.apollo;

public final class ApolloConfigUtil
{
    /**
     * 网关-api分组id
     */
    public static final String GATEWAY_API_GROUP_DATA_ID_POSTFIX = "gw-api-group-rules";

    /**
     * 网关-流控规则id
     */
    public static final String GATEWAY_FLOW_DATA_ID_POSTFIX = "gw-flow-rules";

    /**
     * 流控规则id
     */
    public static final String FLOW_DATA_ID_POSTFIX = "flow-rules";
    /**
     * 降级规则id
     */
    public static final String DEGRADE_DATA_ID_POSTFIX = "degrade-rules";
    /**
     * 热点规则id
     */
    public static final String PARAM_FLOW_DATA_ID_POSTFIX = "param-flow-rules";
    /**
     * 系统规则id
     */
    public static final String SYSTEM_DATA_ID_POSTFIX = "system-rules";
    /**
     * 授权规则id
     */
    public static final String AUTHORITY_DATA_ID_POSTFIX = "authority-rules";
    /**
     * 集群流控id
     */
    public static final String CLUSTER_GROUP_DATA_ID_POSTFIX = "cluster-group-rules";

    private ApolloConfigUtil()
    {
    }

    public static String getGatewayFlowDataId(String appName)
    {
        return String.format("%s-%s", appName, GATEWAY_FLOW_DATA_ID_POSTFIX);
    }

    public static String getGatewayApiGroupDataId(String appName)
    {
        return String.format("%s-%s", appName, GATEWAY_API_GROUP_DATA_ID_POSTFIX);
    }

    public static String getClusterGroupDataId(String appName)
    {
        return String.format("%s-%s", appName, CLUSTER_GROUP_DATA_ID_POSTFIX);
    }

    public static String getFlowDataId(String appName)
    {
        return String.format("%s-%s", appName, FLOW_DATA_ID_POSTFIX);
    }

    public static String getDegradeDataId(String appName)
    {
        return String.format("%s-%s", appName, DEGRADE_DATA_ID_POSTFIX);
    }

    public static String getParamFlowDataId(String appName)
    {
        return String.format("%s-%s", appName, PARAM_FLOW_DATA_ID_POSTFIX);
    }

    public static String getSystemDataId(String appName)
    {
        return String.format("%s-%s", appName, SYSTEM_DATA_ID_POSTFIX);
    }

    public static String getAuthorityDataId(String appName)
    {
        return String.format("%s-%s", appName, AUTHORITY_DATA_ID_POSTFIX);
    }
}

1.3. Added Provider and Publisher:

        Sentinel Dashboard has extracted interfaces for pushing rules and pulling rules to the remote configuration center since version 1.4.0: DynamicRuleProvider pull rules, DynamicRulePublisher push rules, so, only need to pass these two interfaces, to achieve the configuration center The reading and writing of storage rules can achieve the effect of synchronization between modification rules in Sentinel Dashboard and configuration center storage.

        Only the modification cases of flow control rules are provided here. The modification of other rule types (flow control/degradation/hotspot/system/authorization) is basically the same as that of flow control, so it will not be repeated:

(1) Add a new provider and query the persistent rules from the Apollo configuration center:

@Component("flowRuleApolloProvider")
public class FlowRuleApolloProvider implements DynamicRuleProvider<List<FlowRuleEntity>> {

    @Autowired
    private ApolloOpenApiClient apolloOpenApiClient;
    @Autowired
    private Converter<String, List<FlowRuleEntity>> converter;
    @Value("${app.id}")
    private String appId;
    @Value("${spring.profiles.active}")
    private String env;
    @Value("${apollo.clusterName}")
    private String clusterName;
    @Value("${apollo.namespaceName}")
    private String namespaceName;

    @Override
    public List<FlowRuleEntity> getRules(String appName)
    {
        String flowDataId = ApolloConfigUtil.getFlowDataId(appName);

        OpenNamespaceDTO openNamespaceDTO = apolloOpenApiClient.getNamespace(appId, env, clusterName, namespaceName);

        String rules = openNamespaceDTO
                .getItems()
                .stream()
                .filter(p -> p.getKey().equals(flowDataId))
                .map(OpenItemDTO::getValue)
                .findFirst()
                .orElse("");

        if (StringUtil.isEmpty(rules)) {
            return new ArrayList<>();
        }
        return converter.convert(rules);
    }
}

(2) Add a Publisher to persist the flow control rules to the Apollo configuration center:

@Component("flowRuleApolloPublisher")
public class FlowRuleApolloPublisher implements DynamicRulePublisher<List<FlowRuleEntity>> {

    @Autowired
    private ApolloOpenApiClient apolloOpenApiClient;
    @Autowired
    private Converter<List<FlowRuleEntity>, String> converter;
    @Value("${app.id}")
    private String appId;
    @Value("${spring.profiles.active}")
    private String env;
    @Value("${apollo.user}")
    private String user;
    @Value("${apollo.clusterName}")
    private String clusterName;
    @Value("${apollo.namespaceName}")
    private String namespaceName;

    @Override
    public void publish(String app, List<FlowRuleEntity> rules){
        AssertUtil.notEmpty(app, "app name cannot be empty");
        if (rules == null) {
            return;
        }

        filterField(rules);
        // Increase the configuration
        String flowDataId = ApolloConfigUtil.getFlowDataId(app);
        OpenItemDTO openItemDTO = new OpenItemDTO();
        openItemDTO.setKey(flowDataId);
        openItemDTO.setValue(converter.convert(rules));
        openItemDTO.setComment("Program auto-join");
        openItemDTO.setDataChangeCreatedBy(user);
        apolloOpenApiClient.createOrUpdateItem(appId, env, clusterName, namespaceName, openItemDTO);

        // Release configuration
        NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO();
        namespaceReleaseDTO.setEmergencyPublish(true);
        namespaceReleaseDTO.setReleaseComment("Modify or add configurations");
        namespaceReleaseDTO.setReleasedBy(user);
        namespaceReleaseDTO.setReleaseTitle("Modify or add configurations");
        apolloOpenApiClient.publishNamespace(appId, env, clusterName, namespaceName, namespaceReleaseDTO);
    }

    /**
     * 过滤不必要的字段
     */
    private void filterField(List<FlowRuleEntity> rules) {
        // 对不必要的信息进行过滤
        for (FlowRuleEntity rule : rules) {
            rule.setGmtCreate(null);
            rule.setGmtModified(null);
        }
    }
}

(3) Introduce Provider and Publisher in Controller:

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

(4) Modify the query interface of the controller to query the sentinel rules from apollo instead:

/**
 * 查询流控配置,用于展示在sentinel-dashboard上 
 */
@GetMapping("/rules")
@AuthAction(PrivilegeType.READ_RULE)
public Result<List<FlowRuleEntity>> apiQueryMachineRules(@RequestParam String app, @RequestParam String ip, @RequestParam Integer port) {

    if (StringUtil.isEmpty(app))
    {
        return Result.ofFail(-1, "app can't be null or empty");
    }
    if (StringUtil.isEmpty(ip))
    {
        return Result.ofFail(-1, "ip can't be null or empty");
    }
    if (port == null)
    {
        return Result.ofFail(-1, "port can't be null");
    }

    try {
        List<FlowRuleEntity> rules = ruleProvider.getRules(app);
        if (rules != null && !rules.isEmpty())
        {
            for (FlowRuleEntity entity : rules)
            {
                entity.setApp(app);
                if (entity.getClusterConfig() != null && entity.getClusterConfig().getFlowId() != null)
                {
                    entity.setId(entity.getClusterConfig().getFlowId());
                }
            }
        }

        repository.saveAll(rules);
        return Result.ofSuccess(rules);
    }
    catch (Throwable throwable)
    {
        logger.error("Error when querying flow rules", throwable);
        return Result.ofThrowable(-1, throwable);
    }
}

(5) Modify the new or modified interface of the controller, and each new or modified interface is synchronized to Apollo:

/**
 * 发布限流配置
 */
private CompletableFuture<Void> publishRules(String app, String ip, Integer port) {
    List<FlowRuleEntity> rules = repository.findAllByMachine(MachineInfo.of(app, ip, port));
    try {
        rulePublisher.publish(app, rules);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sentinelApiClient.setFlowRuleOfMachineAsync(app, ip, port, rules);
}

2. Configure the Apollo space of sentinel-dashboard:

2.1. Create the apollo application of the sentinel-dashboard project:

 2.2. Create a public namespace for storing sentinel-dashboard rules:

        After entering the application, click "Add Namespace" to create an Apollo storage space that specifically stores Sentinel's various current limiting, fuse and downgrade rules. It should be noted here that the type of space created must be "public" public space , because in the end these The rules need to be obtained by specific microservice applications, and in Apollo, only the public Namecspace can be inherited by other applications.

2.3. Create an open authorization information token based on the application:

(1) Click on Administrator Tools -> Open Platform Authorization Management in the upper right corner of the console

 (2) Third-party application ID=AppId, third-party application name=please fill in freely, project leader=apollo.user in the configuration file, click Create for the first time, if the upper right corner prompts that it already exists, click Query

 (3) Please select app for authorization type:

        The final generated Token information will be configured as an important credential for the connection between sentinel-dashboard and the Apollo interface. So far, through the above steps, the transformation of the sentinel-dashboard project has been completed. Next, we will introduce how other projects can be integrated and connected with the transformed sentinel-dashboard.

3. Spring boot integrates sentinel and persists rules to apollo:

This section takes the gateway-bbk gateway project as an example, if the non-gateway project removes the gateway-related configuration

 3.1. Introduce dependencies:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    <version>2.2.6.RELEASE</version>
</dependency>
<!--apollo-->
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-apollo</artifactId>
    <version>1.5.2</version>
</dependency>

3.2. Configuration file:

        Sentinel-dashboard is to write the rules into sentinel-rules in the public space of the Apollo application, so other microservices can inherit and read the configuration of the public space through Apollo. It's just that we are carrying out the transformation of sentinel-dashboard, and the writing of the rules has been compiled into a certain prefix/suffix identifier, so if SpringCloud microservices want to match the corresponding rules, they also need to agree on the reading method in the configuration of their own services. Take the two rules of current limiting and fusing as an example to configure, as shown in the following flowRulesKey:

# sentinel + apollo进行规则持久化,RulesKey指定该规则在apollo中key的名称,命名格式需与sentinel-dashboard配置的格式保持一致
sentinel.datasource.rules.apollo.namespace-name = EDU001.sentinel-rules
# 从Apollo公共空间中EDU001.sentinel-rules读取限流规则
spring.cloud.sentinel.datasource.flow.apollo.ruleType = flow
spring.cloud.sentinel.datasource.flow.apollo.namespace-name = ${sentinel.datasource.rules.apollo.namespace-name}
spring.cloud.sentinel.datasource.flow.apollo.flowRulesKey = ${spring.application.name}-${spring.cloud.sentinel.datasource.flow.apollo.ruleType}-rules
# 从Apollo公共空间中EDU001.sentinel-rules读取熔断规则
spring.cloud.sentinel.datasource.degrade.apollo.ruleType = degrade
spring.cloud.sentinel.datasource.degrade.apollo.namespace-name = ${sentinel.datasource.rules.apollo.namespace-name}
spring.cloud.sentinel.datasource.degrade.apollo.flowRulesKey = ${spring.application.name}-${spring.cloud.sentinel.datasource.degrade.apollo.rule-ruleType}-rules
# 从Apollo公共空间中EDU001.sentinel-rules读取网关限流规则
spring.cloud.sentinel.datasource.gwFlow.apollo.ruleType = gw-flow
spring.cloud.sentinel.datasource.gwFlow.apollo.namespace-name = ${sentinel.datasource.rules.apollo.namespace-name}
spring.cloud.sentinel.datasource.gwFlow.apollo.flowRulesKey = ${spring.application.name}-${spring.cloud.sentinel.datasource.gwFlow.apollo.ruleType}-rules
# 从Apollo公共空间中EDU001.sentinel-rules读取网关API管理规则
spring.cloud.sentinel.datasource.gwApiGroup.apollo.ruleType = gw-api-group
spring.cloud.sentinel.datasource.gwApiGroup.apollo.namespace-name = ${sentinel.datasource.rules.apollo.namespace-name}
spring.cloud.sentinel.datasource.gwApiGroup.apollo.flowRulesKey = ${spring.application.name}-${spring.cloud.sentinel.datasource.gwApiGroup.apollo.ruleType}-rules
    
# sentinel看板的地址
spring.cloud.sentinel.transport.dashboard = 112.74.98.151:80
# 开启对sentinel看板的饥饿式加载
spring.cloud.sentinel.eager = true

# 此项为该项目在配置中心的项目名
app.id=gateway-bbk
# 加载的配置文件名,需引入 sentinel-dashboard 配置的公共空间
apollo.bootstrap.namespaces=application,EDU001.sentinel-rules
apollo.bootstrap.enabled=true
# 指定apollo的注册地址:
#本地开发环境 Local environment
local.meta=http://47.112.238.105:8004
#开发联调环境 Development environment
dev.meta=http://172.18.227.113:8080
#功能验收测试环境 Feature Acceptance Test environment
fat.meta=http://172.18.227.115:8080
#生产环境 Production environment
pro.meta=http://xxxx.xxx.net

        It can be seen from the above configuration that we match various rules through naming rules through the configuration method of Sentinel Client relying on conventions (here, the naming rules of Sentinel rules can be agreed in accordance with the actual management requirements to ensure that sentinel-dashboard writes Just match the microservice read)! For example, if it is classified from a management perspective, {department name}.sentinel-rules can be added, which requires the department name prefix to be added when creating the namespace public space.

4. Integration test:

4.1. New rules:

        Add a new rule in the sentinel-dashboard console:

4.2. Synchronize to Apollo:

After the sentinel dashiboard console is successfully added, we can enter the apollo configuration center to see that the new rules have been persisted to the configuration center 

Reference article: https://zhuanlan.zhihu.com/p/64892865

Guess you like

Origin blog.csdn.net/a745233700/article/details/122659459