apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.37k stars 2.9k forks source link

[BUG] Sentinel Plugin use default fallbackUri instead of configured empty one #5560

Open cxshun opened 2 months ago

cxshun commented 2 months ago

Is there an existing issue for this?

Current Behavior

When enable Sentinel plugin in dashboard, with rule fallback uri setting to null, I found that bootstrap using default fallback/sentinel instead of my configured value null. image image

After search the source, I found that SentinelHandle has default value, as show below.

private String fallbackUri = "/fallback/sentinel";

When I update sentinel rule config with fallbackuri is empty, I found dashboard update request is without the fallbackuri, as showed below.

PUT /rule/1784868213710041088 HTTP/1.1
{
    "selectorId": "1784868086001872896",
    "name": "默认限流",
    "matchMode": "0",
    "handle": "{\"degradeRuleCount\":\"0\",\"degradeRuleEnable\":\"1\",\"degradeRuleGrade\":\"0\",\"degradeRuleMinRequestAmount\":5,\"degradeRuleStatIntervals\":1,\"degradeRuleSlowRatioThreshold\":0.5,\"degradeRuleTimeWindow\":0,\"flowRuleControlBehavior\":\"0\",\"flowRuleCount\":\"10\",\"flowRuleMaxQueueingTimeMs\":\"500\",\"flowRuleWarmUpPeriodSec\":10,\"flowRuleEnable\":1,\"flowRuleGrade\":\"0\"}",
    "loged": true,
    "enabled": true,
    "matchRestful": false,
    "sort": 1,
    "ruleConditions": [
        {
            "id": "1784868214053974016",
            "ruleId": "1784868213710041088",
            "paramType": "uri",
            "paramTypeName": "uri",
            "operator": "pathPattern",
            "operatorName": "pathPattern",
            "paramName": "/",
            "paramValue": "/**",
            "dateCreated": "2024-04-29 20:51:29",
            "dateUpdated": "2024-04-29 20:51:29"
        }
    ],
    "id": "1784868213710041088"
}

Then with the websocket data from admin to bootstrap, it shows the fallbackUri is missing.

2024-04-29 18:22:30 [WebSocketConnectReadThread-29] INFO  org.apache.shenyu.plugin.sync.data.websocket.client.ShenyuWebsocketClient - handleResult({"groupType":"RULE","eventType":"UPDATE","data":[{"id":"1784868213710041088","name":"默认限流","pluginName":"sentinel","selectorId":"1784868086001872896","matchMode":0,"sort":1,"enabled":true,"loged":true,"handle":"{\"degradeRuleCount\":\"0\",\"degradeRuleEnable\":\"1\",\"degradeRuleGrade\":\"0\",\"degradeRuleMinRequestAmount\":5,\"degradeRuleStatIntervals\":1,\"degradeRuleSlowRatioThreshold\":0.5,\"degradeRuleTimeWindow\":0,\"flowRuleControlBehavior\":\"0\",\"flowRuleCount\":\"10\",\"flowRuleMaxQueueingTimeMs\":\"500\",\"flowRuleWarmUpPeriodSec\":10,\"flowRuleEnable\":1,\"flowRuleGrade\":\"0\"}","conditionDataList":[{"paramType":"uri","operator":"pathPattern","paramName":"/","paramValue":"/**"}],"beforeConditionDataList":[],"matchRestful":false}]})

When I tried to trigger the sentinel plugin, it has the following log:

2024-04-29 17:00:31 [shenyu-netty-epoll-9] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match , rule name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-2] ERROR org.apache.shenyu.plugin.api.utils.WebFluxResultUtils - can not match selector data: divide , path is /fallback/sentinel
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - sentinel rule success match , rule name :默认限流
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector match success from default strategy
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success match , selector name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match , rule name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-3] ERROR org.apache.shenyu.plugin.api.utils.WebFluxResultUtils - can not match selector data: divide , path is /fallback/sentinel

Expected Behavior

When configure Sentinel Plugin's fallback uri to null, it should be null.

Steps To Reproduce

  1. Add sentinel plugin selector match request uri.
  2. Add sentinel plugin selector rule to configure strategy, configure fallback uri to null or leave it empty.
  3. Start to benchmark ot trigger sentinel plugin.

Environment

ShenYu version(s):2.6.1

Debug logs

2024-04-29 17:00:31 [shenyu-netty-epoll-9] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match , rule name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-2] ERROR org.apache.shenyu.plugin.api.utils.WebFluxResultUtils - can not match selector data: divide , path is /fallback/sentinel
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - sentinel rule success match , rule name :默认限流
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector match success from default strategy
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success match , selector name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-5] INFO  org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match , rule name :xp-device-boot
2024-04-29 17:00:31 [shenyu-netty-epoll-3] ERROR org.apache.shenyu.plugin.api.utils.WebFluxResultUtils - can not match selector data: divide , path is /fallback/sentinel

Anything else?

No response

moremind commented 2 months ago

this has fixed in master