feat: support config empty protection. (#1583)

Co-authored-by: Haotian Zhang <skyebefreeman@qq.com>
pull/1600/head
Fishtail 3 months ago committed by Haotian Zhang
parent b1f6ec908d
commit 254e7a3738

@ -37,3 +37,4 @@
- [feat:support stat and event report with service discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1560)
- [fix: add gateway context config example.](https://github.com/Tencent/spring-cloud-tencent/pull/1561)
- [fix: use getActiveRuleId method to fix javaagent ratelimit pb method not found error.](https://github.com/Tencent/spring-cloud-tencent/pull/1575)
- [feat:support config empty protection.](https://github.com/Tencent/spring-cloud-tencent/pull/1583)

@ -80,11 +80,12 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
}
private void initDataSource(ConfigurationImpl configuration) {
ConnectorConfigImpl connectorConfig = configuration.getConfigFile().getServerConnector();
// set connector type
configuration.getConfigFile().getServerConnector().setConnectorType(polarisConfigProperties.getDataSource());
connectorConfig.setConnectorType(polarisConfigProperties.getDataSource());
if (StringUtils.equalsIgnoreCase(polarisConfigProperties.getDataSource(), LOCAL_FILE_CONNECTOR_TYPE)) {
String localFileRootPath = polarisConfigProperties.getLocalFileRootPath();
configuration.getConfigFile().getServerConnector().setPersistDir(localFileRootPath);
connectorConfig.setPersistDir(localFileRootPath);
LOGGER.info("[SCT] Run spring cloud tencent config with local data source. localFileRootPath = {}", localFileRootPath);
return;
}
@ -108,13 +109,15 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
checkAddressAccessible(configAddresses);
}
configuration.getConfigFile().getServerConnector().setAddresses(configAddresses);
connectorConfig.setAddresses(configAddresses);
if (StringUtils.isNotEmpty(polarisConfigProperties.getToken())) {
ConnectorConfigImpl connectorConfig = configuration.getConfigFile().getServerConnector();
connectorConfig.setToken(polarisConfigProperties.getToken());
}
connectorConfig.setEmptyProtectionEnable(polarisConfigProperties.isEmptyProtectionEnabled());
connectorConfig.setEmptyProtectionExpiredInterval(polarisConfigProperties.getEmptyProtectionExpiredInterval());
LOGGER.info("[SCT] Run spring cloud tencent config in polaris data source.");
}

@ -97,6 +97,17 @@ public class PolarisConfigProperties {
private boolean checkAddress = true;
/**
* if empty protection is enabled.
*/
private boolean emptyProtectionEnabled = true;
/**
* interval of empty protection. 7 days by default.
*/
private long emptyProtectionExpiredInterval = 7 * 24 * 3600 * 1000L;
public boolean isEnabled() {
return enabled;
}
@ -201,6 +212,22 @@ public class PolarisConfigProperties {
this.checkAddress = checkAddress;
}
public boolean isEmptyProtectionEnabled() {
return emptyProtectionEnabled;
}
public void setEmptyProtectionEnabled(boolean emptyProtectionEnabled) {
this.emptyProtectionEnabled = emptyProtectionEnabled;
}
public long getEmptyProtectionExpiredInterval() {
return emptyProtectionExpiredInterval;
}
public void setEmptyProtectionExpiredInterval(long emptyProtectionExpiredInterval) {
this.emptyProtectionExpiredInterval = emptyProtectionExpiredInterval;
}
@Override
public String toString() {
return "PolarisConfigProperties{" +
@ -217,6 +244,8 @@ public class PolarisConfigProperties {
", localFileRootPath='" + localFileRootPath + '\'' +
", internalEnabled=" + internalEnabled +
", checkAddress=" + checkAddress +
", emptyProtectionEnabled=" + emptyProtectionEnabled +
", emptyProtectionExpiredInterval=" + emptyProtectionExpiredInterval +
'}';
}
}

@ -73,7 +73,7 @@
<revision>2.0.2.0-Hoxton.SR12-SNAPSHOT</revision>
<!-- Dependencies -->
<polaris.version>2.0.1.0-SNAPSHOT</polaris.version>
<polaris.version>2.0.2.0-SNAPSHOT</polaris.version>
<guava.version>32.1.3-jre</guava.version>
<logback.version>1.2.13</logback.version>
<springdoc.version>1.7.0</springdoc.version>

Loading…
Cancel
Save