This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.4
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.4 by this push:
new f4b0b13984 Remove datasoure status checker (#15046)
f4b0b13984 is described below
commit f4b0b13984be1c4cb2729f9fca1c6cf35e63f0d7
Author: Jermaine Hua <[email protected]>
AuthorDate: Tue Jan 28 22:08:08 2025 +0800
Remove datasoure status checker (#15046)
Signed-off-by: “JermaineHua” <[email protected]>
---
.../spring/status/DataSourceStatusChecker.java | 104 -------------------
.../org.apache.dubbo.common.status.StatusChecker | 1 -
.../spring/status/DataSourceStatusCheckerTest.java | 112 ---------------------
.../dubbo-spring-boot-actuator/README.md | 37 ++++---
4 files changed, 18 insertions(+), 236 deletions(-)
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java
deleted file mode 100644
index 0b46de0f3a..0000000000
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/status/DataSourceStatusChecker.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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 org.apache.dubbo.config.spring.status;
-
-import org.apache.dubbo.common.extension.Activate;
-import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.status.Status;
-import org.apache.dubbo.common.status.StatusChecker;
-import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.config.spring.extension.SpringExtensionInjector;
-import org.apache.dubbo.rpc.model.ApplicationModel;
-
-import javax.sql.DataSource;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.util.Map;
-
-import org.springframework.context.ApplicationContext;
-
-import static
org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_WARN_STATUS_CHECKER;
-
-/**
- * DataSourceStatusChecker
- */
-@Activate
-public class DataSourceStatusChecker implements StatusChecker {
-
- private static final ErrorTypeAwareLogger logger =
-
LoggerFactory.getErrorTypeAwareLogger(DataSourceStatusChecker.class);
-
- private ApplicationModel applicationModel;
-
- private ApplicationContext applicationContext;
-
- public DataSourceStatusChecker(ApplicationModel applicationModel) {
- this.applicationModel = applicationModel;
- }
-
- public DataSourceStatusChecker(ApplicationContext context) {
- this.applicationContext = context;
- }
-
- @Override
- public Status check() {
- if (applicationContext == null) {
- SpringExtensionInjector springExtensionInjector =
SpringExtensionInjector.get(applicationModel);
- applicationContext = springExtensionInjector.getContext();
- }
-
- if (applicationContext == null) {
- return new Status(Status.Level.UNKNOWN);
- }
-
- Map<String, DataSource> dataSources =
applicationContext.getBeansOfType(DataSource.class, false, false);
- if (CollectionUtils.isEmptyMap(dataSources)) {
- return new Status(Status.Level.UNKNOWN);
- }
- Status.Level level = Status.Level.OK;
- StringBuilder buf = new StringBuilder();
- for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
- DataSource dataSource = entry.getValue();
- if (buf.length() > 0) {
- buf.append(", ");
- }
- buf.append(entry.getKey());
-
- try (Connection connection = dataSource.getConnection()) {
- DatabaseMetaData metaData = connection.getMetaData();
- try (ResultSet resultSet = metaData.getTypeInfo()) {
- if (!resultSet.next()) {
- level = Status.Level.ERROR;
- }
- }
- buf.append(metaData.getURL());
- buf.append('(');
- buf.append(metaData.getDatabaseProductName());
- buf.append('-');
- buf.append(metaData.getDatabaseProductVersion());
- buf.append(')');
- } catch (Throwable e) {
- logger.warn(CONFIG_WARN_STATUS_CHECKER, "", "",
e.getMessage(), e);
- return new Status(level, e.getMessage());
- }
- }
- return new Status(level, buf.toString());
- }
-}
diff --git
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
index 0df084b289..8f0ffaeccb 100644
---
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
+++
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
@@ -1,2 +1 @@
spring=org.apache.dubbo.config.spring.status.SpringStatusChecker
-datasource=org.apache.dubbo.config.spring.status.DataSourceStatusChecker
\ No newline at end of file
diff --git
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/status/DataSourceStatusCheckerTest.java
b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/status/DataSourceStatusCheckerTest.java
deleted file mode 100644
index 7edf41135d..0000000000
---
a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/status/DataSourceStatusCheckerTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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 org.apache.dubbo.config.spring.status;
-
-import org.apache.dubbo.common.status.Status;
-import org.apache.dubbo.config.spring.ServiceBean;
-
-import javax.sql.DataSource;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.springframework.context.ApplicationContext;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-class DataSourceStatusCheckerTest {
- private DataSourceStatusChecker dataSourceStatusChecker;
-
- @Mock
- private ApplicationContext applicationContext;
-
- @BeforeEach
- public void setUp() throws Exception {
- initMocks(this);
- this.dataSourceStatusChecker = new
DataSourceStatusChecker(applicationContext);
- new
ServiceBean<Object>(applicationContext).setApplicationContext(applicationContext);
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- Mockito.reset(applicationContext);
- }
-
- @Test
- void testWithoutApplicationContext() {
- Status status = dataSourceStatusChecker.check();
-
- assertThat(status.getLevel(), is(Status.Level.UNKNOWN));
- }
-
- @Test
- void testWithoutDatasource() {
- Map<String, DataSource> map = new HashMap<String, DataSource>();
- given(applicationContext.getBeansOfType(eq(DataSource.class),
anyBoolean(), anyBoolean()))
- .willReturn(map);
-
- Status status = dataSourceStatusChecker.check();
-
- assertThat(status.getLevel(), is(Status.Level.UNKNOWN));
- }
-
- @Test
- void testWithDatasourceHasNextResult() throws SQLException {
- Map<String, DataSource> map = new HashMap<String, DataSource>();
- DataSource dataSource = mock(DataSource.class);
- Connection connection = mock(Connection.class,
Answers.RETURNS_DEEP_STUBS);
- given(dataSource.getConnection()).willReturn(connection);
- given(connection.getMetaData().getTypeInfo().next()).willReturn(true);
-
- map.put("mockDatabase", dataSource);
- given(applicationContext.getBeansOfType(eq(DataSource.class),
anyBoolean(), anyBoolean()))
- .willReturn(map);
- Status status = dataSourceStatusChecker.check();
-
- assertThat(status.getLevel(), is(Status.Level.OK));
- }
-
- @Test
- void testWithDatasourceNotHasNextResult() throws SQLException {
- Map<String, DataSource> map = new HashMap<String, DataSource>();
- DataSource dataSource = mock(DataSource.class);
- Connection connection = mock(Connection.class,
Answers.RETURNS_DEEP_STUBS);
- given(dataSource.getConnection()).willReturn(connection);
- given(connection.getMetaData().getTypeInfo().next()).willReturn(false);
-
- map.put("mockDatabase", dataSource);
- given(applicationContext.getBeansOfType(eq(DataSource.class),
anyBoolean(), anyBoolean()))
- .willReturn(map);
- Status status = dataSourceStatusChecker.check();
-
- assertThat(status.getLevel(), is(Status.Level.ERROR));
- }
-}
diff --git a/dubbo-spring-boot-project/dubbo-spring-boot-actuator/README.md
b/dubbo-spring-boot-project/dubbo-spring-boot-actuator/README.md
index a753c9ef36..f699593746 100644
--- a/dubbo-spring-boot-project/dubbo-spring-boot-actuator/README.md
+++ b/dubbo-spring-boot-project/dubbo-spring-boot-actuator/README.md
@@ -55,7 +55,7 @@ If your project failed to resolve the dependency, try to add
the following repos
-Suppose a Spring Boot Web application did not specify
`management.server.port`, you can access http://localhost:8080/actuator/health
via Web Client and will get a response with JSON format is like below :
+Suppose a Spring Boot Web application did not specify
`management.server.port`, you can access http://localhost:8080/actuator/health
via Web Client and will get a response with JSON format is like below :
```json
{
@@ -100,10 +100,10 @@ Suppose a Spring Boot Web application did not specify
`management.server.port`,
```
- `memory`, `load`, `threadpool` and `server` are Dubbo's build-in
`StatusChecker`s in above example.
- Dubbo allows the application to extend `StatusChecker`'s SPI.
+ `memory`, `load`, `threadpool` and `server` are Dubbo's build-in
`StatusChecker`s in above example.
+ Dubbo allows the application to extend `StatusChecker`'s SPI.
-Default , `memory` and `load` will be added into Dubbo's `HealthIndicator` ,
it could be overridden by
+Default , `memory` and `load` will be added into Dubbo's `HealthIndicator` ,
it could be overridden by
externalized configuration [`StatusChecker`'s
defaults](#statuschecker-defaults).
@@ -127,7 +127,6 @@ externalized configuration [`StatusChecker`'s
defaults](#statuschecker-defaults)
```properties
registry=org.apache.dubbo.registry.status.RegistryStatusChecker
spring=org.apache.dubbo.config.spring.status.SpringStatusChecker
-datasource=org.apache.dubbo.config.spring.status.DataSourceStatusChecker
memory=org.apache.dubbo.common.status.support.MemoryStatusChecker
load=org.apache.dubbo.common.status.support.LoadStatusChecker
server=org.apache.dubbo.rpc.protocol.dubbo.status.ServerStatusChecker
@@ -144,7 +143,7 @@ The property key that is name of `StatusChecker` can be a
valid value of `manag
-Actuator endpoint `dubbo` supports Actuator Endpoints :
+Actuator endpoint `dubbo` supports Actuator Endpoints :
| ID | Enabled | HTTP URI | HTTP Method |
Description | Content Type |
| ------------------- | ----------- | ----------------------------------- |
------------------ | ------------------ | ------------------ |
@@ -198,7 +197,7 @@ Actuator endpoint `dubbo` supports Actuator Endpoints :
#### `/actuator/dubbo`
-`/dubbo` exposes Dubbo's meta data :
+`/dubbo` exposes Dubbo's meta data :
```json
{
@@ -217,11 +216,11 @@ Actuator endpoint `dubbo` supports Actuator Endpoints :
}
```
-###
+###
#### `/actuator/dubbo/properties`
-`/actuator/dubbo/properties` exposes all Dubbo's Properties from Spring Boot
Externalized Configuration (a.k.a `PropertySources`) :
+`/actuator/dubbo/properties` exposes all Dubbo's Properties from Spring Boot
Externalized Configuration (a.k.a `PropertySources`) :
```json
{
@@ -380,16 +379,16 @@ The key is the string presentation of `@Reference`
`Field` or `Method ` , `Refe
}
},
"ConsumerConfig": {
-
+
},
"MethodConfig": {
-
+
},
"ModuleConfig": {
-
+
},
"MonitorConfig": {
-
+
},
"ProtocolConfig": {
"dubbo": {
@@ -425,16 +424,16 @@ The key is the string presentation of `@Reference`
`Field` or `Method ` , `Refe
}
},
"ProviderConfig": {
-
+
},
"ReferenceConfig": {
-
+
},
"RegistryConfig": {
-
+
},
"ServiceConfig": {
-
+
}
}
```
@@ -521,7 +520,7 @@ Compared with the `simple profiler` mode, the `detail
profiler` collects more ti
-`management.health.dubbo.status.defaults` is a property name for setting names
of `StatusChecker`s , its value is allowed to multiple-values , for example :
+`management.health.dubbo.status.defaults` is a property name for setting names
of `StatusChecker`s , its value is allowed to multiple-values , for example :
```properties
management.health.dubbo.status.defaults = registry,memory,load
@@ -531,7 +530,7 @@ management.health.dubbo.status.defaults =
registry,memory,load
#### Default Value
-The default value is :
+The default value is :
```properties
management.health.dubbo.status.defaults = memory,load