alibaba / alibaba/Sentinel

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

Open
#1,368 4 comments 0 reactions 0 assignees View on GitHub
kind/discussion
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## 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)

1.
2.
3.

### 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 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?

Contributor guide

Open the contributing guide

Research direction

Start by tracing how SentinelConfig.setConfig and System.setProperty update TransportConfig. Compare initialization with and without csp.sentinel.app.type=1, then follow the gateway and API menu registration path in the Dashboard. Reproduce with the provided Spring Cloud Gateway dependencies and verify that both menu items remain visible when the heartbeat client IP is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.