feat:support stat and event report with service discovery. (#1533)

pull/1554/head
Haotian Zhang 5 months ago committed by GitHub
parent 355716e191
commit d9d830f67d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,3 +12,4 @@
- [fix:fix watch tsf config, fix bean refresh with RefreshScope and ConfigurationProperties.](https://github.com/Tencent/spring-cloud-tencent/pull/1511) - [fix:fix watch tsf config, fix bean refresh with RefreshScope and ConfigurationProperties.](https://github.com/Tencent/spring-cloud-tencent/pull/1511)
- [docs:simplify GitHub Actions.](https://github.com/Tencent/spring-cloud-tencent/pull/1514) - [docs:simplify GitHub Actions.](https://github.com/Tencent/spring-cloud-tencent/pull/1514)
- [feat: support config event.](https://github.com/Tencent/spring-cloud-tencent/pull/1532) - [feat: support config event.](https://github.com/Tencent/spring-cloud-tencent/pull/1532)
- [feat:support stat and event report with service discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1533)

@ -20,7 +20,6 @@ package com.tencent.cloud.polaris.context.event;
import com.tencent.cloud.common.constant.OrderConstant; import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.polaris.context.PolarisConfigModifier; import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.polaris.api.config.plugin.DefaultPlugins; import com.tencent.polaris.api.config.plugin.DefaultPlugins;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.factory.config.ConfigurationImpl; import com.tencent.polaris.factory.config.ConfigurationImpl;
import com.tencent.polaris.plugins.event.pushgateway.PushGatewayEventReporterConfig; import com.tencent.polaris.plugins.event.pushgateway.PushGatewayEventReporterConfig;
@ -43,7 +42,7 @@ public class PushGatewayEventReporterConfigModifier implements PolarisConfigModi
.add(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE); .add(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE);
PushGatewayEventReporterConfig pushGatewayEventReporterConfig = new PushGatewayEventReporterConfig(); PushGatewayEventReporterConfig pushGatewayEventReporterConfig = new PushGatewayEventReporterConfig();
if (!properties.isEnabled() || StringUtils.isBlank(properties.getAddress())) { if (!properties.isEnabled()) {
pushGatewayEventReporterConfig.setEnable(false); pushGatewayEventReporterConfig.setEnable(false);
return; return;
} }
@ -53,6 +52,8 @@ public class PushGatewayEventReporterConfigModifier implements PolarisConfigModi
pushGatewayEventReporterConfig.setAddress(properties.getAddress()); pushGatewayEventReporterConfig.setAddress(properties.getAddress());
pushGatewayEventReporterConfig.setEventQueueSize(properties.getEventQueueSize()); pushGatewayEventReporterConfig.setEventQueueSize(properties.getEventQueueSize());
pushGatewayEventReporterConfig.setMaxBatchSize(properties.getMaxBatchSize()); pushGatewayEventReporterConfig.setMaxBatchSize(properties.getMaxBatchSize());
pushGatewayEventReporterConfig.setNamespace(properties.getNamespace());
pushGatewayEventReporterConfig.setService(properties.getService());
configuration.getGlobal().getEventReporter() configuration.getGlobal().getEventReporter()
.setPluginConfig(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE, pushGatewayEventReporterConfig); .setPluginConfig(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE, pushGatewayEventReporterConfig);

@ -47,6 +47,16 @@ public class PushGatewayEventReporterProperties {
*/ */
private int maxBatchSize = 100; private int maxBatchSize = 100;
/**
* Namespace for push gateway event. Default is Polaris.
*/
private String namespace = "Polaris";
/**
* Service for push gateway event. Default is polaris.pushgateway.
*/
private String service = "polaris.pushgateway";
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
@ -79,6 +89,22 @@ public class PushGatewayEventReporterProperties {
this.maxBatchSize = maxBatchSize; this.maxBatchSize = maxBatchSize;
} }
public String getNamespace() {
return namespace;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
@Override @Override
public String toString() { public String toString() {
return "PushGatewayEventReporterProperties{" + return "PushGatewayEventReporterProperties{" +
@ -86,6 +112,8 @@ public class PushGatewayEventReporterProperties {
", address='" + address + '\'' + ", address='" + address + '\'' +
", eventQueueSize=" + eventQueueSize + ", eventQueueSize=" + eventQueueSize +
", maxBatchSize=" + maxBatchSize + ", maxBatchSize=" + maxBatchSize +
", namespace='" + namespace + '\'' +
", service='" + service + '\'' +
'}'; '}';
} }
} }

@ -74,6 +74,18 @@
"type": "java.lang.Integer", "type": "java.lang.Integer",
"description": "Max batch size for push gateway event. Default is 100.", "description": "Max batch size for push gateway event. Default is 100.",
"default": 100 "default": 100
},
{
"name": "spring.cloud.polaris.event.pushgateway.namespace",
"type": "java.lang.String",
"description": "Namespace for push gateway event. Default is Polaris.",
"defaultValue": "Polaris"
},
{
"name": "spring.cloud.polaris.event.pushgateway.service",
"type": "java.lang.String",
"description": "Service for push gateway event. Default is polaris.pushgateway.",
"defaultValue": "polaris.pushgateway"
} }
], ],
"hints": [] "hints": []

@ -41,7 +41,9 @@ public class PushGatewayEventReporterConfigModifierTest {
.withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true") .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")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123") .withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456"); .withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.namespace=test-namespace")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.service=test-service");
@BeforeEach @BeforeEach
void setUp() { void setUp() {
@ -59,6 +61,8 @@ public class PushGatewayEventReporterConfigModifierTest {
assertThat(config.getAddress()).isEqualTo("1.2.3.4:9091"); assertThat(config.getAddress()).isEqualTo("1.2.3.4:9091");
assertThat(config.getEventQueueSize()).isEqualTo(123); assertThat(config.getEventQueueSize()).isEqualTo(123);
assertThat(config.getMaxBatchSize()).isEqualTo(456); assertThat(config.getMaxBatchSize()).isEqualTo(456);
assertThat(config.getNamespace()).isEqualTo("test-namespace");
assertThat(config.getService()).isEqualTo("test-service");
}); });
} }
} }

@ -39,7 +39,9 @@ public class PushGatewayEventReporterPropertiesTest {
.withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true") .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")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123") .withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456"); .withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.namespace=test-namespace")
.withPropertyValues("spring.cloud.polaris.event.pushgateway.service=test-service");
@BeforeEach @BeforeEach
void setUp() { void setUp() {
@ -54,6 +56,8 @@ public class PushGatewayEventReporterPropertiesTest {
assertThat(properties.getAddress()).isEqualTo("1.2.3.4:9091"); assertThat(properties.getAddress()).isEqualTo("1.2.3.4:9091");
assertThat(properties.getEventQueueSize()).isEqualTo(123); assertThat(properties.getEventQueueSize()).isEqualTo(123);
assertThat(properties.getMaxBatchSize()).isEqualTo(456); assertThat(properties.getMaxBatchSize()).isEqualTo(456);
assertThat(properties.getNamespace()).isEqualTo("test-namespace");
assertThat(properties.getService()).isEqualTo("test-service");
}); });
} }
} }

@ -50,6 +50,18 @@ public class PolarisStatProperties {
@Value("${spring.cloud.polaris.stat.pushgateway.address:}") @Value("${spring.cloud.polaris.stat.pushgateway.address:}")
private String pushGatewayAddress; private String pushGatewayAddress;
/**
* PushGateway namespace.
*/
@Value("${spring.cloud.polaris.stat.pushgateway.namespace:Polaris}")
private String statNamespace = "Polaris";
/**
* PushGateway service.
*/
@Value("${spring.cloud.polaris.stat.pushgateway.service:polaris.pushgateway}")
private String statService = "polaris.pushgateway";
/** /**
* Push metrics interval. * Push metrics interval.
* unit: milliseconds default 60s. * unit: milliseconds default 60s.
@ -95,6 +107,22 @@ public class PolarisStatProperties {
this.pushGatewayAddress = pushGatewayAddress; this.pushGatewayAddress = pushGatewayAddress;
} }
public String getStatNamespace() {
return statNamespace;
}
public void setStatNamespace(String statNamespace) {
this.statNamespace = statNamespace;
}
public String getStatService() {
return statService;
}
public void setStatService(String statService) {
this.statService = statService;
}
public Long getPushGatewayPushInterval() { public Long getPushGatewayPushInterval() {
return pushGatewayPushInterval; return pushGatewayPushInterval;
} }
@ -110,4 +138,18 @@ public class PolarisStatProperties {
public void setOpenGzip(Boolean openGzip) { public void setOpenGzip(Boolean openGzip) {
this.openGzip = openGzip; this.openGzip = openGzip;
} }
@Override
public String toString() {
return "PolarisStatProperties{" +
"enabled=" + enabled +
", path='" + path + '\'' +
", pushGatewayEnabled=" + pushGatewayEnabled +
", pushGatewayAddress='" + pushGatewayAddress + '\'' +
", statNamespace='" + statNamespace + '\'' +
", statService='" + statService + '\'' +
", pushGatewayPushInterval=" + pushGatewayPushInterval +
", openGzip=" + openGzip +
'}';
}
} }

@ -51,6 +51,8 @@ public class StatConfigModifier implements PolarisConfigModifier {
// push gateway // push gateway
prometheusHandlerConfig.setType("push"); prometheusHandlerConfig.setType("push");
prometheusHandlerConfig.setAddress(polarisStatProperties.getPushGatewayAddress()); prometheusHandlerConfig.setAddress(polarisStatProperties.getPushGatewayAddress());
prometheusHandlerConfig.setNamespace(polarisStatProperties.getStatNamespace());
prometheusHandlerConfig.setService(polarisStatProperties.getStatService());
prometheusHandlerConfig.setPushInterval(polarisStatProperties.getPushGatewayPushInterval()); prometheusHandlerConfig.setPushInterval(polarisStatProperties.getPushGatewayPushInterval());
prometheusHandlerConfig.setOpenGzip(polarisStatProperties.getOpenGzip()); prometheusHandlerConfig.setOpenGzip(polarisStatProperties.getOpenGzip());
} }

@ -79,6 +79,18 @@
"description": "If push gateway gzip open. default false.", "description": "If push gateway gzip open. default false.",
"sourceType": "com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties", "sourceType": "com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties",
"defaultValue": false "defaultValue": false
},
{
"name": "spring.cloud.polaris.stat.pushgateway.namespace",
"type": "java.lang.String",
"description": "PushGateway namespace.",
"defaultValue": "Polaris"
},
{
"name": "spring.cloud.polaris.stat.pushgateway.service",
"type": "java.lang.String",
"description": "PushGateway service.",
"defaultValue": "polaris.pushgateway"
} }
] ]
} }

@ -38,6 +38,8 @@ public class PolarisStatPropertiesTest {
.withPropertyValues("spring.cloud.polaris.stat.path=/xxx") .withPropertyValues("spring.cloud.polaris.stat.path=/xxx")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.enabled=true") .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")
.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") .withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-interval=1000")
.withPropertyValues("spring.cloud.gateway.enabled=false"); .withPropertyValues("spring.cloud.gateway.enabled=false");
@ -51,6 +53,8 @@ public class PolarisStatPropertiesTest {
assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx"); assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx");
assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue(); assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue();
assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091"); assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091");
assertThat(polarisStatProperties.getStatNamespace()).isEqualTo("test-namespace");
assertThat(polarisStatProperties.getStatService()).isEqualTo("test-service");
assertThat(polarisStatProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); assertThat(polarisStatProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000");
}); });
} }

@ -55,6 +55,8 @@ public class StatConfigModifierTest {
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.address=127.0.0.1:9091") .withPropertyValues("spring.cloud.polaris.stat.pushgateway.address=127.0.0.1:9091")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-interval=1000") .withPropertyValues("spring.cloud.polaris.stat.pushgateway.push-interval=1000")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.open-gzip=true") .withPropertyValues("spring.cloud.polaris.stat.pushgateway.open-gzip=true")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.namespace=test-namespace")
.withPropertyValues("spring.cloud.polaris.stat.pushgateway.service=test-service")
.withPropertyValues("spring.application.name=test") .withPropertyValues("spring.application.name=test")
.withPropertyValues("spring.cloud.gateway.enabled=false"); .withPropertyValues("spring.cloud.gateway.enabled=false");
@ -93,6 +95,8 @@ public class StatConfigModifierTest {
assertThat(prometheusHandlerConfig.getAddress()).isEqualTo("127.0.0.1:9091"); assertThat(prometheusHandlerConfig.getAddress()).isEqualTo("127.0.0.1:9091");
assertThat(prometheusHandlerConfig.getPushInterval()).isEqualTo(1000); assertThat(prometheusHandlerConfig.getPushInterval()).isEqualTo(1000);
assertThat(prometheusHandlerConfig.isOpenGzip()).isTrue(); assertThat(prometheusHandlerConfig.isOpenGzip()).isTrue();
assertThat(prometheusHandlerConfig.getNamespace()).isEqualTo("test-namespace");
assertThat(prometheusHandlerConfig.getService()).isEqualTo("test-service");
}); });
} }

Loading…
Cancel
Save