From bcbd03da2437257f430f53c3054e3d800e911125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=87=8D=E9=98=B3?= <1010720098@qq.com> Date: Wed, 6 Oct 2021 22:57:34 +0800 Subject: [PATCH] feature:expands grayscale publishing capabilities to support dimensions other than IP fix #2932 --- CHANGES.md | 1 + .../GrayReleaseRulesHolderTest.java | 11 +- .../internals/RemoteConfigRepository.java | 4 +- .../framework/apollo/util/ConfigUtil.java | 10 +- .../common/dto/GrayReleaseRuleItemDTO.java | 2 +- .../controller/ConfigControllerTest.java | 2 +- .../apollo/core/ApolloClientSystemConsts.java | 4 +- .../framework/apollo/core/ConfigConsts.java | 1 - .../provider/DefaultApplicationProvider.java | 6 +- .../main/resources/META-INF/app.properties | 2 +- .../src/main/resources/static/i18n/en.json | 2 +- .../src/main/resources/static/i18n/zh-CN.json | 2 +- .../gray-release-rules-modal-directive.js | 2 +- .../directive/namespace-panel-directive.js | 4 +- .../component/gray-release-rules-modal.html | 4 +- docs/zh/usage/java-sdk-user-guide.md | 112 +++++++++--------- 16 files changed, 84 insertions(+), 85 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bf95b084771..aa82770f773 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Apollo 1.10.0 * [feat(scripts): use bash to call openapi](https://github.com/apolloconfig/apollo/pull/3980) * [Support search by item](https://github.com/apolloconfig/apollo/pull/3977) * [Implement password policies to avoid weak passwords](https://github.com/apolloconfig/apollo/pull/4008) +* [Extend the gray release capability to support dimensions other than IP](https://github.com/apolloconfig/apollo/pull/4013) ------------------ All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1) \ No newline at end of file diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java index a9e33165a4e..68e3265fc5e 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java @@ -101,7 +101,9 @@ public void testScanGrayReleaseRules() throws Exception { grayReleaseRulesHolder.afterPropertiesSet(); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule - (someClientAppId, someClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); + (someClientAppId, someClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (someClientAppId, anotherClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule (someClientAppId.toUpperCase(), someClientIp, someClientLabel, someAppId.toUpperCase(), someClusterName, someNamespaceName.toUpperCase())); assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(someClientAppId, @@ -128,7 +130,7 @@ public void testScanGrayReleaseRules() throws Exception { GrayReleaseRule anotherRule = assembleGrayReleaseRule(someAppId, someClusterName, someNamespaceName, Lists.newArrayList(assembleRuleItem(anotherClientAppId, Sets.newHashSet - (anotherClientIp),Sets.newHashSet(someClientLabel))), someReleaseId, activeBranchStatus); + (anotherClientIp),Sets.newHashSet(anotherClientLabel))), someReleaseId, activeBranchStatus); when(grayReleaseRuleRepository.findByAppIdAndClusterNameAndNamespaceName(someAppId, someClusterName, someNamespaceName)).thenReturn(Lists.newArrayList(anotherRule)); @@ -139,9 +141,14 @@ public void testScanGrayReleaseRules() throws Exception { assertNull(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule (someClientAppId, someClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (anotherClientAppId, anotherClientIp, someClientLabel, someAppId, someClusterName, someNamespaceName)); + assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule + (anotherClientAppId, someClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); assertEquals(someReleaseId, grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule (anotherClientAppId, anotherClientIp, anotherClientLabel, someAppId, someClusterName, someNamespaceName)); + assertFalse(grayReleaseRulesHolder.hasGrayReleaseRule(someClientAppId, someClientIp, someNamespaceName)); assertFalse(grayReleaseRulesHolder.hasGrayReleaseRule(someClientAppId, someClientIp, diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index f35c06f05ff..fcb4b0ecd64 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -311,8 +311,8 @@ String assembleQueryConfigUrl(String uri, String appId, String cluster, String n queryParams.put("ip", queryParamEscaper.escape(localIp)); } - String label=m_configUtil.getAppLabel(); - if(!Strings.isNullOrEmpty(label)){ + String label = m_configUtil.getAppLabel(); + if (!Strings.isNullOrEmpty(label)) { queryParams.put("label", queryParamEscaper.escape(label)); } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java index 9b3b9c34a09..0288efafb56 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java @@ -95,15 +95,7 @@ public String getAppId() { * @return the app label or ConfigConsts.NO_APPLABEL_PLACEHOLDER if app label is not available */ public String getAppLabel() { - String appLabel = Foundation.app().getAppLabel(); - if (Strings.isNullOrEmpty(appLabel)) { - appLabel = ConfigConsts.NO_APPLABEL_PLACEHOLDER; - if (warnLogRateLimiter.tryAcquire()) { - logger.warn( - "app.label is not set, please make sure it is set in classpath:/META-INF/app.properties, now apollo will only load public namespace configurations!"); - } - } - return appLabel; + return Foundation.app().getAppLabel(); } /** diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java index d20525b7062..6ea0dd83c0e 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java @@ -75,6 +75,6 @@ private boolean labelMatches(String clientLabel) { public String toString() { return toStringHelper(this).add("clientAppId", clientAppId) .add("clientIpList", clientIpList) - .add("clientLabelList",clientLabelList).toString(); + .add("clientLabelList", clientLabelList).toString(); } } diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java index 6720196d4f4..94bd5fd64b2 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java @@ -109,7 +109,7 @@ public void setUp() throws Exception { @Test public void testQueryConfig() throws Exception { - String someClientSideReleaseKey = "4"; + String someClientSideReleaseKey = "1"; String someServerSideNewReleaseKey = "2"; HttpServletResponse someResponse = mock(HttpServletResponse.class); diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ApolloClientSystemConsts.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ApolloClientSystemConsts.java index 0da9226cc7f..b1718ef4d1c 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ApolloClientSystemConsts.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ApolloClientSystemConsts.java @@ -29,7 +29,7 @@ public class ApolloClientSystemConsts { /** * apollo client app label */ - public static final String APP_LABEL = "app.label"; + public static final String APOLLO_LABEL = "apollo.label"; /** * apollo client app id environment variables @@ -39,7 +39,7 @@ public class ApolloClientSystemConsts { /** * apollo client app label environment variables */ - public static final String APP_LABEL_ENVIRONMENT_VARIABLES = "APP_LABEL"; + public static final String APOLLO_LABEL_ENVIRONMENT_VARIABLES = "APOLLO_LABEL"; /** * cluster name diff --git a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ConfigConsts.java b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ConfigConsts.java index 23f1d736bbf..921bb72c771 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ConfigConsts.java +++ b/apollo-core/src/main/java/com/ctrip/framework/apollo/core/ConfigConsts.java @@ -24,6 +24,5 @@ public interface ConfigConsts { String APOLLO_META_KEY = "apollo.meta"; String CONFIG_FILE_CONTENT_KEY = "content"; String NO_APPID_PLACEHOLDER = "ApolloNoAppIdPlaceHolder"; - String NO_APPLABEL_PLACEHOLDER = "ApolloNoAppLabelPlaceHolder"; long NOTIFICATION_ID_PLACEHOLDER = -1; } diff --git a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/provider/DefaultApplicationProvider.java b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/provider/DefaultApplicationProvider.java index 591cff539e3..17dd0727819 100644 --- a/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/provider/DefaultApplicationProvider.java +++ b/apollo-core/src/main/java/com/ctrip/framework/foundation/internals/provider/DefaultApplicationProvider.java @@ -149,7 +149,7 @@ private void initAppId() { private void initAppLabel() { // 1. Get app.label from System Property - m_appLabel = System.getProperty(ApolloClientSystemConsts.APP_LABEL); + m_appLabel = System.getProperty(ApolloClientSystemConsts.APOLLO_LABEL); if (!Utils.isBlank(m_appLabel)) { m_appLabel = m_appLabel.trim(); logger.info("App Label is set to {} by app.label property from System Property", m_appLabel); @@ -157,7 +157,7 @@ private void initAppLabel() { } //2. Try to get app label from OS environment variable - m_appLabel = System.getenv(ApolloClientSystemConsts.APP_LABEL_ENVIRONMENT_VARIABLES); + m_appLabel = System.getenv(ApolloClientSystemConsts.APOLLO_LABEL_ENVIRONMENT_VARIABLES); if (!Utils.isBlank(m_appLabel)) { m_appLabel = m_appLabel.trim(); logger.info("App Label is set to {} by APP_LABEL property from OS environment variable", m_appLabel); @@ -165,7 +165,7 @@ private void initAppLabel() { } // 3. Try to get app label from app.properties. - m_appLabel = m_appProperties.getProperty(ApolloClientSystemConsts.APP_LABEL); + m_appLabel = m_appProperties.getProperty(ApolloClientSystemConsts.APOLLO_LABEL); if (!Utils.isBlank(m_appLabel)) { m_appLabel = m_appLabel.trim(); logger.info("App Label is set to {} by app.label property from {}", m_appLabel, diff --git a/apollo-demo/src/main/resources/META-INF/app.properties b/apollo-demo/src/main/resources/META-INF/app.properties index b40e9c003bf..df455bd913f 100644 --- a/apollo-demo/src/main/resources/META-INF/app.properties +++ b/apollo-demo/src/main/resources/META-INF/app.properties @@ -15,4 +15,4 @@ # # test app.id=100004458 -app.label=myLabel \ No newline at end of file +apollo.label=myLabel \ No newline at end of file diff --git a/apollo-portal/src/main/resources/static/i18n/en.json b/apollo-portal/src/main/resources/static/i18n/en.json index 2d1cfbb8f82..9a840aa9817 100644 --- a/apollo-portal/src/main/resources/static/i18n/en.json +++ b/apollo-portal/src/main/resources/static/i18n/en.json @@ -386,7 +386,7 @@ "Config.SyntaxCheckFailed.DialogTitle": "Syntax Check Error", "Config.SyntaxCheckFailed.DialogContent": "Delete Namespace Failure Tip", "Config.CreateBranchTips.DialogTitle": "Create Grayscale Notice", - "Config.CreateBranchTips.DialogContent": "By creating grayscale version, you can do grayscale test for some configurations.
Grayscale process is as follows:
    1. Create grayscale version
    2. Configure grayscale configuration items
    3. Configure grayscale rules. If it is a private namespace, it can be grayed according to the IP of client. If it is a public namespace, it can be grayed according to both appId and the IP.
    4. Grayscale release
Grayscale version has two final results: Full release and Abandon grayscale
Full release: grayscale configurations are merged with the main version and released, all clients will use the merged configurations
Abandon grayscale: Delete grayscale version. All clients will use the configurations of the main version
Notice:
    1. If the grayscale version has been released, then the grayscale rules will be effective immediately without the need to release grayscale configuration again.", + "Config.CreateBranchTips.DialogContent": "By creating grayscale version, you can do grayscale test for some configurations.
Grayscale process is as follows:
    1. Create grayscale version
    2. Configure grayscale configuration items
    3. Configure grayscale rules. If it is a private namespace, it can be grayed according to the IP and Label of client. If it is a public namespace, it can be grayed according to appId, IP and Label.
    4. Grayscale release
Grayscale version has two final results: Full release and Abandon grayscale
Full release: grayscale configurations are merged with the main version and released, all clients will use the merged configurations
Abandon grayscale: Delete grayscale version. All clients will use the configurations of the main version
Notice:
    1. If the grayscale version has been released, then the grayscale rules will be effective immediately without the need to release grayscale configuration again.", "Config.ProjectMissEnvInfos": "There are missing environments in the current project, please click \"Recover Environments\" on the left side of the page to do the recovery.", "Config.ProjectMissNamespaceInfos": "There are missing namespaces in the current environment. Please click \"Recover Namespaces\" on the left side of the page to do the recovery.", "Config.SystemError": "System error, please try again or contact the system administrator", diff --git a/apollo-portal/src/main/resources/static/i18n/zh-CN.json b/apollo-portal/src/main/resources/static/i18n/zh-CN.json index 529b69c3c4b..49c351242f7 100644 --- a/apollo-portal/src/main/resources/static/i18n/zh-CN.json +++ b/apollo-portal/src/main/resources/static/i18n/zh-CN.json @@ -386,7 +386,7 @@ "Config.SyntaxCheckFailed.DialogTitle": "语法检查错误", "Config.SyntaxCheckFailed.DialogContent": "删除Namespace失败提示", "Config.CreateBranchTips.DialogTitle": "创建灰度须知", - "Config.CreateBranchTips.DialogContent": "通过创建灰度版本,您可以对某些配置做灰度测试
灰度流程为:
  1.创建灰度版本
  2.配置灰度配置项
  3.配置灰度规则.如果是私有的namespace可以按照客户端的IP进行灰度,如果是公共的namespace则可以同时按AppId和客户端的IP进行灰度
  4.灰度发布
灰度版本最终有两种结果:全量发布和放弃灰度
全量发布:灰度的配置合到主版本并发布,所有的客户端都会使用合并后的配置
放弃灰度:删除灰度版本,所有的客户端都会使用回主版本的配置
注意事项:
  1.如果灰度版本已经有灰度发布过,那么修改灰度规则后,无需再次灰度发布就立即生效", + "Config.CreateBranchTips.DialogContent": "通过创建灰度版本,您可以对某些配置做灰度测试
灰度流程为:
  1.创建灰度版本
  2.配置灰度配置项
  3.配置灰度规则.如果是私有的namespace可以按照客户端的IP和Label进行灰度,如果是公共的namespace则可以同时按AppId,客户端的IP和客户端的Label进行灰度
  4.灰度发布
灰度版本最终有两种结果:全量发布和放弃灰度
全量发布:灰度的配置合到主版本并发布,所有的客户端都会使用合并后的配置
放弃灰度:删除灰度版本,所有的客户端都会使用回主版本的配置
注意事项:
  1.如果灰度版本已经有灰度发布过,那么修改灰度规则后,无需再次灰度发布就立即生效", "Config.ProjectMissEnvInfos": "当前应用有环境缺失,请点击页面左侧『补缺环境』补齐数据", "Config.ProjectMissNamespaceInfos": "当前环境有Namespace缺失,请点击页面左侧『补缺Namespace』补齐数据", "Config.SystemError": "系统出错,请重试或联系系统负责人", diff --git a/apollo-portal/src/main/resources/static/scripts/directive/gray-release-rules-modal-directive.js b/apollo-portal/src/main/resources/static/scripts/directive/gray-release-rules-modal-directive.js index f3a98bd738a..7dff7e1869f 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive/gray-release-rules-modal-directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive/gray-release-rules-modal-directive.js @@ -45,7 +45,7 @@ function rulesModalDirective($translate, toastr, AppUtil, EventManager, Instance var branch = context.branch; scope.branch = branch; - if (branch.editingRuleItem.clientIpList && branch.editingRuleItem.clientIpList[0] == '*') { + if (branch.editingRuleItem.clientIpList && branch.editingRuleItem.clientIpList[0] == '*' && branch.editingRuleItem.clientLabelList && branch.editingRuleItem.clientLabelList[0] == '*') { branch.editingRuleItem.ApplyToAllInstances = true; } else { branch.editingRuleItem.ApplyToAllInstances = false; diff --git a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js index 6d17452bcc6..fb54964b737 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js @@ -669,8 +669,8 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio function editRuleItem(branch, ruleItem) { ruleItem.isNew = false; - ruleItem.draftIpList = _.clone(ruleItem.clientIpList); - ruleItem.draftLabelList = _.clone(ruleItem.clientLabelList); + ruleItem.draftIpList = _.clone(ruleItem.clientIpList) || []; + ruleItem.draftLabelList = _.clone(ruleItem.clientLabelList) || []; branch.editingRuleItem = ruleItem; EventManager.emit(EventManager.EventType.EDIT_GRAY_RELEASE_RULES, { diff --git a/apollo-portal/src/main/resources/static/views/component/gray-release-rules-modal.html b/apollo-portal/src/main/resources/static/views/component/gray-release-rules-modal.html index b59645daddb..f0672e9b60f 100644 --- a/apollo-portal/src/main/resources/static/views/component/gray-release-rules-modal.html +++ b/apollo-portal/src/main/resources/static/views/component/gray-release-rules-modal.html @@ -57,7 +57,7 @@