背景:
修改了Sentinel源码,去Nacos获取数据加载到Sentinel,一直显示不出来。但是实际规则确实生效的。
修改了com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1#apiQueryMachineRules这段代码:
@GetMapping("/rules")
public Result<List<FlowRuleEntity>> apiQueryMachineRules(HttpServletRequest request,
@RequestParam String app,
@RequestParam String ip,
@RequestParam Integer port) {
AuthUser authUser = authService.getAuthUser(request);
authUser.authTarget(app, PrivilegeType.READ_RULE);
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 = sentinelApiClient.fetchFlowRuleOfMachine(app, ip, port);
//从磁盘获取文件数据
List<FlowRuleEntity> rules = ruleProvider.getRules(app);
rules = repository.saveAll(rules);
return Result.ofSuccess(rules);
} catch (Throwable throwable) {
logger.error("Error when querying flow rules", throwable);
return Result.ofThrowable(-1, throwable);
}
}
问题定位
直接访问:
http://localhost:8080/v1/flow/rules?app=consumer-center&ip=127.0.0.1&port=8720 , 方便定位问题。
debug到:
com.alibaba.nacos.client.config.NacosConfigService#getConfigInner 抛出异常:
报错信息里有:“47.111.191.111”, 全局搜索。发现:
修改重启,解决。