This is the 23rd day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Nacos plays a central role in the configuration of the project, but there is a situation where some operators dynamically modify the flow control rules and realize the synchronization of the flow control rules on the Nacos console, while others modify the flow control rules through Sentinel Dashboard. This situation leads to inconsistent data between flow control rules on Nacos and Sentinel Dashboard traffic control rules.

As the storage center of the configured persistent database, it is not recommended to modify flow control rules on Nacos, because Nacos is not responsible for the configuration of flow control rules, but Sentinel DashBoard’s console specifically responsible for the management of flow control rules, which makes the configuration of flow control rules clearer and more visible. So the management of flow control rules is centralized on Sentinel Dashboard. However, Sentinel Dashboard dynamically modified flow control rules need to be synchronized to Nacos.

Sentinel Dashboard integrates Nacos to achieve bidirectional synchronization of flow control rules

All operations under [Flow control rules] of Sentinel Dashboard call FlowControllerV1 class in Sentinel Dashboard source code, which has localized add, delete, change and check operations of flow control rules.

In com. Alibaba. CSP. Sentinel. Dashboard. Controller. The v2 packages have a FlowControllerV2 class, this class provides flow control rules to add and delete operations, and the V1 version difference is that it can realize the rules of data source pull and release.

@RestController
@RequestMapping(value="/v2/flow")
public class FlowControllerV2{
    	@Autowired
    	private InMemoryRuleRepositoryAdapter<FlowRuleEntity> repository;
    	@Auowired
    	@Qualifier("flowRuleDefaultProvider")
    	private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
    	@Auowired
    	@Qualifier("flowRuleDefaultPublisher")
    	private DynamicRulePulisher<List<FlowRuleEntity>> rulePublisher;
}
Copy the code

FlowControllerV2 relies on two important classes

  1. DynamicRulePulisher: Publishes dynamic rules that are modified in the Sentinel Dashboard to be synchronized to a specified data source.
  2. DynamicRuleProvider: pulls dynamic rules. It obtains flow control rules from specified data sources and displays them in the Sentinel Dashboard.

DynamicRuleProvider and DynamicRulePulisher need to be extended and Nacos integrated to achieve bidirectional synchronization of Sentinel Dashboard flow control rules.

Sentinel Dashboard synchronizes flow control rules to Nacos

To modify the Sentinel Dashboard code, the specific process is as follows:

  1. Pull Sentinel 1.7.2 from Github
  2. Open the Sentinel source code using IDEA
  3. Remove the sentinel-datasource-nacos dependency in the sentinel-Dashboard module pom. XML file.
<dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-nacos</artifactId>
            <! --<scope>test</scope>-->
        </dependency>
Copy the code