Skip to content

Commit

Permalink
feature:expands grayscale publishing capabilities to support dimensio…
Browse files Browse the repository at this point in the history
…ns other than IP

fix apolloconfig#2932
  • Loading branch information
zcy1010 committed Oct 6, 2021
1 parent 6e98ec6 commit bcbd03d
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 85 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,23 @@ 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);
return;
}

//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);
return;
}

// 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,
Expand Down
2 changes: 1 addition & 1 deletion apollo-demo/src/main/resources/META-INF/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#
# test
app.id=100004458
app.label=myLabel
apollo.label=myLabel
2 changes: 1 addition & 1 deletion apollo-portal/src/main/resources/static/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br> Grayscale process is as follows: <br> &nbsp; &nbsp; 1. Create grayscale version <br> &nbsp; &nbsp; 2. Configure grayscale configuration items <br> &nbsp; &nbsp; 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. <br> &nbsp; &nbsp; 4. Grayscale release <br> Grayscale version has two final results: <b> Full release and Abandon grayscale</b> <br> <b>Full release</b>: grayscale configurations are merged with the main version and released, all clients will use the merged configurations <br> <b> Abandon grayscale</b>: Delete grayscale version. All clients will use the configurations of the main version<br> Notice: <br> &nbsp; &nbsp; 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. <br> Grayscale process is as follows: <br> &nbsp; &nbsp; 1. Create grayscale version <br> &nbsp; &nbsp; 2. Configure grayscale configuration items <br> &nbsp; &nbsp; 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. <br> &nbsp; &nbsp; 4. Grayscale release <br> Grayscale version has two final results: <b> Full release and Abandon grayscale</b> <br> <b>Full release</b>: grayscale configurations are merged with the main version and released, all clients will use the merged configurations <br> <b> Abandon grayscale</b>: Delete grayscale version. All clients will use the configurations of the main version<br> Notice: <br> &nbsp; &nbsp; 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",
Expand Down
2 changes: 1 addition & 1 deletion apollo-portal/src/main/resources/static/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
"Config.SyntaxCheckFailed.DialogTitle": "语法检查错误",
"Config.SyntaxCheckFailed.DialogContent": "删除Namespace失败提示",
"Config.CreateBranchTips.DialogTitle": "创建灰度须知",
"Config.CreateBranchTips.DialogContent": "通过创建灰度版本,您可以对某些配置做灰度测试<br>灰度流程为:<br>&nbsp;&nbsp;1.创建灰度版本 <br>&nbsp;&nbsp;2.配置灰度配置项<br>&nbsp;&nbsp;3.配置灰度规则.如果是私有的namespace可以按照客户端的IP进行灰度,如果是公共的namespace则可以同时按AppId和客户端的IP进行灰度<br>&nbsp;&nbsp;4.灰度发布<br>灰度版本最终有两种结果:<b>全量发布和放弃灰度</b><br><b>全量发布</b>:灰度的配置合到主版本并发布,所有的客户端都会使用合并后的配置<br><b>放弃灰度</b>:删除灰度版本,所有的客户端都会使用回主版本的配置<br>注意事项:<br>&nbsp;&nbsp;1.如果灰度版本已经有灰度发布过,那么修改灰度规则后,无需再次灰度发布就立即生效",
"Config.CreateBranchTips.DialogContent": "通过创建灰度版本,您可以对某些配置做灰度测试<br>灰度流程为:<br>&nbsp;&nbsp;1.创建灰度版本 <br>&nbsp;&nbsp;2.配置灰度配置项<br>&nbsp;&nbsp;3.配置灰度规则.如果是私有的namespace可以按照客户端的IP和Label进行灰度,如果是公共的namespace则可以同时按AppId,客户端的IP和客户端的Label进行灰度<br>&nbsp;&nbsp;4.灰度发布<br>灰度版本最终有两种结果:<b>全量发布和放弃灰度</b><br><b>全量发布</b>:灰度的配置合到主版本并发布,所有的客户端都会使用合并后的配置<br><b>放弃灰度</b>:删除灰度版本,所有的客户端都会使用回主版本的配置<br>注意事项:<br>&nbsp;&nbsp;1.如果灰度版本已经有灰度发布过,那么修改灰度规则后,无需再次灰度发布就立即生效",
"Config.ProjectMissEnvInfos": "当前应用有环境缺失,请点击页面左侧『补缺环境』补齐数据",
"Config.ProjectMissNamespaceInfos": "当前环境有Namespace缺失,请点击页面左侧『补缺Namespace』补齐数据",
"Config.SystemError": "系统出错,请重试或联系系统负责人",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h4 class="modal-title">
</div>
</div>

<div class="form-group" ng -show="!branch.editingRuleItem.ApplyToAllInstances">
<div class="form-group" ng-show="!branch.editingRuleItem.ApplyToAllInstances">
<label class="control-label col-md-3 text-right">
<apollorequiredfield></apollorequiredfield>
{{'Component.GrayscalePublishRule.IP' | translate }}
Expand Down Expand Up @@ -102,7 +102,7 @@ <h4 class="modal-title">
</div>
</div>

<div class="form-group" ng -show="!branch.editingRuleItem.ApplyToAllInstances">
<div class="form-group" ng-show="!branch.editingRuleItem.ApplyToAllInstances">
<label class="control-label col-md-3 text-right">
<apollorequiredfield></apollorequiredfield>
{{'Component.GrayscalePublishRule.Label' | translate }}
Expand Down
Loading

0 comments on commit bcbd03d

Please sign in to comment.