feat: support config event and monitor address list.

pull/1670/head
fishtailfu 1 month ago
parent d490aeb311
commit a7f4e96556

@ -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<String> 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<String> 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());
// 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 {

@ -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<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");
// PushGatewayPushInterval
polarisStatPushGatewayProperties.setPushGatewayPushInterval(1000L);
assertThat(polarisStatPushGatewayProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000");
polarisStatPushGatewayProperties.setPushInterval(1000L);
assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000");
}
}

Loading…
Cancel
Save