feat: support config event and monitor address list.

pull/1708/head
Fishtail 1 month ago committed by Haotian Zhang
parent 81ac3a54d6
commit 0745ca055b

@ -16,3 +16,4 @@
- [feat: add delay interface in tsf-example.](https://github.com/Tencent/spring-cloud-tencent/pull/1705)
- [fix: fix lb configuration on bootstrap step.](https://github.com/Tencent/spring-cloud-tencent/issues/1706)
- [feat:support fault injection.](https://github.com/Tencent/spring-cloud-tencent/pull/1707)
- [feat: support config event and monitor address list.](https://github.com/Tencent/spring-cloud-tencent/pull/1708)

@ -67,6 +67,18 @@ public final class AddressUtils {
return addressList;
}
public static List<String> parseHostPortList(String addressInfo) {
if (StringUtils.isBlank(addressInfo)) {
return Collections.emptyList();
}
String[] addresses = addressInfo.split(ADDRESS_SEPARATOR);
List<String> addressList = new ArrayList<>();
for (String address : addresses) {
addressList.add(address.trim());
}
return addressList;
}
public static boolean accessible(String ip, int port, int timeout) {
Socket socket = new Socket();
try {

@ -18,6 +18,7 @@
package com.tencent.cloud.polaris.context.event;
import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.polaris.api.config.plugin.DefaultPlugins;
import com.tencent.polaris.factory.config.ConfigurationImpl;
@ -49,7 +50,7 @@ public class PushGatewayEventReporterConfigModifier implements PolarisConfigModi
else {
pushGatewayEventReporterConfig.setEnable(true);
}
pushGatewayEventReporterConfig.setAddress(properties.getAddress());
pushGatewayEventReporterConfig.setAddress(AddressUtils.parseHostPortList(properties.getAddress()));
pushGatewayEventReporterConfig.setEventQueueSize(properties.getEventQueueSize());
pushGatewayEventReporterConfig.setMaxBatchSize(properties.getMaxBatchSize());
pushGatewayEventReporterConfig.setNamespace(properties.getNamespace());

@ -17,6 +17,7 @@
package com.tencent.cloud.polaris.context.event;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@ -33,7 +34,7 @@ public class PushGatewayEventReporterProperties {
private boolean enabled = false;
/**
* Address of pushgateway. For example: 1.2.3.4:9091.
* Address list of pushgateway. For example: 1.2.3.4:9091,1.2.3.4:9092.
*/
private String address;

@ -39,7 +39,7 @@ public class PushGatewayEventReporterConfigModifierTest {
private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class))
.withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091,1.2.3.5:9091")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.namespace=test-namespace")
@ -58,7 +58,8 @@ public class PushGatewayEventReporterConfigModifierTest {
getConfig().getGlobal().getEventReporter()
.getPluginConfig(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE, PushGatewayEventReporterConfig.class);
assertThat(config.isEnable()).isTrue();
assertThat(config.getAddress()).isEqualTo("1.2.3.4:9091");
assertThat(config.getAddress().get(0)).isEqualTo("1.2.3.4:9091");
assertThat(config.getAddress().get(1)).isEqualTo("1.2.3.5:9091");
assertThat(config.getEventQueueSize()).isEqualTo(123);
assertThat(config.getMaxBatchSize()).isEqualTo(456);
assertThat(config.getNamespace()).isEqualTo("test-namespace");

@ -17,6 +17,9 @@
package com.tencent.cloud.polaris.context.event;
import java.util.List;
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration;
import org.junit.jupiter.api.BeforeEach;
@ -37,7 +40,7 @@ public class PushGatewayEventReporterPropertiesTest {
private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class))
.withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091,1.2.3.5:9091")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.namespace=test-namespace")
@ -53,7 +56,9 @@ public class PushGatewayEventReporterPropertiesTest {
this.applicationContextRunner.run(context -> {
PushGatewayEventReporterProperties properties = context.getBean(PushGatewayEventReporterProperties.class);
assertThat(properties.isEnabled()).isTrue();
assertThat(properties.getAddress()).isEqualTo("1.2.3.4:9091");
List<String> addresses = AddressUtils.parseHostPortList(properties.getAddress());
assertThat(addresses.get(0)).isEqualTo("1.2.3.4:9091");
assertThat(addresses.get(1)).isEqualTo("1.2.3.5:9091");
assertThat(properties.getEventQueueSize()).isEqualTo(123);
assertThat(properties.getMaxBatchSize()).isEqualTo(456);
assertThat(properties.getNamespace()).isEqualTo("test-namespace");

@ -18,6 +18,7 @@
package com.tencent.cloud.rpc.enhancement.stat.config;
import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import com.tencent.polaris.factory.config.global.StatReporterConfigImpl;
@ -51,7 +52,7 @@ public class StatConfigModifier implements PolarisConfigModifier {
if (polarisStatProperties.isPushGatewayEnabled()) {
// push gateway
prometheusHandlerConfig.setType("push");
prometheusHandlerConfig.setAddress(polarisStatProperties.getPushGatewayAddress());
prometheusHandlerConfig.setAddress(AddressUtils.parseHostPortList(polarisStatProperties.getPushGatewayAddress()));
prometheusHandlerConfig.setNamespace(polarisStatProperties.getStatNamespace());
prometheusHandlerConfig.setService(polarisStatProperties.getStatService());
prometheusHandlerConfig.setPushInterval(polarisStatProperties.getPushGatewayPushInterval());

@ -17,6 +17,9 @@
package com.tencent.cloud.rpc.enhancement.stat.config;
import java.util.List;
import com.tencent.cloud.common.util.AddressUtils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@ -37,7 +40,7 @@ public class PolarisStatPropertiesTest {
.withPropertyValues("spring.cloud.polaris.stat.enabled=true")
.withPropertyValues("spring.cloud.polaris.stat.path=/xxx")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.address=127.0.0.1:9091")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.address=127.0.0.1:9091, 127.0.0.1:9092")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.namespace=test-namespace")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.service=test-service")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-interval=1000")
@ -52,7 +55,9 @@ public class PolarisStatPropertiesTest {
assertThat(polarisStatProperties.isEnabled()).isTrue();
assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx");
assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue();
assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091");
List<String> addresses = AddressUtils.parseHostPortList(polarisStatProperties.getPushGatewayAddress());
assertThat(addresses.get(0)).isEqualTo("127.0.0.1:9091");
assertThat(addresses.get(1)).isEqualTo("127.0.0.1:9092");
assertThat(polarisStatProperties.getStatNamespace()).isEqualTo("test-namespace");
assertThat(polarisStatProperties.getStatService()).isEqualTo("test-service");
assertThat(polarisStatProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000");
@ -68,8 +73,11 @@ public class PolarisStatPropertiesTest {
assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue();
// PushGatewayAddress
polarisStatProperties.setPushGatewayAddress("127.0.0.1:9091");
assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091");
String pushGatewayAddress = "127.0.0.1:9091, " + "127.0.0.1:9092";
polarisStatProperties.setPushGatewayAddress(pushGatewayAddress);
List<String> addresses = AddressUtils.parseHostPortList(polarisStatProperties.getPushGatewayAddress());
assertThat(addresses.get(0)).isEqualTo("127.0.0.1:9091");
assertThat(addresses.get(1)).isEqualTo("127.0.0.1:9092");
// PushGatewayPushInterval
polarisStatProperties.setPushGatewayPushInterval(1000L);

@ -92,7 +92,7 @@ public class StatConfigModifierTest {
.getGlobal().getStatReporter()
.getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class);
assertThat(prometheusHandlerConfig.getType()).isEqualTo("push");
assertThat(prometheusHandlerConfig.getAddress()).isEqualTo("127.0.0.1:9091");
assertThat(prometheusHandlerConfig.getAddress().get(0)).isEqualTo("127.0.0.1:9091");
assertThat(prometheusHandlerConfig.getPushInterval()).isEqualTo(1000);
assertThat(prometheusHandlerConfig.isOpenGzip()).isTrue();
assertThat(prometheusHandlerConfig.getNamespace()).isEqualTo("test-namespace");

Loading…
Cancel
Save