From a7f4e965566b62fe13a8bdefe67872cd881901cb Mon Sep 17 00:00:00 2001 From: fishtailfu Date: Thu, 24 Jul 2025 14:29:50 +0800 Subject: [PATCH] feat: support config event and monitor address list. --- .../PolarisStatPushGatewayProperties.java | 57 +++++++++++-------- .../stat/config/StatConfigModifier.java | 8 +-- .../config/PolarisStatPropertiesTest.java | 16 +++--- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPushGatewayProperties.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPushGatewayProperties.java index 14dcc3aa8..d98dab171 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPushGatewayProperties.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPushGatewayProperties.java @@ -15,66 +15,61 @@ public class PolarisStatPushGatewayProperties { /** * If state pushGateway reporter enabled. */ - @Value("${spring.cloud.polaris.stat.pushgateway.enabled:#{false}}") - private boolean pushGatewayEnabled = false; + private boolean enabled = false; /** * PushGateway namespace. */ - @Value("${spring.cloud.polaris.stat.pushgateway.namespace:Polaris}") - private String statNamespace = "Polaris"; + private String namespace = "Polaris"; /** * PushGateway service. */ - @Value("${spring.cloud.polaris.stat.pushgateway.service:polaris.pushgateway}") - private String statService = "polaris.pushgateway"; + private String service = "polaris.pushgateway"; /** * Push metrics interval. * unit: milliseconds default 60s. */ - @Value("${spring.cloud.polaris.stat.pushgateway.push-interval:#{60000}}") - private Long pushGatewayPushInterval = 60 * 1000L; + private Long pushInterval = 60 * 1000L; /** * If push gateway gzip open. default false. */ - @Value("${spring.cloud.polaris.stat.pushgateway.open-gzip:#{false}}") private Boolean openGzip = false; private List address; - boolean isPushGatewayEnabled() { - return pushGatewayEnabled; + boolean isEnabled() { + return enabled; } - void setPushGatewayEnabled(boolean pushGatewayEnabled) { - this.pushGatewayEnabled = pushGatewayEnabled; + void setEnabled(boolean enabled) { + this.enabled = enabled; } - String getStatNamespace() { - return statNamespace; + String getNamespace() { + return namespace; } - void setStatNamespace(String statNamespace) { - this.statNamespace = statNamespace; + void setNamespace(String namespace) { + this.namespace = namespace; } - String getStatService() { - return statService; + String getService() { + return service; } - void setStatService(String statService) { - this.statService = statService; + void setService(String service) { + this.service = service; } - Long getPushGatewayPushInterval() { - return pushGatewayPushInterval; + Long getPushInterval() { + return pushInterval; } - void setPushGatewayPushInterval(Long pushGatewayPushInterval) { - this.pushGatewayPushInterval = pushGatewayPushInterval; + void setPushInterval(Long pushInterval) { + this.pushInterval = pushInterval; } Boolean getOpenGzip() { @@ -92,4 +87,16 @@ public class PolarisStatPushGatewayProperties { void setAddress(List address) { this.address = address; } + + @Override + public String toString() { + return "PolarisStatPushGatewayProperties{" + + "enabled=" + enabled + + ", namespace='" + namespace + '\'' + + ", service='" + service + '\'' + + ", pushInterval=" + pushInterval + + ", openGzip=" + openGzip + + ", address=" + address + + '}'; + } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifier.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifier.java index 4b36cc14a..715215bc8 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifier.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifier.java @@ -51,13 +51,13 @@ public class StatConfigModifier implements PolarisConfigModifier { prometheusHandlerConfig.setPathRegexList(polarisStatProperties.getPathRegexList()); // Set prometheus plugin. if (polarisStatProperties.isEnabled()) { - if (polarisStatPushGatewayProperties.isPushGatewayEnabled()) { + if (polarisStatPushGatewayProperties.isEnabled()) { // push gateway prometheusHandlerConfig.setType("push"); prometheusHandlerConfig.setAddress(polarisStatPushGatewayProperties.getAddress()); - prometheusHandlerConfig.setNamespace(polarisStatPushGatewayProperties.getStatNamespace()); - prometheusHandlerConfig.setService(polarisStatPushGatewayProperties.getStatService()); - prometheusHandlerConfig.setPushInterval(polarisStatPushGatewayProperties.getPushGatewayPushInterval()); + prometheusHandlerConfig.setNamespace(polarisStatPushGatewayProperties.getNamespace()); + prometheusHandlerConfig.setService(polarisStatPushGatewayProperties.getService()); + prometheusHandlerConfig.setPushInterval(polarisStatPushGatewayProperties.getPushInterval()); prometheusHandlerConfig.setOpenGzip(polarisStatPushGatewayProperties.getOpenGzip()); } else { diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesTest.java index 4fd4c4491..3226285db 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesTest.java @@ -53,12 +53,12 @@ public class PolarisStatPropertiesTest { assertThat(polarisStatProperties).isNotNull(); assertThat(polarisStatProperties.isEnabled()).isTrue(); assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx"); - assertThat(polarisStatPushGatewayProperties.isPushGatewayEnabled()).isTrue(); + assertThat(polarisStatPushGatewayProperties.isEnabled()).isTrue(); assertThat(polarisStatPushGatewayProperties.getAddress().get(0)).isEqualTo("127.0.0.1:9091"); assertThat(polarisStatPushGatewayProperties.getAddress().get(1)).isEqualTo("127.0.0.1:9092"); - assertThat(polarisStatPushGatewayProperties.getStatNamespace()).isEqualTo("test-namespace"); - assertThat(polarisStatPushGatewayProperties.getStatService()).isEqualTo("test-service"); - assertThat(polarisStatPushGatewayProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); + assertThat(polarisStatPushGatewayProperties.getNamespace()).isEqualTo("test-namespace"); + assertThat(polarisStatPushGatewayProperties.getService()).isEqualTo("test-service"); + assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000"); }); } @@ -67,8 +67,8 @@ public class PolarisStatPropertiesTest { PolarisStatProperties polarisStatProperties = new PolarisStatProperties(); PolarisStatPushGatewayProperties polarisStatPushGatewayProperties = new PolarisStatPushGatewayProperties(); // PushGatewayEnabled - polarisStatPushGatewayProperties.setPushGatewayEnabled(true); - assertThat(polarisStatPushGatewayProperties.isPushGatewayEnabled()).isTrue(); + polarisStatPushGatewayProperties.setEnabled(true); + assertThat(polarisStatPushGatewayProperties.isEnabled()).isTrue(); // PushGatewayAddress List pushGatewayAddress = List.of("127.0.0.1:9091", "127.0.0.1:9092"); @@ -77,7 +77,7 @@ public class PolarisStatPropertiesTest { assertThat(polarisStatPushGatewayProperties.getAddress().get(1)).isEqualTo("127.0.0.1:9092"); // PushGatewayPushInterval - polarisStatPushGatewayProperties.setPushGatewayPushInterval(1000L); - assertThat(polarisStatPushGatewayProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); + polarisStatPushGatewayProperties.setPushInterval(1000L); + assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000"); } }