关于1.7.1SentinelConfig.setConfig,Dashboard API管理和网关流控规则菜单项不显示

s1ag04yj  于 2021-11-29  发布在  Java
关注(0)|答案(4)|浏览(525)

Issue Description

使用 Sentinel 1.7.1的时候,@PostConstruct initFunc里面添加代码SentinelConfig.setConfig(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress());
会导致 Sentinel Dashboard 左侧菜单项,API管理和网关流控规则菜单项不显示。

如果,启动网关应用 加上参数 csp.sentinel.app.type=1 就显示正常。此外,在不加参数的情况下,调整代码为 System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress()); 也会显示正常。

Describe what happened (or what feature you want)

Describe what you expected to happen

看是否优化下相关代码,可以使用 SentinelConfig.setConfig 设置。

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

Tell us your environment

相关Jar依赖:
spring-cloud-alibaba-dependencies 2.2.0.RELEASE
spring-cloud-dependencies Hoxton.SR3

spring-cloud-starter-gateway、spring-cloud-alibaba-sentinel-gateway、spring-cloud-starter-alibaba-sentinel、sentinel-datasource-nacos

具体代码为:
`
@slf4j
@component
public class CustomBlockRequestHandler implements BlockRequestHandler {
@Autowired
private InetUtils inetUtils;

//http://ip:port/getRules?type=flow
//http://ip:port/gateway/getRules

@PostConstruct
public void doInit() {
    //SentinelConfig.setConfig(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress());//导致菜单不显示的代码
    System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress());//替换代码,显示菜单
}

@Override
public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable ex) {
    String resultString = "{\"code\":403,\"message\":\"服务开启限流保护,请稍后再试!\"}";
    return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS).contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(resultString));
}

}

`

Anything else we need to know?

t1rydlwq

t1rydlwq1#

我用gateway接入sentinel 也出现了这个问题,只有在启动参数上加csp.sentinel.app.type=1 才行

2vuwiymt

2vuwiymt2#

zuul1集成的时候,在工程的src\main\resources 下加了文件sentinel.properties配置了csp.sentinel.app.type=1
并且sentinel-record.log打印了[SentinelConfig] Application type resolved: 1
但是控制台api管理菜单、网关流控制规则菜单项不显示

wtlkbnrh

wtlkbnrh3#

没有在启动参数上加csp.sentinel.app.type=1 情况下SentinelSCGAutoConfiguration 加载在SentinelAutoConfiguration之后 如果spring.cloud.sentinel.eager=true 会导致发送初始化心跳APP_TYPE取值不正确

bqujaahr

bqujaahr4#

1290 (comment)

从这儿看到了答案,估计心跳时有问题,你可以尝试重启下dashboard

相关问题