Sentinel icon indicating copy to clipboard operation
Sentinel copied to clipboard

sentinel 1.8.6 持久化数据到nacos配置中心,修改规则刷新页面数据有延迟

Open xinxinQ opened this issue 1 year ago • 2 comments

Issue Description

sentinel 1.8.6 数据持久化nacos,dashboard页面刷新还是修改之前的数据,再次刷新后正常 Type: bug report

Describe what happened

数据保存nacos后数据不实时刷新

Describe what you expected to happen

dashboard修改规则,刷新页面后实时更新修改后的内容

How to reproduce it (as minimally and precisely as possible)

  1. 实现DynamicRulePublisher<List<FlowRuleEntity>>后重写: public void publish(String app, T rules) throws Exception { AssertUtil.notEmpty(app, "app name cannot be empty"); if (rules == null) { return; }

     String dataId = app + this.getDataIdPostfix();
     String groupId = nacosProperties.getGroupId();
    
     log.info("publish; dataId: {},groupId: {},rules: {}",dataId,groupId,rules);
    
     nacosConfigService.publishConfig(dataId,groupId, converter.convert(rules), ConfigType.JSON.getType());
    

    }

  2. FlowController 代码: public Result<List<FlowRuleEntity>> apiQueryMachineRules(@RequestParam String app) {

     if (StringUtil.isEmpty(app)) {
         return Result.ofFail(-1, "app can't be null or empty");
     }
     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());
                 }
             }
         }
         rules = repository.saveAll(rules);
         return Result.ofSuccess(rules);
     } catch (Throwable throwable) {
         logger.error("Error when querying flow rules", throwable);
         return Result.ofThrowable(-1, throwable);
     }
    

    } public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id, @RequestBody FlowRuleEntity entity) { if (id == null || id <= 0) { return Result.ofFail(-1, "Invalid id"); } FlowRuleEntity oldEntity = repository.findById(id); if (oldEntity == null) { return Result.ofFail(-1, "id " + id + " does not exist"); } if (entity == null) { return Result.ofFail(-1, "invalid body"); }

     entity.setApp(oldEntity.getApp());
     entity.setIp(oldEntity.getIp());
     entity.setPort(oldEntity.getPort());
     Result<FlowRuleEntity> checkResult = checkEntityInternal(entity);
     if (checkResult != null) {
         return checkResult;
     }
    
     entity.setId(id);
     Date date = new Date();
     entity.setGmtCreate(oldEntity.getGmtCreate());
     entity.setGmtModified(date);
     try {
         entity = repository.save(entity);
         if (entity == null) {
             return Result.ofFail(-1, "save entity fail");
         }
         publishRules(oldEntity.getApp());
     } catch (Throwable throwable) {
         logger.error("Failed to update flow rule", throwable);
         return Result.ofThrowable(-1, throwable);
     }
     return Result.ofSuccess(entity);
    

    }

  3. 页面操作修改刷新页面数据还是修改前的,强刷页面后正常显示

xinxinQ avatar Apr 16 '24 01:04 xinxinQ

数据保存完之后,又刷新获取,nacos数据有延迟的,可以修改成优先从内存获取。

sirius19 avatar Apr 25 '24 13:04 sirius19

感觉使用内存的数据来展示 dashboard 不大合适,因为这样的话就不知道是否成功变更到 sentinel 应用. @LearningGp

Daydreamer-ia avatar Jul 13 '24 15:07 Daydreamer-ia