This is an automated email from the ASF dual-hosted git repository. liuhongyu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push: new 84daff6bec [type:issue] Support for gray release in divide-plugin. (#5763) 84daff6bec is described below commit 84daff6bec78e478f69d00ff4701c6da1ff6b665 Author: yunlongn <yunlo...@outlook.com> AuthorDate: Wed Nov 20 20:28:35 2024 +0800 [type:issue] Support for gray release in divide-plugin. (#5763) * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] fix issue 5751. * [type:issue] Support for gray release in divide-plugin. --------- Co-authored-by: aias00 <liuhon...@apache.org> Co-authored-by: moremind <hefen...@apache.org> --- .../src/main/resources/static/index.0e8007d1.js | 1 - .../src/main/resources/static/index.2f2f389d.css | 10 ------ .../src/main/resources/static/index.98a87b65.js | 1 - .../ShenyuClientRegisterDivideServiceImplTest.java | 8 ++--- .../ShenyuClientRegisterDubboServiceImplTest.java | 8 ++--- .../ShenyuClientRegisterGrpcServiceImplTest.java | 8 ++--- ...yuClientRegisterSpringCloudServiceImplTest.java | 4 +-- .../ShenyuClientRegisterTarsServiceImplTest.java | 8 ++--- .../dto/convert/selector/CommonUpstream.java | 28 ++++++++++++++- .../common/dto/convert/selector/DubboUpstream.java | 29 ++------------- shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml | 1 + .../shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml | 1 + .../shenyu/loadbalancer/entity/Upstream.java | 42 ++++++++++++++++++++++ .../shenyu/loadbalancer/entity/UpstreamTest.java | 1 + .../divide/handler/DivideUpstreamDataHandler.java | 9 ++++- .../handler/GrpcDiscoveryUpstreamDataHandler.java | 8 ++++- .../handler/WebSocketUpstreamDataHandler.java | 8 ++++- 17 files changed, 115 insertions(+), 60 deletions(-) diff --git a/shenyu-admin/src/main/resources/static/index.0e8007d1.js b/shenyu-admin/src/main/resources/static/index.0e8007d1.js deleted file mode 100644 index d82645b750..0000000000 --- a/shenyu-admin/src/main/resources/static/index.0e8007d1.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s="lVK7")}({"+0it":function(e,t,n){"us [...] \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/static/index.2f2f389d.css b/shenyu-admin/src/main/resources/static/index.2f2f389d.css deleted file mode 100644 index 8dd2a4fa4c..0000000000 --- a/shenyu-admin/src/main/resources/static/index.2f2f389d.css +++ /dev/null @@ -1,10 +0,0 @@ -#root,body,html{height:100%}.plug-content-wrap{padding:24px}.open{color:#14c974}.close{color:#ff586d}.optionParts{display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;gap:16px}.ant-layout{min-height:100%}ol,ul{list-style:none}.ant-table{background:#fff}.table-selected{background:#98cdff}.edit{cursor:pointer}.edit,.edit:hover{color:#1890ff}.searchblock{display:-ms-flexbox!important;display:flex!important}.searchblock button{margin-left:30px}.ant-table table{padding [...] - /*! autoprefixer: ignore next */-webkit-box-orient:vertical;overflow:hidden}.main___i2kiy{width:100%;height:100%;padding:24px}.header___1eXCR,.main___i2kiy{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}.header___1eXCR .titleBar___1m0IH{width:100%;display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:end;align-items:end;-ms-flex:1 1;flex:1 1}.header___1eXCR .titleBar___1m0IH .left___HAYeJ{display:-ms-flexbo [...] - * - * antd v3.26.20 - * - * Copyright 2015-present, Alipay, Inc. - * All rights reserved. - * - */body,html{width:100%;height:100%}input::-ms-clear,input::-ms-reveal{display:none}*,:after,:before{-webkit-box-sizing:border-box;box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:rgba(0,0,0,0)}@-ms-viewport{width:device-width}article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}body{margin:0;color:rgba(0,0,0,.65);font-si [...] - /*! autoprefixer: ignore next */-webkit-box-orient:vertical;overflow:hidden}.ant-upload{-webkit-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0;color:rgba(0,0,0,.65);font-size:14px;font-variant:tabular-nums;line-height:1.5;list-style:none;-webkit-font-feature-settings:"tnum";font-feature-settings:"tnum";outline:0}.ant-upload p{margin:0}.ant-upload-btn{display:block;width:100%;outline:none}.ant-upload input[type=file]{cursor:pointer}.ant-upload.ant-upload-select{display:i [...] \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/static/index.98a87b65.js b/shenyu-admin/src/main/resources/static/index.98a87b65.js deleted file mode 100644 index 5d53bd6ee7..0000000000 --- a/shenyu-admin/src/main/resources/static/index.98a87b65.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s="lVK7")}({"+0it":function(e,t,n){"us [...] \ No newline at end of file diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java index 1b30a356b8..7b20a5e531 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDivideServiceImplTest.java @@ -98,10 +98,10 @@ public final class ShenyuClientRegisterDivideServiceImplTest { public void testBuildHandle() { shenyuClientRegisterDivideService = spy(shenyuClientRegisterDivideService); - final String returnStr = "[{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',warmup:10,weight:50,status:true,timestamp:1637826588267}," - + "{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8091',warmup:10,weight:50,status:true,timestamp:1637826588267}]"; - final String expected = "[{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," - + "{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]"; + final String returnStr = "[{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',warmup:10,weight:50,status:true,timestamp:1637826588267,\"gray\":false}," + + "{protocol:'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8091',warmup:10,weight:50,status:true,timestamp:1637826588267,\"gray\":false}]"; + final String expected = "[{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}," + + "{\"weight\":50,\"warmup\":10,\"protocol\":\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}]"; List<URIRegisterDTO> list = new ArrayList<>(); list.add(URIRegisterDTO.builder().protocol("http://").appName("test1").rpcType(RpcTypeEnum.HTTP.getName()).host(LOCALHOST).port(8090).build()); SelectorDO selectorDO = mock(SelectorDO.class); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java index 783e3cdbe8..f0d58adaf5 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterDubboServiceImplTest.java @@ -93,11 +93,11 @@ public final class ShenyuClientRegisterDubboServiceImplTest { public void testBuildHandle() { shenyuClientRegisterDubboService = spy(shenyuClientRegisterDubboService); - final String returnStr = "[{protocol:'dubbo://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',warmup:10,weight:50,status:true,timestamp:1637826588267}," - + "{protocol:'dubbo://',upstreamHost:'localhost',upstreamUrl:'localhost:8091',warmup:10,weight:50,status:true,timestamp:1637826588267}]"; + final String returnStr = "[{protocol:'dubbo://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',warmup:10,weight:50,status:true,timestamp:1637826588267,\"gray\":false}," + + "{protocol:'dubbo://',upstreamHost:'localhost',upstreamUrl:'localhost:8091',warmup:10,weight:50,status:true,timestamp:1637826588267,\"gray\":false}]"; final String expected = "[{\"port\":0,\"weight\":50,\"warmup\":10,\"protocol\":\"dubbo://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\"," - + "\"status\":true,\"timestamp\":1637826588267},{\"port\":0,\"weight\":50,\"warmup\":10,\"protocol\":\"dubbo://\",\"upstreamHost\":\"localhost\"," - + "\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]"; + + "\"status\":true,\"timestamp\":1637826588267,\"gray\":false},{\"port\":0,\"weight\":50,\"warmup\":10,\"protocol\":\"dubbo://\",\"upstreamHost\":\"localhost\"," + + "\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}]"; List<URIRegisterDTO> list = new ArrayList<>(); list.add(URIRegisterDTO.builder().appName("test1") diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java index eb5ac6e0b4..da752f00dd 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterGrpcServiceImplTest.java @@ -95,10 +95,10 @@ public final class ShenyuClientRegisterGrpcServiceImplTest { public void testBuildHandle() { shenyuClientRegisterGrpcService = spy(shenyuClientRegisterGrpcService); - final String returnStr = "[{upstreamUrl='localhost:8090',weight=1,status=true,timestamp=1637826588267}," - + "{upstreamUrl='localhost:8091',weight=2,status=true,timestamp=1637826588267}]"; - final String expected = "[{\"weight\":1,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," - + "{\"weight\":2,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]"; + final String returnStr = "[{upstreamUrl='localhost:8090',weight=1,status=true,timestamp=1637826588267,\"gray\":false}," + + "{upstreamUrl='localhost:8091',weight=2,status=true,timestamp=1637826588267,\"gray\":false}]"; + final String expected = "[{\"weight\":1,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}," + + "{\"weight\":2,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}]"; List<URIRegisterDTO> list = new ArrayList<>(); list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.GRPC.getName()).host("localhost").port(8090).build()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java index 5d55a19908..c141f5e8a6 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImplTest.java @@ -106,9 +106,9 @@ public final class ShenyuClientRegisterSpringCloudServiceImplTest { shenyuClientRegisterSpringCloudService = spy(shenyuClientRegisterSpringCloudService); final String returnStr = "{serviceId:'test1',gray:false,divideUpstreams:[{weight:50,warmup:10,protocol:" - + "'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',status:'true',timestamp:1637909490935}]}"; + + "'http://',upstreamHost:'localhost',upstreamUrl:'localhost:8090',status:'true',timestamp:1637909490935,\"gray\":false}]}"; final String expected = "{\"serviceId\":\"test1\",\"gray\":false,\"divideUpstreams\":[{\"weight\":50,\"warmup\":10,\"protocol\":" - + "\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637909490935}]}"; + + "\"http://\",\"upstreamHost\":\"localhost\",\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637909490935,\"gray\":false}]}"; final URIRegisterDTO dto1 = URIRegisterDTO.builder().appName("test2") .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .host(HOST).port(8090).build(); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java index 8047e54b8e..85cb25bc85 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterTarsServiceImplTest.java @@ -98,10 +98,10 @@ public final class ShenyuClientRegisterTarsServiceImplTest { public void testBuildHandle() { shenyuClientRegisterTarsService = spy(shenyuClientRegisterTarsService); - final String returnStr = "[{upstreamUrl:'localhost:8090',weight:1,warmup:10,status:true,timestamp:1637826588267}," - + "{upstreamUrl:'localhost:8091',weight:2,warmup:10,status:true,timestamp:1637826588267}]"; - final String expected = "[{\"weight\":1,\"warmup\":10,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267}," - + "{\"weight\":2,\"warmup\":10,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267}]"; + final String returnStr = "[{upstreamUrl:'localhost:8090',weight:1,warmup:10,status:true,timestamp:1637826588267,\"gray\":false}," + + "{upstreamUrl:'localhost:8091',weight:2,warmup:10,status:true,timestamp:1637826588267,\"gray\":false}]"; + final String expected = "[{\"weight\":1,\"warmup\":10,\"upstreamUrl\":\"localhost:8090\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}," + + "{\"weight\":2,\"warmup\":10,\"upstreamUrl\":\"localhost:8091\",\"status\":true,\"timestamp\":1637826588267,\"gray\":false}]"; List<URIRegisterDTO> list = new ArrayList<>(); list.add(URIRegisterDTO.builder().appName("test1").rpcType(RpcTypeEnum.TARS.getName()).host("localhost").port(8090).build()); SelectorDO selectorDO = mock(SelectorDO.class); diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/CommonUpstream.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/CommonUpstream.java index 10e3a18de8..94ed062e96 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/CommonUpstream.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/CommonUpstream.java @@ -54,6 +54,11 @@ public class CommonUpstream { */ private String namespaceId; + /** + * this is gray. + */ + private boolean gray; + /** * Instantiates a new Common upstream. */ @@ -186,6 +191,24 @@ public class CommonUpstream { return namespaceId; } + /** + * gray. + * + * @return Gray + */ + public boolean isGray() { + return gray; + } + + /** + * set gray. + * + * @param gray gray + */ + public void setGray(final boolean gray) { + this.gray = gray; + } + /** * set namespaceId. * @@ -206,13 +229,14 @@ public class CommonUpstream { CommonUpstream that = (CommonUpstream) o; return Objects.equals(upstreamHost, that.upstreamHost) && Objects.equals(protocol, that.protocol) + && Objects.equals(gray, that.gray) && Objects.equals(upstreamUrl, that.upstreamUrl) && Objects.equals(namespaceId, that.namespaceId); } @Override public int hashCode() { - return Objects.hash(upstreamHost, protocol, upstreamUrl, namespaceId); + return Objects.hash(upstreamHost, protocol, upstreamUrl, namespaceId, gray); } @Override @@ -233,6 +257,8 @@ public class CommonUpstream { + timestamp + ", namespaceId=" + namespaceId + + ", gray=" + + gray + '}'; } } diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/DubboUpstream.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/DubboUpstream.java index 8761a71d80..85c43492d8 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/DubboUpstream.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/selector/DubboUpstream.java @@ -39,11 +39,6 @@ public final class DubboUpstream extends CommonUpstream { */ private int port; - /** - * gray status. - */ - private Boolean gray; - /** * group. */ @@ -146,24 +141,6 @@ public final class DubboUpstream extends CommonUpstream { this.port = port; } - /** - * Gets the value of gray. - * - * @return the value of gray - */ - public Boolean isGray() { - return gray; - } - - /** - * Sets the gray. - * - * @param gray gray - */ - public void setGray(final Boolean gray) { - this.gray = gray; - } - /** * Gets the value of weight. * @@ -250,14 +227,14 @@ public final class DubboUpstream extends CommonUpstream { && Objects.equals(appName, that.appName) && Objects.equals(this.getProtocol(), that.getProtocol()) && Objects.equals(this.getUpstreamUrl(), that.getUpstreamUrl()) - && Objects.equals(gray, that.gray) + && Objects.equals(this.isGray(), that.isGray()) && Objects.equals(group, that.group) && Objects.equals(version, that.version); } @Override public int hashCode() { - return Objects.hash(registry, appName, port, gray, group, version); + return Objects.hash(registry, appName, port, this.isGray(), group, version); } @Override @@ -268,7 +245,7 @@ public final class DubboUpstream extends CommonUpstream { + "', protocol='" + this.getProtocol() + "', port=" + port + ", upstreamUrl='" + this.getUpstreamUrl() - + "', gray=" + gray + + "', gray=" + this.isGray() + ", weight=" + weight + ", warmup=" + warmup + ", status=" + isStatus() diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml index c36f4f5f11..8b2e6e786e 100644 --- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml @@ -540,6 +540,7 @@ data: url: http://shenyu-admin.default.svc.cluster.local:9095 username: admin password: 123456 + enabled: true application-bootstrap-sync-zookeeper.yml: | shenyu: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml index b66b22a2b8..387f40f5f2 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml @@ -508,6 +508,7 @@ data: url: http://shenyu-admin:9095 username: admin password: 123456 + enabled: true application-bootstrap-sync-zookeeper.yml: | shenyu: diff --git a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java index 8e34e13f0c..a7f96f0d68 100644 --- a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java +++ b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/entity/Upstream.java @@ -98,6 +98,11 @@ public final class Upstream { */ private long lastPicked; + /** + * this is gray. + */ + private boolean gray; + /** * Total number of requests being processed. */ @@ -116,6 +121,7 @@ public final class Upstream { this.warmup = builder.warmup; this.group = builder.group; this.version = builder.version; + this.gray = builder.gray; } /** @@ -348,6 +354,24 @@ public final class Upstream { this.inflight = inflight; } + /** + * gray. + * + * @return Gray + */ + public boolean isGray() { + return gray; + } + + /** + * set gray. + * + * @param gray gray + */ + public void setGray(final boolean gray) { + this.gray = gray; + } + /** * Gets succeeded. * @return the succeeded @@ -484,6 +508,11 @@ public final class Upstream { */ private String version; + /** + * gray. + */ + private Boolean gray = false; + /** * no args constructor. */ @@ -586,5 +615,18 @@ public final class Upstream { this.version = version; return this; } + + + /** + * build gray. + * + * @param gray gray + * @return this builder + */ + public Builder gray(final Boolean gray) { + this.gray = gray; + return this; + } + } } diff --git a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/entity/UpstreamTest.java b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/entity/UpstreamTest.java index f9fa0ef394..0ce8dc53a7 100644 --- a/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/entity/UpstreamTest.java +++ b/shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/entity/UpstreamTest.java @@ -33,6 +33,7 @@ public class UpstreamTest { .timestamp(1) .warmup(1) .version("version") + .gray(false) .weight(1) .status(true) .build(); diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DivideUpstreamDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DivideUpstreamDataHandler.java index 1d265e9f36..1c3634b983 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DivideUpstreamDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DivideUpstreamDataHandler.java @@ -46,7 +46,13 @@ public class DivideUpstreamDataHandler implements DiscoveryUpstreamDataHandler { return; } List<DiscoveryUpstreamData> upstreamList = discoverySyncData.getUpstreamDataList(); - UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), convertUpstreamList(upstreamList)); + final List<Upstream> upstreams = convertUpstreamList(upstreamList); + final List<Upstream> grayUpstreamList = upstreams.stream().filter(Upstream::isGray).toList(); + if (!grayUpstreamList.isEmpty()) { + UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), grayUpstreamList); + } else { + UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), upstreams); + } // the update is also need to clean, but there is no way to // distinguish between crate and update, so it is always clean MetaDataCache.getInstance().clean(); @@ -68,6 +74,7 @@ public class DivideUpstreamDataHandler implements DiscoveryUpstreamDataHandler { .url(u.getUrl()) .weight(u.getWeight()) .warmup(Integer.parseInt(properties.getProperty("warmup", "10"))) + .gray(Boolean.parseBoolean(properties.getProperty("gray", "false"))) .status(0 == u.getStatus()) .timestamp(Optional.ofNullable(u.getDateCreated()).map(Timestamp::getTime).orElse(System.currentTimeMillis())) .build(); diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/handler/GrpcDiscoveryUpstreamDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/handler/GrpcDiscoveryUpstreamDataHandler.java index c209e03675..9f0b3fa6d4 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/handler/GrpcDiscoveryUpstreamDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-grpc/src/main/java/org/apache/shenyu/plugin/grpc/handler/GrpcDiscoveryUpstreamDataHandler.java @@ -50,7 +50,13 @@ public class GrpcDiscoveryUpstreamDataHandler implements DiscoveryUpstreamDataHa } LOG.info("discovery grpc upstream data:{}", JsonUtils.toJson(discoverySyncData)); final String selectorId = discoverySyncData.getSelectorId(); - ApplicationConfigCache.getInstance().handlerUpstream(selectorId, convertUpstreamList(discoverySyncData.getUpstreamDataList())); + final List<GrpcUpstream> upstreams = convertUpstreamList(discoverySyncData.getUpstreamDataList()); + final List<GrpcUpstream> grayUpstreamList = upstreams.stream().filter(GrpcUpstream::isGray).toList(); + if (!grayUpstreamList.isEmpty()) { + ApplicationConfigCache.getInstance().handlerUpstream(discoverySyncData.getSelectorId(), grayUpstreamList); + } else { + ApplicationConfigCache.getInstance().handlerUpstream(discoverySyncData.getSelectorId(), upstreams); + } GrpcClientCache.initGrpcClient(selectorId); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/handler/WebSocketUpstreamDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/handler/WebSocketUpstreamDataHandler.java index a532e6a036..c5a07c0ce6 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/handler/WebSocketUpstreamDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-websocket/src/main/java/org/apache/shenyu/plugin/websocket/handler/WebSocketUpstreamDataHandler.java @@ -46,7 +46,13 @@ public class WebSocketUpstreamDataHandler implements DiscoveryUpstreamDataHandle return; } List<DiscoveryUpstreamData> upstreamList = discoverySyncData.getUpstreamDataList(); - UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), convertUpstreamList(upstreamList)); + final List<Upstream> upstreams = convertUpstreamList(upstreamList); + final List<Upstream> grayUpstreamList = upstreams.stream().filter(Upstream::isGray).toList(); + if (!grayUpstreamList.isEmpty()) { + UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), grayUpstreamList); + } else { + UpstreamCacheManager.getInstance().submit(discoverySyncData.getSelectorId(), upstreams); + } MetaDataCache.getInstance().clean(); }