fix: add config report property

pull/1813/head
fishtailfu 1 month ago
parent a3ed64c011
commit c12d31cc0c

@ -74,7 +74,7 @@ public class ConfigurationModifier implements PolarisConfigurationConfigModifier
clientReporterConfig.setEnable(true);
ConfigWatchReporterConfig configWatchReporterConfig = clientReporterConfig.getPluginConfig(
ConfigWatchClientReporter.NAME, ConfigWatchReporterConfig.class);
configWatchReporterConfig.setEnable(true);
configWatchReporterConfig.setEnable(polarisConfigProperties.isReportEnabled());
clientReporterConfig.setPluginConfig(ConfigWatchClientReporter.NAME, configWatchReporterConfig);
configuration.getConsumer().getOutlierDetection().setWhen(OutlierDetectionConfig.When.never);
configuration.getConsumer().getCircuitBreaker().setEnable(false);

@ -110,6 +110,12 @@ public class PolarisConfigProperties {
*/
private long emptyProtectionExpiredInterval = 7 * 24 * 3600 * 1000L;
/**
* If config watch metadata reporting is enabled.
*/
@Value("${spring.cloud.polaris.config.report.enabled:#{'true'}}")
private boolean reportEnabled = true;
public boolean isEnabled() {
return enabled;
@ -231,6 +237,14 @@ public class PolarisConfigProperties {
this.emptyProtectionExpiredInterval = emptyProtectionExpiredInterval;
}
public boolean isReportEnabled() {
return reportEnabled;
}
public void setReportEnabled(boolean reportEnabled) {
this.reportEnabled = reportEnabled;
}
@Override
public String toString() {
return "PolarisConfigProperties{" +
@ -249,6 +263,7 @@ public class PolarisConfigProperties {
", checkAddress=" + checkAddress +
", emptyProtectionEnabled=" + emptyProtectionEnabled +
", emptyProtectionExpiredInterval=" + emptyProtectionExpiredInterval +
", reportEnabled=" + reportEnabled +
'}';
}
}

@ -85,6 +85,13 @@
"defaultValue": "./polaris/backup/config",
"description": "Where to load config file, polaris or local."
},
{
"name": "spring.cloud.polaris.config.report.enabled",
"type": "java.lang.Boolean",
"defaultValue": true,
"description": "Whether to report config watch metadata through the Polaris client reporter.",
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
},
{
"name": "spring.cloud.polaris.config.crypto.enabled",
"type": "java.lang.Boolean",

@ -90,6 +90,7 @@ class ConfigurationModifierTest {
void setUp() {
configurationModifier = new ConfigurationModifier(
polarisConfigProperties, polarisCryptoConfigProperties, polarisContextProperties);
Mockito.lenient().when(polarisConfigProperties.isReportEnabled()).thenReturn(true);
}
/**
@ -199,6 +200,21 @@ class ConfigurationModifierTest {
verify(configuration.getConfigFile(), never()).getServerConnector();
}
@DisplayName("modify should disable config watch reporter when configured")
@Test
void testModify_ConfigWatchReportDisabled() {
ConfigurationImpl configuration = buildMockConfiguration();
when(polarisConfigProperties.isReportEnabled()).thenReturn(false);
when(polarisContextProperties.getEnabled()).thenReturn(false);
configurationModifier.modify(configuration);
verify(configWatchReporter).setEnable(false);
verify(configuration.getGlobal().getClientReporter())
.setPluginConfig(ConfigWatchClientReporter.NAME, configWatchReporter);
verify(configuration.getConfigFile(), never()).getServerConnector();
}
/**
* Test modify with local file data source.
* Scenario: dataSource is "localFile", both polaris and config are enabled.

Loading…
Cancel
Save