feat(dashboard): 调整日志路径并优化Nacos配置

- 修改日志文件存储路径为相对路径 ./logs/csp/sentinel-dashboard.log
- 默认启用认证登录功能,注释掉 auth.enabled=false 配置
- 更新 Nacos 配置,将默认地址指向本地并新增 groupId 配置项
- 动态读取 groupId 并注入到 NacosConfigUtil 中
- FlowControllerV2 使用新的 FlowRuleApiProvider 和 FlowRuleApiPublisher 替代原有实现
- 注释旧的动态规则提供器和发布器引用
This commit is contained in:
mshe 2025-11-21 08:07:52 +08:00
parent b14de1ea5f
commit ff999c6703
4 changed files with 37 additions and 9 deletions

View File

@ -21,6 +21,8 @@ import java.util.List;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService; import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.rule.apiProvider.FlowRuleApiProvider;
import com.alibaba.csp.sentinel.dashboard.rule.apiPublisher.FlowRuleApiPublisher;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
@ -58,12 +60,19 @@ public class FlowControllerV2 {
@Autowired @Autowired
private InMemoryRuleRepositoryAdapter<FlowRuleEntity> repository; private InMemoryRuleRepositoryAdapter<FlowRuleEntity> repository;
// @Autowired
// @Qualifier("flowRuleDefaultProvider")
// private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
//
// @Autowired
// @Qualifier("flowRuleDefaultPublisher")
// private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
@Autowired @Autowired
@Qualifier("flowRuleDefaultProvider") private FlowRuleApiProvider ruleProvider;
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired @Autowired
@Qualifier("flowRuleDefaultPublisher") private FlowRuleApiPublisher rulePublisher;
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
@GetMapping("/rules") @GetMapping("/rules")
@AuthAction(PrivilegeType.READ_RULE) @AuthAction(PrivilegeType.READ_RULE)

View File

@ -15,6 +15,8 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.rule.nacos; package com.alibaba.csp.sentinel.dashboard.rule.nacos;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* @author Ms.He * @author Ms.He
* 2025-11-21 07:37 * 2025-11-21 07:37
@ -23,8 +25,7 @@ package com.alibaba.csp.sentinel.dashboard.rule.nacos;
* pc-name mshe * pc-name mshe
*/ */
public final class NacosConfigUtil { public final class NacosConfigUtil {
public static String GROUP_ID = "DEFAULT_GROUP";
public static final String GROUP_ID = "DEFAULT_GROUP";
public static final String GLOBAL_DATA_ID_POSTFIX = ".json"; public static final String GLOBAL_DATA_ID_POSTFIX = ".json";
// 流控规则 // 流控规则

View File

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration @Configuration
@ConfigurationProperties(prefix = "nacos.config") @ConfigurationProperties(prefix = "nacos.config")
public class NacosServerConfig { public class NacosServerConfig {
@ -11,6 +13,12 @@ public class NacosServerConfig {
private String namespace; private String namespace;
private String username; private String username;
private String password; private String password;
private String groupId;
@PostConstruct
public void doInit() {
NacosConfigUtil.GROUP_ID = groupId;
}
public String getServerAddr() { public String getServerAddr() {
return serverAddr; return serverAddr;
@ -44,6 +52,14 @@ public class NacosServerConfig {
this.password = password; this.password = password;
} }
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@Override @Override
public String toString() { public String toString() {
return JSONObject.toJSONString(this); return JSONObject.toJSONString(this);

View File

@ -6,13 +6,14 @@ server.servlet.encoding.enabled=true
server.servlet.session.cookie.name=sentinel_dashboard_cookie server.servlet.session.cookie.name=sentinel_dashboard_cookie
#logging settings #logging settings
logging.level.org.springframework.web=INFO logging.level.org.springframework.web=INFO
logging.file.name=${user.home}/logs/csp/sentinel-dashboard.log logging.file.name=./logs/csp/sentinel-dashboard.log
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 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 #logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
#auth settings #auth settings
auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version 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 auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png
# If auth.enabled=false, Sentinel console disable login # If auth.enabled=false, Sentinel console disable login
#auth.enabled=false
auth.username=admin auth.username=admin
auth.password=admin auth.password=admin
# Inject the dashboard version. It's required to enable # Inject the dashboard version. It's required to enable
@ -20,9 +21,10 @@ auth.password=admin
sentinel.dashboard.version=@project.version@ sentinel.dashboard.version=@project.version@
############################################################## ##############################################################
# nacos config # nacos config
#nacos.config.server-addr=http://127.0.0.1:8848 nacos.config.server-addr=http://127.0.0.1:8848
nacos.config.server-addr=http://172.16.8.70:8848 #nacos.config.server-addr=http://172.16.8.70:8848
nacos.config.namespace=namespace-sentinel nacos.config.namespace=namespace-sentinel
nacos.config.groupId=DEFAULT_GROUP
nacos.config.username= nacos.config.username=
nacos.config.password= nacos.config.password=
############################################################## ##############################################################