diff --git a/CHANGELOG.md b/CHANGELOG.md
index 123a022a..3c6a8fa6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@
- [feat:Add GitHub action of codecov.yml.](https://github.com/Tencent/spring-cloud-tencent/pull/328)
- [Feature: add spring cloud tencent logo](https://github.com/Tencent/spring-cloud-tencent/pull/329)
- [Feature: Optimize static metadata manager](https://github.com/Tencent/spring-cloud-tencent/pull/327)
+- [Feature: support actuator for sct core components](https://github.com/Tencent/spring-cloud-tencent/pull/343)
- [test:update junit of metadata.](https://github.com/Tencent/spring-cloud-tencent/pull/340)
- [Optimize code style & unit test case](https://github.com/Tencent/spring-cloud-tencent/pull/336)
- [rm code: Condition 'null != interceptors' is always 'true' ](https://github.com/Tencent/spring-cloud-tencent/pull/342)
diff --git a/spring-cloud-starter-tencent-polaris-config/pom.xml b/spring-cloud-starter-tencent-polaris-config/pom.xml
index a7f0e589..e7262c29 100644
--- a/spring-cloud-starter-tencent-polaris-config/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-config/pom.xml
@@ -71,6 +71,18 @@
test
+
+ org.springframework.boot
+ spring-boot-actuator
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-actuator-autoconfigure
+ true
+
+
org.mockitomockito-inline
diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpoint.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpoint.java
new file mode 100644
index 00000000..eb9e94f5
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpoint.java
@@ -0,0 +1,58 @@
+/*
+ * 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.polaris.config.endpoint;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.tencent.cloud.polaris.config.adapter.PolarisPropertySource;
+import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
+import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+
+/**
+ * Endpoint of polaris config.
+ *
+ * @author shuiqingliu
+ **/
+@Endpoint(id = "polaris-config")
+public class PolarisConfigEndpoint {
+
+ private final PolarisConfigProperties polarisConfigProperties;
+ private final PolarisPropertySourceManager polarisPropertySourceManager;
+
+ public PolarisConfigEndpoint(PolarisConfigProperties polarisConfigProperties, PolarisPropertySourceManager polarisPropertySourceManager) {
+ this.polarisConfigProperties = polarisConfigProperties;
+ this.polarisPropertySourceManager = polarisPropertySourceManager;
+ }
+
+ @ReadOperation
+ public Map polarisConfig() {
+ Map configInfo = new HashMap<>();
+ configInfo.put("PolarisConfigProperties", polarisConfigProperties);
+
+ List propertySourceList = polarisPropertySourceManager.getAllPropertySources();
+ configInfo.put("PolarisPropertySource", propertySourceList);
+
+ return configInfo;
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java
new file mode 100644
index 00000000..cb26462e
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointAutoConfiguration.java
@@ -0,0 +1,49 @@
+/*
+ * 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.polaris.config.endpoint;
+
+import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
+import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
+
+import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The AutoConfiguration for Polaris Config's endpoint.
+ *
+ * @author shuiqingliu
+ **/
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnClass(Endpoint.class)
+@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled",
+ matchIfMissing = true)
+public class PolarisConfigEndpointAutoConfiguration {
+
+ @Bean
+ @ConditionalOnAvailableEndpoint
+ @ConditionalOnMissingBean
+ public PolarisConfigEndpoint polarisConfigEndpoint(PolarisConfigProperties polarisConfigProperties, PolarisPropertySourceManager polarisPropertySourceManager) {
+ return new PolarisConfigEndpoint(polarisConfigProperties, polarisPropertySourceManager);
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/spring.factories
index a0c33067..98221a39 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/spring.factories
@@ -1,4 +1,5 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- com.tencent.cloud.polaris.config.PolarisConfigAutoConfiguration
+ com.tencent.cloud.polaris.config.PolarisConfigAutoConfiguration,\
+ com.tencent.cloud.polaris.config.endpoint.PolarisConfigEndpointAutoConfiguration
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java
new file mode 100644
index 00000000..93190ee1
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.polaris.config.endpoint;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.tencent.cloud.polaris.config.adapter.MockedConfigKVFile;
+import com.tencent.cloud.polaris.config.adapter.PolarisPropertySource;
+import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
+import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test for polaris config endpoint.
+ *
+ * @author shuiqingliu
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class PolarisConfigEndpointTest {
+
+ private final String testNamespace = "testNamespace";
+ private final String testServiceName = "testServiceName";
+ private final String testFileName = "application.properties";
+
+ @Mock
+ private PolarisConfigProperties polarisConfigProperties;
+ @Mock
+ private PolarisPropertySourceManager polarisPropertySourceManager;
+
+ @Test
+ public void testPolarisConfigEndpoint() {
+ Map content = new HashMap<>();
+ content.put("k1", "v1");
+ content.put("k2", "v2");
+ content.put("k3", "v3");
+ MockedConfigKVFile file = new MockedConfigKVFile(content);
+ PolarisPropertySource polarisPropertySource = new PolarisPropertySource(testNamespace, testServiceName, testFileName,
+ file, content);
+ when(polarisPropertySourceManager.getAllPropertySources()).thenReturn(Lists.newArrayList(polarisPropertySource));
+
+ PolarisConfigEndpoint endpoint = new PolarisConfigEndpoint(polarisConfigProperties, polarisPropertySourceManager);
+ Map info = endpoint.polarisConfig();
+ assertThat(polarisConfigProperties).isEqualTo(info.get("PolarisConfigProperties"));
+ assertThat(Lists.newArrayList(polarisPropertySource)).isEqualTo(info.get("PolarisPropertySource"));
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/pom.xml b/spring-cloud-starter-tencent-polaris-discovery/pom.xml
index 39d8d5f8..ac077bb7 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-discovery/pom.xml
@@ -93,6 +93,18 @@
test
+
+ org.springframework.boot
+ spring-boot-actuator
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-actuator-autoconfigure
+ true
+
+
io.projectreactorreactor-test
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPoint.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPoint.java
new file mode 100644
index 00000000..5e006ac0
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPoint.java
@@ -0,0 +1,82 @@
+/*
+ * 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.polaris.endpoint;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
+import com.tencent.polaris.api.pojo.ServiceInstances;
+import com.tencent.polaris.api.rpc.InstancesResponse;
+import org.apache.commons.lang.StringUtils;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+import org.springframework.boot.actuate.endpoint.annotation.Selector;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+
+/**
+ * Endpoint of polaris discovery, include discovery properties and service instance.
+ *
+ * @author shuiqingliu
+ */
+@Endpoint(id = "polaris-discovery")
+public class PolarisDiscoveryEndPoint {
+
+ private final PolarisDiscoveryProperties polarisDiscoveryProperties;
+ private final DiscoveryClient polarisDiscoveryClient;
+ private final PolarisDiscoveryHandler polarisDiscoveryHandler;
+
+ public PolarisDiscoveryEndPoint(PolarisDiscoveryProperties polarisDiscoveryProperties, DiscoveryClient polarisDiscoveryClient, PolarisDiscoveryHandler polarisDiscoveryHandler) {
+ this.polarisDiscoveryProperties = polarisDiscoveryProperties;
+ this.polarisDiscoveryClient = polarisDiscoveryClient;
+ this.polarisDiscoveryHandler = polarisDiscoveryHandler;
+ }
+
+ @ReadOperation
+ public Map polarisDiscovery(@Selector String serviceId) {
+ Map polarisDisConveryInfo = new HashMap<>();
+ polarisDisConveryInfo.put("PolarisDiscoveryProperties", polarisDiscoveryProperties);
+
+ List serviceInstancesInfoList = new ArrayList<>();
+
+ if (StringUtils.isNotEmpty(serviceId)) {
+ ServiceInstances serviceInstances = getServiceInstances(serviceId);
+ serviceInstancesInfoList.add(serviceInstances);
+ polarisDisConveryInfo.put("ServiceInstances", serviceInstancesInfoList);
+ return polarisDisConveryInfo;
+ }
+
+ for (String service : polarisDiscoveryClient.getServices()) {
+ ServiceInstances serviceInstances = getServiceInstances(service);
+ serviceInstancesInfoList.add(serviceInstances);
+ }
+
+ polarisDisConveryInfo.put("ServiceInstances", serviceInstancesInfoList);
+ return polarisDisConveryInfo;
+ }
+
+ private ServiceInstances getServiceInstances(String serviceId) {
+ InstancesResponse instancesResponse = polarisDiscoveryHandler.getHealthyInstances(serviceId);
+ ServiceInstances serviceInstances = instancesResponse.toServiceInstances();
+ return serviceInstances;
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointAutoConfiguration.java
new file mode 100644
index 00000000..d6b59763
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointAutoConfiguration.java
@@ -0,0 +1,49 @@
+/*
+ * 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.polaris.endpoint;
+
+import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
+import com.tencent.cloud.polaris.discovery.ConditionalOnPolarisDiscoveryEnabled;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
+
+import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The AutoConfiguration for Polaris Discovery's Endpoint.
+ *
+ * @author shuiqingliu
+ **/
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnClass(Endpoint.class)
+@ConditionalOnPolarisDiscoveryEnabled
+public class PolarisDiscoveryEndpointAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnAvailableEndpoint
+ public PolarisDiscoveryEndPoint polarisDiscoveryEndPoint(PolarisDiscoveryProperties polarisDiscoveryProperties,
+ DiscoveryClient discoveryClient, PolarisDiscoveryHandler polarisDiscoveryHandler) {
+ return new PolarisDiscoveryEndPoint(polarisDiscoveryProperties, discoveryClient, polarisDiscoveryHandler);
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
index 83b8e001..e8deb25e 100644
--- a/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/resources/META-INF/spring.factories
@@ -2,6 +2,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration,\
com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration,\
com.tencent.cloud.polaris.ribbon.PolarisDiscoveryRibbonAutoConfiguration,\
- com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration
+ com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration,\
+ com.tencent.cloud.polaris.endpoint.PolarisDiscoveryEndpointAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.DiscoveryPropertiesBootstrapAutoConfiguration
diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPointTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPointTest.java
new file mode 100644
index 00000000..ea5562d1
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndPointTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.polaris.endpoint;
+
+import java.util.Map;
+
+import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClient;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClientConfiguration;
+import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
+import com.tencent.polaris.test.mock.discovery.NamingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.context.annotation.Configuration;
+
+import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
+import static com.tencent.polaris.test.common.Consts.PORT;
+import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test for polaris discovery endpoint.
+ *
+ * @author shuiqingliu
+ */
+public class PolarisDiscoveryEndPointTest {
+
+ private static NamingServer namingServer;
+
+ private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(
+ PolarisDiscoveryEndPointTest.PolarisPropertiesConfiguration.class,
+ PolarisDiscoveryClientConfiguration.class,
+ PolarisDiscoveryAutoConfiguration.class,
+ PolarisDiscoveryEndpointAutoConfiguration.class))
+ .withPropertyValues("spring.application.name=" + SERVICE_PROVIDER)
+ .withPropertyValues("server.port=" + PORT)
+ .withPropertyValues("spring.cloud.polaris.address=grpc://127.0.0.1:10081")
+ .withPropertyValues(
+ "spring.cloud.polaris.discovery.namespace=" + NAMESPACE_TEST)
+ .withPropertyValues("spring.cloud.polaris.discovery.token=xxxxxx");
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ namingServer = NamingServer.startNamingServer(10081);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ if (null != namingServer) {
+ namingServer.terminate();
+ }
+ }
+
+ @Test
+ public void testPolarisDiscoveryEndpoint() {
+ this.contextRunner.run(context -> {
+ PolarisDiscoveryProperties polarisDiscoveryProperties = context
+ .getBean(PolarisDiscoveryProperties.class);
+ DiscoveryClient discoveryClient = context
+ .getBean(PolarisDiscoveryClient.class);
+ PolarisDiscoveryHandler polarisDiscoveryHandler = context.getBean(PolarisDiscoveryHandler.class);
+ PolarisDiscoveryEndPoint polarisDiscoveryEndPoint = new PolarisDiscoveryEndPoint(polarisDiscoveryProperties, discoveryClient, polarisDiscoveryHandler);
+
+ Map mapInfo = polarisDiscoveryEndPoint.polarisDiscovery("java_provider_test");
+
+ assertThat(polarisDiscoveryProperties).isEqualTo(mapInfo.get("PolarisDiscoveryProperties"));
+
+ });
+ }
+
+ @Configuration
+ @EnableAutoConfiguration
+ @EnableDiscoveryClient
+ static class PolarisPropertiesConfiguration {
+
+ }
+
+}
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
index aaccef81..d3499dee 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/pom.xml
@@ -90,6 +90,18 @@
test
+
+ org.springframework.boot
+ spring-boot-actuator
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-actuator-autoconfigure
+ true
+
+
org.mockitomockito-inline
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/endpoint/PolarisRateLimitRuleEndpoint.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/endpoint/PolarisRateLimitRuleEndpoint.java
new file mode 100644
index 00000000..28bbae22
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/endpoint/PolarisRateLimitRuleEndpoint.java
@@ -0,0 +1,101 @@
+/*
+ * 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.polaris.ratelimit.endpoint;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.tencent.cloud.polaris.context.ServiceRuleManager;
+import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitProperties;
+import com.tencent.polaris.client.pb.RateLimitProto;
+import com.tencent.polaris.client.pb.RoutingProto;
+import org.apache.commons.lang.StringUtils;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+import org.springframework.boot.actuate.endpoint.annotation.Selector;
+import org.springframework.lang.Nullable;
+import org.springframework.util.CollectionUtils;
+
+/**
+ * Endpoint of Polaris RateLimit rule.
+ *
+ * @author shuiqingliu
+ **/
+@Endpoint(id = "polaris-ratelimit")
+public class PolarisRateLimitRuleEndpoint {
+
+ private final ServiceRuleManager serviceRuleManager;
+ private final PolarisRateLimitProperties polarisRateLimitProperties;
+
+ public PolarisRateLimitRuleEndpoint(ServiceRuleManager serviceRuleManager, PolarisRateLimitProperties polarisRateLimitProperties) {
+ this.serviceRuleManager = serviceRuleManager;
+ this.polarisRateLimitProperties = polarisRateLimitProperties;
+ }
+
+ @ReadOperation
+ public Map rateLimit(@Selector String namespace, @Selector String service, @Nullable String dstService) {
+ Map result = new HashMap<>();
+ RateLimitProto.RateLimit rateLimit = serviceRuleManager.getServiceRateLimitRule(namespace, service);
+ result.put("properties", polarisRateLimitProperties);
+ result.put("namespace", namespace);
+ result.put("service", service);
+ result.put("rateLimits", parseRateLimitRule(rateLimit));
+
+ if (StringUtils.isEmpty(dstService)) {
+ return result;
+ }
+ List routes = serviceRuleManager.getServiceRouterRule(namespace, service, dstService);
+ result.put("routes", routes);
+ return result;
+ }
+
+ private List
+
+
+ org.springframework.boot
+ spring-boot-actuator
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-actuator-autoconfigure
+ true
+
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpoint.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpoint.java
new file mode 100644
index 00000000..360018ea
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpoint.java
@@ -0,0 +1,56 @@
+/*
+ * 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.common.metadata.endpoint;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.tencent.cloud.common.metadata.StaticMetadataManager;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+
+/**
+ * Endpoint of polaris's metadata.
+ *
+ * @author shuiqingliu
+ **/
+@Endpoint(id = "polaris-metadata")
+public class PolarisMetadataEndpoint {
+
+ private final StaticMetadataManager staticMetadataManager;
+
+ public PolarisMetadataEndpoint(StaticMetadataManager staticMetadataManager) {
+ this.staticMetadataManager = staticMetadataManager;
+ }
+
+ @ReadOperation
+ public Map metadata() {
+ Map result = new HashMap<>();
+ result.put("Env", staticMetadataManager.getAllEnvMetadata());
+ result.put("EnvTransitive", staticMetadataManager.getEnvTransitiveMetadata());
+ result.put("ConfigTransitive", staticMetadataManager.getConfigTransitiveMetadata());
+ result.put("Config", staticMetadataManager.getAllConfigMetadata());
+ result.put("MergeStatic", staticMetadataManager.getMergedStaticMetadata());
+ result.put("CustomSPI", staticMetadataManager.getCustomSPITransitiveMetadata());
+ result.put("zone", staticMetadataManager.getZone());
+ result.put("region", staticMetadataManager.getRegion());
+ result.put("campus", staticMetadataManager.getCampus());
+ return result;
+ }
+}
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointAutoConfiguration.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointAutoConfiguration.java
new file mode 100644
index 00000000..9c87587c
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointAutoConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * 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.common.metadata.endpoint;
+
+import com.tencent.cloud.common.metadata.StaticMetadataManager;
+
+import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The AutoConfiguration for metadata endpoint.
+ *
+ * @author shuiqingliu
+ **/
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnClass(Endpoint.class)
+public class PolarisMetadataEndpointAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnAvailableEndpoint
+ public PolarisMetadataEndpoint metadataEndpoint(StaticMetadataManager staticMetadataManager) {
+ return new PolarisMetadataEndpoint(staticMetadataManager);
+ }
+}
diff --git a/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
index ba9f2b86..4c54d337 100644
--- a/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-tencent-commons/src/main/resources/META-INF/spring.factories
@@ -1,3 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.common.util.ApplicationContextAwareUtils,\
- com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration
+ com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration,\
+ com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointTests.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointTests.java
new file mode 100644
index 00000000..d20a2fd4
--- /dev/null
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/endpoint/PolarisMetadataEndpointTests.java
@@ -0,0 +1,58 @@
+/*
+ * 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.common.metadata.endpoint;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.tencent.cloud.common.metadata.StaticMetadataManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test for polaris metadata endpoint.
+ *
+ * @author shuiqingliu
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class PolarisMetadataEndpointTests {
+
+ @Mock
+ private StaticMetadataManager staticMetadataManager;
+
+ @Test
+ public void testPolarisMetadataEndpoint() {
+ Map envMetadata = new HashMap<>();
+ envMetadata.put("k1", "v1");
+ envMetadata.put("k2", "v2");
+ envMetadata.put("k3", "v3");
+
+ when(staticMetadataManager.getAllEnvMetadata()).thenReturn(envMetadata);
+
+ PolarisMetadataEndpoint polarisMetadataEndpoint = new PolarisMetadataEndpoint(staticMetadataManager);
+ Map metaMap = polarisMetadataEndpoint.metadata();
+ assertThat(envMetadata).isEqualTo(metaMap.get("Env"));
+ }
+}
diff --git a/spring-cloud-tencent-examples/metadata-transfer-example/metadata-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/metadata-transfer-example/metadata-caller-service/src/main/resources/bootstrap.yml
index 89d1f233..a390f51a 100644
--- a/spring-cloud-tencent-examples/metadata-transfer-example/metadata-caller-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/metadata-transfer-example/metadata-caller-service/src/main/resources/bootstrap.yml
@@ -24,3 +24,9 @@ spring:
# Assigned which metadata key-value will be passed along the link
transitive:
- CUSTOM-METADATA-KEY-TRANSITIVE
+management:
+ endpoints:
+ web:
+ exposure:
+ include:
+ - polaris-metadata
\ No newline at end of file
diff --git a/spring-cloud-tencent-examples/polaris-config-example/pom.xml b/spring-cloud-tencent-examples/polaris-config-example/pom.xml
index cef91e5a..bb7ef026 100644
--- a/spring-cloud-tencent-examples/polaris-config-example/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-config-example/pom.xml
@@ -24,6 +24,41 @@
com.tencent.cloudspring-cloud-starter-tencent-polaris-config
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+
diff --git a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml
index 38ed7eed..84e44d4a 100644
--- a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml
@@ -12,3 +12,9 @@ spring:
groups:
- name: ${spring.application.name} # group name
files: [ "config/application.properties", "config/bootstrap.yml" ] # config/application.properties takes precedence over config/bootstrap.yml
+management:
+ endpoints:
+ web:
+ exposure:
+ include:
+ - polaris-config
\ No newline at end of file
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
index e9ccc1f2..544193b7 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
@@ -32,3 +32,9 @@ spring:
# client:
# serviceUrl:
# defaultZone: http://127.0.0.1:7654/eureka/
+management:
+ endpoints:
+ web:
+ exposure:
+ include:
+ - polaris-discovery
\ No newline at end of file
diff --git a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml
index cd9f4875..f7cbb1e6 100644
--- a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/pom.xml
@@ -28,6 +28,10 @@
spring-cloud-starter-tencent-polaris-ratelimit
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
diff --git a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
index 37c98639..6741bde1 100644
--- a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
@@ -12,3 +12,10 @@ spring:
enabled: true
rejectRequestTipsFilePath: reject-tips.html
maxQueuingTime: 500
+
+management:
+ endpoints:
+ web:
+ exposure:
+ include:
+ - polaris-ratelimit
\ No newline at end of file