Skip to content

Commit 3acc36a

Browse files
author
ZhangJian He
authored
Merge branch 'master' into master
2 parents 63b196f + d886164 commit 3acc36a

File tree

76 files changed

+1184
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1184
-330
lines changed

CHANGES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Apollo 2.4.0
88
* [Update the server config link in system info page](https://github.com/apolloconfig/apollo/pull/5204)
99
* [Feature support portal restTemplate Client connection pool config](https://github.com/apolloconfig/apollo/pull/5200)
1010
* [Feature added the ability for administrators to globally search for Value](https://github.com/apolloconfig/apollo/pull/5182)
11+
* [Fix: Resolve issues with duplicate comments and blank lines in configuration management](https://github.com/apolloconfig/apollo/pull/5232)
12+
* [Fix link namespace published items show missing some items](https://github.com/apolloconfig/apollo/pull/5240)
13+
* [Feature: Add limit and whitelist for namespace count per appid+cluster](https://github.com/apolloconfig/apollo/pull/5228)
14+
* [Feature support the observe status access-key for pre-check and logging only](https://github.com/apolloconfig/apollo/pull/5236)
15+
* [Feature add limit for items count per namespace](https://github.com/apolloconfig/apollo/pull/5227)
16+
* [Feature: Add ConfigService cache record stats function](https://github.com/apolloconfig/apollo/pull/5247)
17+
* [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248)
18+
* [Refactor: Configuration files uniformly use Kebab style](https://github.com/apolloconfig/apollo/pull/5262)
1119

1220
------------------
13-
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
21+
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AccessKeyController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package com.ctrip.framework.apollo.adminservice.controller;
1818

19+
import static com.ctrip.framework.apollo.common.constants.AccessKeyMode.FILTER;
20+
1921
import com.ctrip.framework.apollo.biz.entity.AccessKey;
2022
import com.ctrip.framework.apollo.biz.service.AccessKeyService;
2123
import com.ctrip.framework.apollo.common.dto.AccessKeyDTO;
@@ -27,6 +29,7 @@
2729
import org.springframework.web.bind.annotation.PostMapping;
2830
import org.springframework.web.bind.annotation.PutMapping;
2931
import org.springframework.web.bind.annotation.RequestBody;
32+
import org.springframework.web.bind.annotation.RequestParam;
3033
import org.springframework.web.bind.annotation.RestController;
3134

3235
/**
@@ -61,9 +64,11 @@ public void delete(@PathVariable String appId, @PathVariable long id, String ope
6164
}
6265

6366
@PutMapping(value = "/apps/{appId}/accesskeys/{id}/enable")
64-
public void enable(@PathVariable String appId, @PathVariable long id, String operator) {
67+
public void enable(@PathVariable String appId, @PathVariable long id,
68+
@RequestParam(required = false, defaultValue = "" + FILTER) int mode, String operator) {
6569
AccessKey entity = new AccessKey();
6670
entity.setId(id);
71+
entity.setMode(mode);
6772
entity.setEnabled(true);
6873
entity.setDataChangeLastModifiedBy(operator);
6974

@@ -74,6 +79,7 @@ public void enable(@PathVariable String appId, @PathVariable long id, String ope
7479
public void disable(@PathVariable String appId, @PathVariable long id, String operator) {
7580
AccessKey entity = new AccessKey();
7681
entity.setId(id);
82+
entity.setMode(FILTER);
7783
entity.setEnabled(false);
7884
entity.setDataChangeLastModifiedBy(operator);
7985

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.ctrip.framework.apollo.adminservice.controller;
1818

1919
import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock;
20+
import com.ctrip.framework.apollo.biz.config.BizConfig;
2021
import com.ctrip.framework.apollo.biz.entity.Commit;
2122
import com.ctrip.framework.apollo.biz.entity.Item;
2223
import com.ctrip.framework.apollo.biz.entity.Namespace;
@@ -58,13 +59,14 @@ public class ItemController {
5859
private final NamespaceService namespaceService;
5960
private final CommitService commitService;
6061
private final ReleaseService releaseService;
62+
private final BizConfig bizConfig;
6163

62-
63-
public ItemController(final ItemService itemService, final NamespaceService namespaceService, final CommitService commitService, final ReleaseService releaseService) {
64+
public ItemController(final ItemService itemService, final NamespaceService namespaceService, final CommitService commitService, final ReleaseService releaseService, final BizConfig bizConfig) {
6465
this.itemService = itemService;
6566
this.namespaceService = namespaceService;
6667
this.commitService = commitService;
6768
this.releaseService = releaseService;
69+
this.bizConfig = bizConfig;
6870
}
6971

7072
@PreAcquireNamespaceLock
@@ -78,6 +80,14 @@ public ItemDTO create(@PathVariable("appId") String appId,
7880
if (managedEntity != null) {
7981
throw BadRequestException.itemAlreadyExists(entity.getKey());
8082
}
83+
84+
if (bizConfig.isItemNumLimitEnabled()) {
85+
int itemCount = itemService.findNonEmptyItemCount(entity.getNamespaceId());
86+
if (itemCount >= bizConfig.itemNumLimit()) {
87+
throw new BadRequestException("The maximum number of items (" + bizConfig.itemNumLimit() + ") for this namespace has been reached. Current item count is " + itemCount + ".");
88+
}
89+
}
90+
8191
entity = itemService.save(entity);
8292
dto = BeanUtils.transform(ItemDTO.class, entity);
8393
commitService.createCommit(appId, clusterName, namespaceName, new ConfigChangeContentBuilder().createItem(entity).build(),

apollo-adminservice/src/main/resources/application-database-discovery.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ spring.cloud.discovery.enabled=false
1818

1919
apollo.service.registry.enabled=true
2020
apollo.service.registry.cluster=default
21-
apollo.service.registry.heartbeatIntervalInSecond=10
21+
apollo.service.registry.heartbeat-interval-in-second=10
2222

apollo-adminservice/src/main/resources/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ logging:
3838
eureka:
3939
instance:
4040
hostname: ${hostname:localhost}
41-
preferIpAddress: true
41+
prefer-ip-address: true
4242
status-page-url-path: /info
4343
health-check-url-path: /health
4444
client:
45-
serviceUrl:
45+
service-url:
4646
# This setting will be overridden by eureka.service.url setting from ApolloConfigDB.ServerConfig or System Property
4747
# see com.ctrip.framework.apollo.biz.eureka.ApolloEurekaClientConfig
4848
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
4949
healthcheck:
5050
enabled: true
51-
eurekaServiceUrlPollIntervalSeconds: 60
51+
eureka-service-url-poll-interval-seconds: 60
5252

5353
management:
5454
health:

apollo-adminservice/src/test/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ server:
2323
eureka:
2424
instance:
2525
hostname: ${hostname:localhost}
26-
preferIpAddress: true
26+
prefer-ip-address: true
2727
status-page-url-path: /info
2828
health-check-url-path: /health
2929
client:
30-
serviceUrl:
30+
service-url:
3131
defaultZone: http://${eureka.instance.hostname}:8090/eureka/
3232
healthcheck:
3333
enabled: true

apollo-assembly/src/main/resources/application-database-discovery.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ spring.cloud.discovery.enabled=false
1919

2020
apollo.service.registry.enabled=true
2121
apollo.service.registry.cluster=default
22-
apollo.service.registry.heartbeatIntervalInSecond=10
22+
apollo.service.registry.heartbeat-interval-in-second=10
2323

2424
apollo.service.discovery.enabled=true
2525
# health check by heartbeat, heartbeat time before 61s ago will be seemed as unhealthy
26-
apollo.service.discovery.healthCheckIntervalInSecond = 61
26+
apollo.service.discovery.health-check-interval-in-second = 61

apollo-assembly/src/main/resources/application.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spring:
3030

3131
logging:
3232
file:
33-
name: /opt/logs/100003171/apollo-assembly.log
33+
name: /opt/logs/apollo-assembly.log
3434

3535
management:
3636
health:
@@ -42,22 +42,22 @@ management:
4242
eureka:
4343
instance:
4444
hostname: ${hostname:localhost}
45-
preferIpAddress: true
45+
prefer-ip-address: true
4646
status-page-url-path: /info
4747
health-check-url-path: /health
4848
server:
49-
peerEurekaNodesUpdateIntervalMs: 60000
50-
enableSelfPreservation: false
49+
peer-eureka-nodes-update-interval-ms: 60000
50+
enable-self-preservation: false
5151
client:
52-
serviceUrl:
52+
service-url:
5353
# This setting will be overridden by eureka.service.url setting from ApolloConfigDB.ServerConfig or System Property
5454
# see com.ctrip.framework.apollo.biz.eureka.ApolloEurekaClientConfig
5555
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
5656
healthcheck:
5757
enabled: true
58-
eurekaServiceUrlPollIntervalSeconds: 60
58+
eureka-service-url-poll-interval-seconds: 60
5959
fetch-registry: false
60-
registerWithEureka: false
60+
register-with-eureka: false
6161

6262
server:
6363
compression:

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import com.ctrip.framework.apollo.common.config.RefreshablePropertySource;
2222
import com.google.common.base.Strings;
2323
import com.google.common.collect.Maps;
24+
import com.google.common.collect.Sets;
2425
import com.google.gson.Gson;
2526
import com.google.gson.reflect.TypeToken;
2627
import java.lang.reflect.Type;
2728
import java.util.Collections;
2829
import java.util.List;
2930
import java.util.Map;
31+
import java.util.Set;
3032
import java.util.concurrent.TimeUnit;
3133
import java.util.stream.Collectors;
3234
import org.springframework.stereotype.Component;
@@ -36,6 +38,11 @@ public class BizConfig extends RefreshableConfig {
3638

3739
private static final int DEFAULT_ITEM_KEY_LENGTH = 128;
3840
private static final int DEFAULT_ITEM_VALUE_LENGTH = 20000;
41+
42+
private static final int DEFAULT_MAX_NAMESPACE_NUM = 200;
43+
44+
private static final int DEFAULT_MAX_ITEM_NUM = 1000;
45+
3946
private static final int DEFAULT_APPNAMESPACE_CACHE_REBUILD_INTERVAL = 60; //60s
4047
private static final int DEFAULT_GRAY_RELEASE_RULE_SCAN_INTERVAL = 60; //60s
4148
private static final int DEFAULT_APPNAMESPACE_CACHE_SCAN_INTERVAL = 1; //1s
@@ -99,6 +106,28 @@ public int itemValueLengthLimit() {
99106
return checkInt(limit, 5, Integer.MAX_VALUE, DEFAULT_ITEM_VALUE_LENGTH);
100107
}
101108

109+
public boolean isNamespaceNumLimitEnabled() {
110+
return getBooleanProperty("namespace.num.limit.enabled", false);
111+
}
112+
113+
public int namespaceNumLimit() {
114+
int limit = getIntProperty("namespace.num.limit", DEFAULT_MAX_NAMESPACE_NUM);
115+
return checkInt(limit, 0, Integer.MAX_VALUE, DEFAULT_MAX_NAMESPACE_NUM);
116+
}
117+
118+
public Set<String> namespaceNumLimitWhite() {
119+
return Sets.newHashSet(getArrayProperty("namespace.num.limit.white", new String[0]));
120+
}
121+
122+
public boolean isItemNumLimitEnabled() {
123+
return getBooleanProperty("item.num.limit.enabled", false);
124+
}
125+
126+
public int itemNumLimit() {
127+
int limit = getIntProperty("item.num.limit", DEFAULT_MAX_ITEM_NUM);
128+
return checkInt(limit, 5, Integer.MAX_VALUE, DEFAULT_MAX_ITEM_NUM);
129+
}
130+
102131
public Map<Long, Integer> namespaceValueLengthLimitOverride() {
103132
String namespaceValueLengthOverrideString = getValue("namespace.value.length.limit.override");
104133
Map<Long, Integer> namespaceValueLengthOverride = Maps.newHashMap();
@@ -205,6 +234,10 @@ public boolean isConfigServiceCacheEnabled() {
205234
return getBooleanProperty("config-service.cache.enabled", false);
206235
}
207236

237+
public boolean isConfigServiceCacheStatsEnabled() {
238+
return getBooleanProperty("config-service.cache.stats.enabled", false);
239+
}
240+
208241
public boolean isConfigServiceCacheKeyIgnoreCase() {
209242
return getBooleanProperty("config-service.cache.key.ignore-case", false);
210243
}

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/AccessKey.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class AccessKey extends BaseEntity {
3636
@Column(name = "`Secret`", nullable = false)
3737
private String secret;
3838

39+
@Column(name = "`Mode`")
40+
private int mode;
41+
3942
@Column(name = "`IsEnabled`", columnDefinition = "Bit default '0'")
4043
private boolean enabled;
4144

@@ -55,6 +58,14 @@ public void setSecret(String secret) {
5558
this.secret = secret;
5659
}
5760

61+
public int getMode() {
62+
return mode;
63+
}
64+
65+
public void setMode(int mode) {
66+
this.mode = mode;
67+
}
68+
5869
public boolean isEnabled() {
5970
return enabled;
6071
}
@@ -66,6 +77,6 @@ public void setEnabled(boolean enabled) {
6677
@Override
6778
public String toString() {
6879
return toStringHelper().add("appId", appId).add("secret", secret)
69-
.add("enabled", enabled).toString();
80+
.add("mode", mode).add("enabled", enabled).toString();
7081
}
7182
}

0 commit comments

Comments
 (0)