From d46c1d2f230f1fc77367f1c926317f7f8335ab2c Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Fri, 3 Mar 2023 16:51:09 +0800 Subject: [PATCH] refactor:refactor stat module. (#876) --- CHANGELOG.md | 1 + spring-cloud-starter-tencent-all/pom.xml | 5 - spring-cloud-tencent-coverage/pom.xml | 5 - spring-cloud-tencent-dependencies/pom.xml | 8 +- .../discovery-caller-service/pom.xml | 4 - spring-cloud-tencent-plugin-starters/pom.xml | 5 +- .../pom.xml | 33 ------- ...larisStatPushGatewayAutoConfiguration.java | 42 -------- ...StatPushGatewayBootstrapConfiguration.java | 31 ------ .../PolarisStatPushGatewayModifier.java | 70 ------------- .../PolarisStatPushGatewayProperties.java | 69 ------------- ...itional-spring-configuration-metadata.json | 23 ----- .../main/resources/META-INF/spring.factories | 4 - ...sStatPushGatewayAutoConfigurationTest.java | 49 ---------- ...PushGatewayBootstrapConfigurationTest.java | 47 --------- .../PolarisStatPushGatewayPropertiesTest.java | 51 ---------- .../stat/config/PolarisStatProperties.java | 44 +++++++++ .../stat/config/StatConfigModifier.java | 35 ++++--- ...itional-spring-configuration-metadata.json | 19 ++++ .../RpcEnhancementReporterPropertiesTest.java | 2 +- .../PolarisStatPropertiesDisableTest.java | 55 ----------- .../config/PolarisStatPropertiesTest.java | 56 +++++++---- .../stat/config/StatConfigModifierTest.java | 98 +++++++++++++++++++ .../resources/application-disable.properties | 8 -- .../resources/application-test.properties | 8 +- 25 files changed, 230 insertions(+), 542 deletions(-) delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfiguration.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayModifier.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayProperties.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/additional-spring-configuration-metadata.json delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/spring.factories delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java delete mode 100644 spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java delete mode 100644 spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesDisableTest.java create mode 100644 spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifierTest.java delete mode 100644 spring-cloud-tencent-rpc-enhancement/src/test/resources/application-disable.properties diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b696927b..c1f85bb12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,4 @@ - [optimize:optimize ServiceRuleManager.](https://github.com/Tencent/spring-cloud-tencent/pull/869) - [refactor:update to junit 5.](https://github.com/Tencent/spring-cloud-tencent/pull/865) - [docs:support auto snapshot release in GitHub Action.](https://github.com/Tencent/spring-cloud-tencent/pull/868) +- [refactor:refactor stat module.](https://github.com/Tencent/spring-cloud-tencent/pull/876) diff --git a/spring-cloud-starter-tencent-all/pom.xml b/spring-cloud-starter-tencent-all/pom.xml index 1aaa8bbc7..e5c54f51a 100644 --- a/spring-cloud-starter-tencent-all/pom.xml +++ b/spring-cloud-starter-tencent-all/pom.xml @@ -46,11 +46,6 @@ spring-cloud-starter-tencent-metadata-transfer - - com.tencent.cloud - spring-cloud-tencent-pushgateway-plugin - - org.springframework.cloud diff --git a/spring-cloud-tencent-coverage/pom.xml b/spring-cloud-tencent-coverage/pom.xml index 9f8a67c7f..7a566190e 100644 --- a/spring-cloud-tencent-coverage/pom.xml +++ b/spring-cloud-tencent-coverage/pom.xml @@ -73,11 +73,6 @@ com.tencent.cloud spring-cloud-tencent-gateway-plugin - - - com.tencent.cloud - spring-cloud-tencent-pushgateway-plugin - diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 2195ddd6c..b3de2d581 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -73,7 +73,7 @@ 1.10.0-2021.0.6-SNAPSHOT - 1.11.0-SNAPSHOT + 1.11.0 31.0.1-jre 1.2.11 4.5.1 @@ -174,12 +174,6 @@ ${revision} - - com.tencent.cloud - spring-cloud-tencent-pushgateway-plugin - ${revision} - - com.google.guava diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml index 272490945..1d370e7f5 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/pom.xml @@ -28,10 +28,6 @@ spring-cloud-starter-tencent-polaris-discovery - - com.tencent.cloud - spring-cloud-tencent-pushgateway-plugin - diff --git a/spring-cloud-tencent-plugin-starters/pom.xml b/spring-cloud-tencent-plugin-starters/pom.xml index cba7562ec..6487f9a89 100644 --- a/spring-cloud-tencent-plugin-starters/pom.xml +++ b/spring-cloud-tencent-plugin-starters/pom.xml @@ -1,6 +1,6 @@ - spring-cloud-tencent @@ -17,7 +17,6 @@ spring-cloud-tencent-featureenv-plugin spring-cloud-tencent-gateway-plugin - spring-cloud-tencent-pushgateway-plugin diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml deleted file mode 100644 index 22a80c0f2..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - spring-cloud-tencent-plugin-starters - com.tencent.cloud - ${revision} - ../pom.xml - - 4.0.0 - - spring-cloud-tencent-pushgateway-plugin - - - - com.tencent.cloud - spring-cloud-tencent-polaris-context - - - - com.tencent.polaris - stat-pushgateway - 1.10.5 - - - - org.springframework.boot - spring-boot-starter-test - test - - - \ No newline at end of file diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java deleted file mode 100644 index 1ef1c3853..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -/** - * @author lingxiao.wlx - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnPolarisEnabled -@EnableConfigurationProperties(PolarisStatPushGatewayProperties.class) -public class PolarisStatPushGatewayAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public PolarisStatPushGatewayModifier polarisStatPushGatewayModifier(PolarisStatPushGatewayProperties polarisStatPushGatewayProperties, - Environment environment) { - return new PolarisStatPushGatewayModifier(polarisStatPushGatewayProperties, environment); - } -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfiguration.java deleted file mode 100644 index 67c336613..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfiguration.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * @author lingxiao.wlx - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnProperty("spring.cloud.polaris.enabled") -@Import(PolarisStatPushGatewayAutoConfiguration.class) -public class PolarisStatPushGatewayBootstrapConfiguration { -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayModifier.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayModifier.java deleted file mode 100644 index b680c53c0..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayModifier.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import com.tencent.cloud.common.constant.ContextConstant; -import com.tencent.cloud.polaris.context.PolarisConfigModifier; -import com.tencent.polaris.factory.config.ConfigurationImpl; -import com.tencent.polaris.plugins.stat.pushgateway.handler.PrometheusPushHandlerConfig; - -import org.springframework.core.env.Environment; - -/** - * @author lingxiao.wlx - */ -public class PolarisStatPushGatewayModifier implements PolarisConfigModifier { - - private static final String POLARIS_STAT_ENABLED = "spring.cloud.polaris.stat.enabled"; - - private static final String PROMETHEUS_PUSH_GATEWAY_PLUGIN_NAME = "prometheus-pushgateway"; - - private final PolarisStatPushGatewayProperties polarisStatPushGatewayProperties; - - private final Environment environment; - - public PolarisStatPushGatewayModifier(PolarisStatPushGatewayProperties polarisStatPushGatewayProperties, - Environment environment) { - this.polarisStatPushGatewayProperties = polarisStatPushGatewayProperties; - this.environment = environment; - } - - @Override - public void modify(ConfigurationImpl configuration) { - // Turn on stat reporter configuration. - Boolean statEnabled = environment.getProperty(POLARIS_STAT_ENABLED, Boolean.class, false); - if (!statEnabled) { - configuration.getGlobal().getStatReporter().setEnable(polarisStatPushGatewayProperties.isEnabled()); - } - - // Set prometheus plugin. - if (polarisStatPushGatewayProperties.isEnabled()) { - PrometheusPushHandlerConfig prometheusHandlerConfig = configuration.getGlobal().getStatReporter() - .getPluginConfig(PROMETHEUS_PUSH_GATEWAY_PLUGIN_NAME, PrometheusPushHandlerConfig.class); - prometheusHandlerConfig.setPushgatewayAddress(polarisStatPushGatewayProperties.getAddress()); - prometheusHandlerConfig.setPushInterval(polarisStatPushGatewayProperties.getPushInterval()); - configuration.getGlobal().getStatReporter() - .setPluginConfig(PROMETHEUS_PUSH_GATEWAY_PLUGIN_NAME, prometheusHandlerConfig); - } - } - - @Override - public int getOrder() { - // run after prometheus stat reporter. - return ContextConstant.ModifierOrder.STAT_REPORTER_ORDER + 1; - } -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayProperties.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayProperties.java deleted file mode 100644 index 7b6f681c2..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayProperties.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * The properties for stat pushGateway reporter. - * - * @author lingxiao.wlx - */ -@ConfigurationProperties("spring.cloud.polaris.stat.pushgateway") -public class PolarisStatPushGatewayProperties { - - /** - * If state pushGateway reporter enabled. - */ - private boolean enabled = false; - - /** - * PushGateway address. - */ - private String address; - - /** - * Push metrics interval. - * unit: milliseconds default 30s. - */ - private Long pushInterval = 30 * 1000L; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public Long getPushInterval() { - return pushInterval; - } - - public void setPushInterval(Long pushInterval) { - this.pushInterval = pushInterval; - } -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 2976dc70f..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "properties": [ - { - "name": "spring.cloud.polaris.stat.pushgateway.address", - "type": "java.lang.String", - "description": "PushGateway address.", - "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties" - }, - { - "name": "spring.cloud.polaris.stat.pushgateway.enabled", - "type": "java.lang.Boolean", - "description": "If state pushGateway reporter enabled.", - "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties", - "defaultValue": false - }, - { - "name": "spring.cloud.polaris.stat.pushgateway.push-interval", - "type": "java.lang.Long", - "description": "Push metrics interval. unit: milliseconds default 30s.", - "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties" - } - ] -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 468a15060..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,4 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayAutoConfiguration -org.springframework.cloud.bootstrap.BootstrapConfiguration=\ - com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayBootstrapConfiguration diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java deleted file mode 100644 index b6d09d6ff..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayAutoConfigurationTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.Assertions.assertThat; - - -/** - * Test for {@link PolarisStatPushGatewayAutoConfiguration}. - * - * @author lingxiao.wlx - */ -public class PolarisStatPushGatewayAutoConfigurationTest { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of( - PolarisContextAutoConfiguration.class, - PolarisStatPushGatewayAutoConfiguration.class)); - - @Test - public void testDefaultInitialization() { - this.contextRunner.run(context -> { - assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); - assertThat(context).hasSingleBean(PolarisStatPushGatewayModifier.class); - assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); - }); - } -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java deleted file mode 100644 index bb332d945..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayBootstrapConfigurationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.plugin.pushgateway; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Test for {@link PolarisStatPushGatewayBootstrapConfiguration}. - * - * @author lingxiao.wlx - */ -public class PolarisStatPushGatewayBootstrapConfigurationTest { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(PolarisStatPushGatewayBootstrapConfiguration.class)) - .withPropertyValues("spring.cloud.polaris.enabled=true"); - - @Test - public void testDefaultInitialization() { - this.contextRunner.run(context -> { - assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); - assertThat(context).hasSingleBean(PolarisStatPushGatewayModifier.class); - assertThat(context).hasSingleBean(PolarisStatPushGatewayProperties.class); - assertThat(context).hasSingleBean(PolarisStatPushGatewayBootstrapConfiguration.class); - }); - } -} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java deleted file mode 100644 index 52d14ad86..000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-pushgateway-plugin/src/test/java/com/tencent/cloud/plugin/pushgateway/PolarisStatPushGatewayPropertiesTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - */ - -package com.tencent.cloud.plugin.pushgateway; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Test for {@link PolarisStatPushGatewayProperties}. - * - * @author lingxiao.wlx - */ -public class PolarisStatPushGatewayPropertiesTest { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(PolarisStatPushGatewayBootstrapConfiguration.class)) - .withPropertyValues("spring.cloud.polaris.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.push-interval=1000"); - - @Test - public void polarisStatPushGatewayPropertiesTest() { - contextRunner.run(context -> { - PolarisStatPushGatewayProperties polarisStatPushGatewayProperties = context.getBean(PolarisStatPushGatewayProperties.class); - assertThat(polarisStatPushGatewayProperties.isEnabled()).isTrue(); - assertThat(polarisStatPushGatewayProperties.getAddress()).isEqualTo("127.0.0.1:9091"); - assertThat(polarisStatPushGatewayProperties.getPushInterval().toString()).isEqualTo("1000"); - }); - } -} diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatProperties.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatProperties.java index 5905eb4d7..2ad8e5de0 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatProperties.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatProperties.java @@ -17,6 +17,7 @@ package com.tencent.cloud.rpc.enhancement.stat.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -47,6 +48,25 @@ public class PolarisStatProperties { */ private String path = "/metrics"; + /** + * If state pushGateway reporter enabled. + */ + @Value("${spring.cloud.polaris.stat.pushgateway.enabled:#{false}}") + private boolean pushGatewayEnabled = false; + + /** + * PushGateway address. + */ + @Value("${spring.cloud.polaris.stat.pushgateway.address:}") + private String pushGatewayAddress; + + /** + * Push metrics interval. + * unit: milliseconds default 30s. + */ + @Value("${spring.cloud.polaris.stat.pushgateway.push-interval:#{30000}}") + private Long pushGatewayPushInterval = 30 * 1000L; + public boolean isEnabled() { return enabled; } @@ -78,4 +98,28 @@ public class PolarisStatProperties { public void setPath(String path) { this.path = path; } + + public boolean isPushGatewayEnabled() { + return pushGatewayEnabled; + } + + public void setPushGatewayEnabled(boolean pushGatewayEnabled) { + this.pushGatewayEnabled = pushGatewayEnabled; + } + + public String getPushGatewayAddress() { + return pushGatewayAddress; + } + + public void setPushGatewayAddress(String pushGatewayAddress) { + this.pushGatewayAddress = pushGatewayAddress; + } + + public Long getPushGatewayPushInterval() { + return pushGatewayPushInterval; + } + + public void setPushGatewayPushInterval(Long pushGatewayPushInterval) { + this.pushGatewayPushInterval = pushGatewayPushInterval; + } } 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 8496f70b0..0f06c9651 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 @@ -47,28 +47,35 @@ public class StatConfigModifier implements PolarisConfigModifier { public void modify(ConfigurationImpl configuration) { // Turn on stat reporter configuration. configuration.getGlobal().getStatReporter().setEnable(polarisStatProperties.isEnabled()); - + PrometheusHandlerConfig prometheusHandlerConfig = configuration.getGlobal().getStatReporter() + .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); // Set prometheus plugin. if (polarisStatProperties.isEnabled()) { - PrometheusHandlerConfig prometheusHandlerConfig = configuration.getGlobal().getStatReporter() - .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); - if (!StringUtils.hasText(polarisStatProperties.getHost())) { - polarisStatProperties.setHost(environment.getProperty("spring.cloud.client.ip-address")); + + if (polarisStatProperties.isPushGatewayEnabled()) { + // push gateway + prometheusHandlerConfig.setType("push"); + prometheusHandlerConfig.setAddress(polarisStatProperties.getPushGatewayAddress()); + prometheusHandlerConfig.setPushInterval(polarisStatProperties.getPushGatewayPushInterval()); } - prometheusHandlerConfig.setHost(polarisStatProperties.getHost()); - prometheusHandlerConfig.setPort(polarisStatProperties.getPort()); - prometheusHandlerConfig.setPath(polarisStatProperties.getPath()); - configuration.getGlobal().getStatReporter() - .setPluginConfig(DEFAULT_REPORTER_PROMETHEUS, prometheusHandlerConfig); + else { + // pull metrics + prometheusHandlerConfig.setType("pull"); + if (!StringUtils.hasText(polarisStatProperties.getHost())) { + polarisStatProperties.setHost(environment.getProperty("spring.cloud.client.ip-address")); + } + prometheusHandlerConfig.setHost(polarisStatProperties.getHost()); + prometheusHandlerConfig.setPort(polarisStatProperties.getPort()); + prometheusHandlerConfig.setPath(polarisStatProperties.getPath()); + } + } else { - PrometheusHandlerConfig prometheusHandlerConfig = configuration.getGlobal().getStatReporter() - .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); // Set port to -1 to disable stat plugin. prometheusHandlerConfig.setPort(-1); - configuration.getGlobal().getStatReporter() - .setPluginConfig(DEFAULT_REPORTER_PROMETHEUS, prometheusHandlerConfig); } + configuration.getGlobal().getStatReporter() + .setPluginConfig(DEFAULT_REPORTER_PROMETHEUS, prometheusHandlerConfig); } @Override diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1f618241a..a2a449b33 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-tencent-rpc-enhancement/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -52,6 +52,25 @@ "type": "java.lang.String", "defaultValue": "/metrics", "description": "Path for prometheus to pull." + }, + { + "name": "spring.cloud.polaris.stat.pushgateway.address", + "type": "java.lang.String", + "description": "PushGateway address.", + "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties" + }, + { + "name": "spring.cloud.polaris.stat.pushgateway.enabled", + "type": "java.lang.Boolean", + "description": "If state pushGateway reporter enabled.", + "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties", + "defaultValue": false + }, + { + "name": "spring.cloud.polaris.stat.pushgateway.push-interval", + "type": "java.lang.Long", + "description": "Push metrics interval. unit: milliseconds default 30s.", + "sourceType": "com.tencent.cloud.plugin.pushgateway.PolarisStatPushGatewayProperties" } ] } diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java index e483cf594..48db48072 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementReporterPropertiesTest.java @@ -39,7 +39,7 @@ import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; */ @ExtendWith(SpringExtension.class) @SpringBootTest(classes = RpcEnhancementReporterPropertiesTest.TestApplication.class) -@ActiveProfiles("disable") +@ActiveProfiles("test") public class RpcEnhancementReporterPropertiesTest { @Autowired diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesDisableTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesDisableTest.java deleted file mode 100644 index fbcb0855b..000000000 --- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/PolarisStatPropertiesDisableTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package com.tencent.cloud.rpc.enhancement.stat.config; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Test for {@link PolarisStatProperties}. - * - * @author Haotian Zhang - */ -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = PolarisStatPropertiesDisableTest.TestApplication.class) -@ActiveProfiles("disable") -public class PolarisStatPropertiesDisableTest { - - @Autowired - private PolarisStatProperties polarisStatProperties; - - @Test - public void testDefaultInitialization() { - assertThat(polarisStatProperties).isNotNull(); - assertThat(polarisStatProperties.isEnabled()).isFalse(); - assertThat(polarisStatProperties.getHost()).isBlank(); - } - - @SpringBootApplication - protected static class TestApplication { - - } -} 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 88ac826c5..7074a39b6 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 @@ -18,13 +18,9 @@ package com.tencent.cloud.rpc.enhancement.stat.config; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -33,25 +29,49 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Haotian Zhang */ -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = PolarisStatPropertiesTest.TestApplication.class) -@ActiveProfiles("test") public class PolarisStatPropertiesTest { - @Autowired - private PolarisStatProperties polarisStatProperties; + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisStatPropertiesAutoConfiguration.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.host=127.0.0.1") + .withPropertyValues("spring.cloud.polaris.stat.port=20000") + .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.push-interval=1000"); @Test public void testDefaultInitialization() { - assertThat(polarisStatProperties).isNotNull(); - assertThat(polarisStatProperties.isEnabled()).isTrue(); - assertThat(polarisStatProperties.getHost()).isNotBlank(); - assertThat(polarisStatProperties.getPort()).isEqualTo(20000); - assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx"); + contextRunner.run(context -> { + PolarisStatProperties polarisStatProperties = context.getBean(PolarisStatProperties.class); + + assertThat(polarisStatProperties).isNotNull(); + assertThat(polarisStatProperties.isEnabled()).isTrue(); + assertThat(polarisStatProperties.getHost()).isNotBlank(); + assertThat(polarisStatProperties.getPort()).isEqualTo(20000); + assertThat(polarisStatProperties.getPath()).isEqualTo("/xxx"); + assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue(); + assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091"); + assertThat(polarisStatProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); + }); } - @SpringBootApplication - protected static class TestApplication { + @Test + void testGetAndSet() { + PolarisStatProperties polarisStatProperties = new PolarisStatProperties(); + + // PushGatewayEnabled + polarisStatProperties.setPushGatewayEnabled(true); + assertThat(polarisStatProperties.isPushGatewayEnabled()).isTrue(); + + // PushGatewayAddress + polarisStatProperties.setPushGatewayAddress("127.0.0.1:9091"); + assertThat(polarisStatProperties.getPushGatewayAddress()).isEqualTo("127.0.0.1:9091"); + // PushGatewayPushInterval + polarisStatProperties.setPushGatewayPushInterval(1000L); + assertThat(polarisStatProperties.getPushGatewayPushInterval().toString()).isEqualTo("1000"); } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifierTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifierTest.java new file mode 100644 index 000000000..ba55b6f2e --- /dev/null +++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/stat/config/StatConfigModifierTest.java @@ -0,0 +1,98 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.rpc.enhancement.stat.config; + +import com.tencent.polaris.client.api.SDKContext; +import com.tencent.polaris.plugins.stat.prometheus.handler.PrometheusHandlerConfig; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static com.tencent.polaris.api.config.global.StatReporterConfig.DEFAULT_REPORTER_PROMETHEUS; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link StatConfigModifier}. + * + * @author Haotian Zhang + */ +public class StatConfigModifierTest { + + private final ApplicationContextRunner pullContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(TestApplication.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.host=127.0.0.1") + .withPropertyValues("spring.cloud.polaris.stat.port=20000") + .withPropertyValues("spring.cloud.polaris.stat.path=/xxx"); + + private final ApplicationContextRunner pushContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(TestApplication.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.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.push-interval=1000"); + + private final ApplicationContextRunner disabledContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(TestApplication.class)) + .withPropertyValues("spring.cloud.polaris.enabled=true") + .withPropertyValues("spring.cloud.polaris.stat.enabled=false"); + + @Test + void testPull() { + pullContextRunner.run(context -> { + SDKContext sdkContext = context.getBean(SDKContext.class); + PrometheusHandlerConfig prometheusHandlerConfig = sdkContext.getConfig().getGlobal().getStatReporter() + .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); + assertThat(prometheusHandlerConfig.getType()).isEqualTo("pull"); + assertThat(prometheusHandlerConfig.getHost()).isEqualTo("127.0.0.1"); + assertThat(prometheusHandlerConfig.getPort()).isEqualTo(20000); + assertThat(prometheusHandlerConfig.getPath()).isEqualTo("/xxx"); + }); + } + + @Test + void testPush() { + pushContextRunner.run(context -> { + SDKContext sdkContext = context.getBean(SDKContext.class); + PrometheusHandlerConfig prometheusHandlerConfig = sdkContext.getConfig().getGlobal().getStatReporter() + .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); + assertThat(prometheusHandlerConfig.getType()).isEqualTo("push"); + assertThat(prometheusHandlerConfig.getAddress()).isEqualTo("127.0.0.1:9091"); + assertThat(prometheusHandlerConfig.getPushInterval()).isEqualTo(1000); + }); + } + + @Test + void testDisabled() { + disabledContextRunner.run(context -> { + SDKContext sdkContext = context.getBean(SDKContext.class); + PrometheusHandlerConfig prometheusHandlerConfig = sdkContext.getConfig().getGlobal().getStatReporter() + .getPluginConfig(DEFAULT_REPORTER_PROMETHEUS, PrometheusHandlerConfig.class); + assertThat(prometheusHandlerConfig.getPort()).isEqualTo(-1); + }); + } + + @SpringBootApplication + protected static class TestApplication { + + } +} diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-disable.properties b/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-disable.properties deleted file mode 100644 index a6af090d7..000000000 --- a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-disable.properties +++ /dev/null @@ -1,8 +0,0 @@ -spring.cloud.polaris.stat.enabled=false -spring.cloud.polaris.stat.port=20000 -spring.cloud.polaris.stat.path=/xxx -spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error=false -spring.cloud.tencent.rpc-enhancement.reporter.series[0]=CLIENT_ERROR -spring.cloud.tencent.rpc-enhancement.reporter.series[1]=SERVER_ERROR -spring.cloud.tencent.rpc-enhancement.reporter.statuses[0]=MULTIPLE_CHOICES -spring.cloud.tencent.rpc-enhancement.reporter.statuses[1]=MOVED_PERMANENTLY diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties b/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties index 96d94d0d0..56881cd72 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties +++ b/spring-cloud-tencent-rpc-enhancement/src/test/resources/application-test.properties @@ -1,3 +1,5 @@ -spring.cloud.polaris.stat.enabled=true -spring.cloud.polaris.stat.port=20000 -spring.cloud.polaris.stat.path=/xxx +spring.cloud.tencent.rpc-enhancement.reporter.ignore-internal-server-error=false +spring.cloud.tencent.rpc-enhancement.reporter.series[0]=CLIENT_ERROR +spring.cloud.tencent.rpc-enhancement.reporter.series[1]=SERVER_ERROR +spring.cloud.tencent.rpc-enhancement.reporter.statuses[0]=MULTIPLE_CHOICES +spring.cloud.tencent.rpc-enhancement.reporter.statuses[1]=MOVED_PERMANENTLY