feat: support config event and monitor address list.

pull/1670/head
fishtailfu 2 months ago
parent d490aeb311
commit a7f4e96556

@ -15,66 +15,61 @@ public class PolarisStatPushGatewayProperties {
/** /**
* If state pushGateway reporter enabled. * If state pushGateway reporter enabled.
*/ */
@Value("${spring.cloud.polaris.stat.pushgateway.enabled:#{false}}") private boolean enabled = false;
private boolean pushGatewayEnabled = false;
/** /**
* PushGateway namespace. * PushGateway namespace.
*/ */
@Value("${spring.cloud.polaris.stat.pushgateway.namespace:Polaris}") private String namespace = "Polaris";
private String statNamespace = "Polaris";
/** /**
* PushGateway service. * PushGateway service.
*/ */
@Value("${spring.cloud.polaris.stat.pushgateway.service:polaris.pushgateway}") private String service = "polaris.pushgateway";
private String statService = "polaris.pushgateway";
/** /**
* Push metrics interval. * Push metrics interval.
* unit: milliseconds default 60s. * unit: milliseconds default 60s.
*/ */
@Value("${spring.cloud.polaris.stat.pushgateway.push-interval:#{60000}}") private Long pushInterval = 60 * 1000L;
private Long pushGatewayPushInterval = 60 * 1000L;
/** /**
* If push gateway gzip open. default false. * If push gateway gzip open. default false.
*/ */
@Value("${spring.cloud.polaris.stat.pushgateway.open-gzip:#{false}}")
private Boolean openGzip = false; private Boolean openGzip = false;
private List<String> address; private List<String> address;
boolean isPushGatewayEnabled() { boolean isEnabled() {
return pushGatewayEnabled; return enabled;
} }
void setPushGatewayEnabled(boolean pushGatewayEnabled) { void setEnabled(boolean enabled) {
this.pushGatewayEnabled = pushGatewayEnabled; this.enabled = enabled;
} }
String getStatNamespace() { String getNamespace() {
return statNamespace; return namespace;
} }
void setStatNamespace(String statNamespace) { void setNamespace(String namespace) {
this.statNamespace = statNamespace; this.namespace = namespace;
} }
String getStatService() { String getService() {
return statService; return service;
} }
void setStatService(String statService) { void setService(String service) {
this.statService = statService; this.service = service;
} }
Long getPushGatewayPushInterval() { Long getPushInterval() {
return pushGatewayPushInterval; return pushInterval;
} }
void setPushGatewayPushInterval(Long pushGatewayPushInterval) { void setPushInterval(Long pushInterval) {
this.pushGatewayPushInterval = pushGatewayPushInterval; this.pushInterval = pushInterval;
} }
Boolean getOpenGzip() { Boolean getOpenGzip() {
@ -92,4 +87,16 @@ public class PolarisStatPushGatewayProperties {
void setAddress(List<String> address) { void setAddress(List<String> address) {
this.address = address; this.address = address;
} }
@Override
public String toString() {
return "PolarisStatPushGatewayProperties{" +
"enabled=" + enabled +
", namespace='" + namespace + '\'' +
", service='" + service + '\'' +
", pushInterval=" + pushInterval +
", openGzip=" + openGzip +
", address=" + address +
'}';
}
} }

@ -51,13 +51,13 @@ public class StatConfigModifier implements PolarisConfigModifier {
prometheusHandlerConfig.setPathRegexList(polarisStatProperties.getPathRegexList()); prometheusHandlerConfig.setPathRegexList(polarisStatProperties.getPathRegexList());
// Set prometheus plugin. // Set prometheus plugin.
if (polarisStatProperties.isEnabled()) { if (polarisStatProperties.isEnabled()) {
if (polarisStatPushGatewayProperties.isPushGatewayEnabled()) { if (polarisStatPushGatewayProperties.isEnabled()) {
// push gateway // push gateway
prometheusHandlerConfig.setType("push"); prometheusHandlerConfig.setType("push");
prometheusHandlerConfig.setAddress(polarisStatPushGatewayProperties.getAddress()); prometheusHandlerConfig.setAddress(polarisStatPushGatewayProperties.getAddress());
prometheusHandlerConfig.setNamespace(polarisStatPushGatewayProperties.getStatNamespace()); prometheusHandlerConfig.setNamespace(polarisStatPushGatewayProperties.getNamespace());
prometheusHandlerConfig.setService(polarisStatPushGatewayProperties.getStatService()); prometheusHandlerConfig.setService(polarisStatPushGatewayProperties.getService());
prometheusHandlerConfig.setPushInterval(polarisStatPushGatewayProperties.getPushGatewayPushInterval()); prometheusHandlerConfig.setPushInterval(polarisStatPushGatewayProperties.getPushInterval());
prometheusHandlerConfig.setOpenGzip(polarisStatPushGatewayProperties.getOpenGzip()); prometheusHandlerConfig.setOpenGzip(polarisStatPushGatewayProperties.getOpenGzip());
} }
else { else {

@ -53,12 +53,12 @@ public class PolarisStatPropertiesTest {
assertThat(polarisStatProperties).isNotNull(); assertThat(polarisStatProperties).isNotNull();
assertThat(polarisStatProperties.isEnabled()).isTrue(); assertThat(polarisStatProperties.isEnabled()).isTrue();
assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx"); 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(0)).isEqualTo("127.0.0.1:9091");
assertThat(polarisStatPushGatewayProperties.getAddress().get(1)).isEqualTo("127.0.0.1:9092"); assertThat(polarisStatPushGatewayProperties.getAddress().get(1)).isEqualTo("127.0.0.1:9092");
assertThat(polarisStatPushGatewayProperties.getStatNamespace()).isEqualTo("test-namespace"); assertThat(polarisStatPushGatewayProperties.getNamespace()).isEqualTo("test-namespace");
assertThat(polarisStatPushGatewayProperties.getStatService()).isEqualTo("test-service"); assertThat(polarisStatPushGatewayProperties.getService()).isEqualTo("test-service");
assertThat(polarisStatPushGatewayProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000");
}); });
} }
@ -67,8 +67,8 @@ public class PolarisStatPropertiesTest {
PolarisStatProperties polarisStatProperties = new PolarisStatProperties(); PolarisStatProperties polarisStatProperties = new PolarisStatProperties();
PolarisStatPushGatewayProperties polarisStatPushGatewayProperties = new PolarisStatPushGatewayProperties(); PolarisStatPushGatewayProperties polarisStatPushGatewayProperties = new PolarisStatPushGatewayProperties();
// PushGatewayEnabled // PushGatewayEnabled
polarisStatPushGatewayProperties.setPushGatewayEnabled(true); polarisStatPushGatewayProperties.setEnabled(true);
assertThat(polarisStatPushGatewayProperties.isPushGatewayEnabled()).isTrue(); assertThat(polarisStatPushGatewayProperties.isEnabled()).isTrue();
// PushGatewayAddress // PushGatewayAddress
List<String> pushGatewayAddress = List.of("127.0.0.1:9091", "127.0.0.1:9092"); List<String> 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"); assertThat(polarisStatPushGatewayProperties.getAddress().get(1)).isEqualTo("127.0.0.1:9092");
// PushGatewayPushInterval // PushGatewayPushInterval
polarisStatPushGatewayProperties.setPushGatewayPushInterval(1000L); polarisStatPushGatewayProperties.setPushInterval(1000L);
assertThat(polarisStatPushGatewayProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000");
} }
} }

Loading…
Cancel
Save