当添加流控规则后,控制台无法监控应用

未关闭
#3,518 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
java, spring-boot

调研方向

从 trace 中提到的 dashboard 入口开始,尤其是 SentinelApiClient 和 MetricFetcher,并使用提供的 Java 11、Spring Boot 2.7 配置及规则初始化来复现该问题。将客户端配置的监控 endpoint 与日志中显示的 dashboard 请求进行比较;当 dashboard 能够获取指标和资源树,同时 Flow 规则保持启用时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Bug 描述

在使用sentinel的组件时,碰到了控制台无法监控应用。

环境

环境:"java11,spring boot2.7"

sentinel的依赖是:

<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2021.0.5.0</version>
        </dependency> 

配置文件为:

spring:
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8858
        port: 8719 # Sentinel客户端暴露的监控端口,默认为8719
        client-ip: 127.0.0.1
      enabled: true

sentinel控制台与项目运行在本地电脑上。

问题详细:

在项目中编写了sentinel的流控规则后,控制台就无法监控应用,但是流控规则是生效的,就是控制台监控不了应用了,但是把流控规则去掉后就能监控应用了

Image


在代码中设置sentinel的流控与熔断规则:

@Component
public class SentinelRulesManager {

    @PostConstruct
    public void initRules() {
        initFlowRules();  // 当我注释这个流控规则后,控制台就能监控应用了
        initDegradeRules();
    }

    // 限流规则
    public void initFlowRules() {
        FlowRule flowRule = new FlowRule();
        flowRule.setResource("listQuestionVOByPage");
        flowRule.setCount(2);
        flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule.setLimitApp("default");
        flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT);
        FlowRuleManager.loadRules(Collections.singletonList(flowRule));

    }

    // 降级规则
    public void initDegradeRules() {
        // 单 IP 查看题目列表熔断规则
        DegradeRule slowCallRule = new DegradeRule("listQuestionVOByPage")
                .setGrade(CircuitBreakerStrategy.SLOW_REQUEST_RATIO.getType())
                .setCount(0.2) // 慢调用比例大于 20%
                .setTimeWindow(10) // 熔断持续时间 60 秒
                .setStatIntervalMs(30 * 1000) // 统计时长 30 秒
                .setMinRequestAmount(5) // 最小请求数
                .setSlowRatioThreshold(3); // 响应时间超过 3 秒

        DegradeRule errorRateRule = new DegradeRule("listQuestionVOByPage")
                .setGrade(CircuitBreakerStrategy.ERROR_RATIO.getType())
                .setCount(0.1) // 异常率大于 10%
                .setTimeWindow(10) // 熔断持续时间 60 秒
                .setStatIntervalMs(30 * 1000) // 统计时长 30 秒
                .setMinRequestAmount(5); // 最小请求数

        // 加载规则
        DegradeRuleManager.loadRules(Arrays.asList(slowCallRule, errorRateRule));
    }
}
错误信息:

然后控制台就报错如下:

2025-04-18 12:43:20.872 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher   : Failed to fetch metric from <http://127.0.0.1:8720/metric?startTime=1744951392000&endTime=1744951398000&refetch=false> (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:27.867 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher   : Failed to fetch metric from <http://127.0.0.1:8720/metric?startTime=1744951399000&endTime=1744951405000&refetch=false> (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:34.873 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher   : Failed to fetch metric from <http://127.0.0.1:8720/metric?startTime=1744951406000&endTime=1744951412000&refetch=false> (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:37.613 ERROR 51776 --- [pool-1-thread-1] c.a.c.s.d.client.SentinelApiClient       : HTTP request failed: http://127.0.0.1:8720/jsonTree?type=root
java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946) ~[na:na]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) ~[httpasyncclient-4.1.3.jar!/:4.1.3]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.3.jar!/:4.1.3]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2025-04-18 12:43:37.613 ERROR 51776 --- [nio-8858-exec-8] c.a.c.s.d.client.SentinelApiClient       : Error when fetching items from api: jsonTree -> root

java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused: no further information
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073) ~[na:na]
at com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient.fetchItems(SentinelApiClient.java:383) ~[classes!/:na]
at com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient.fetchResourceOfMachine(SentinelApiClient.java:450) ~[classes!/:na]
at com.alibaba.csp.sentinel.dashboard.controller.ResourceController.fetchResourceChainListOfMachine(ResourceController.java:70) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
主要语言
Java
星标
23.1k
派生
8.1k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

alibaba/Sentinel 的其他 Issue

查看 alibaba/Sentinel 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。