Oscarcheng0312 opened a new pull request, #7812:
URL: https://github.com/apache/incubator-seata/pull/7812

   <!--
       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.
   -->
   <!-- Please make sure you have read and understood the contributing 
guidelines -->
   
   - [ ] I have read the 
[CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md)
 guidelines.
   - [ ] I have registered the PR 
[changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
   
   ### Ⅰ. Describe what this PR did
   
   Endpoint Exposure
   
   ## 1. Server-Side Monitoring Data Endpoints
   
   ### 1) Modifications
   
   `server/src/main/java/org/apache/seata/server/config/ServerConfig.java`
   
   **Purpose**: Provides the key component configurations required for 
server-side connection-pool monitoring.
   
   ```
   
   ### 2)Newly Added
   
   
`server/src/main/java/org/apache/seata/server/controller/ConnectionPoolController.java`
   
   **Purpose**: Provides REST API endpoints for retrieving and updating 
connection-pool metrics.
   These APIs are consumed by the frontend service.
   
   ```java
   @RestController
   @RequestMapping("/api/pool")
   @CrossOrigin(
           origins = {"http://127.0.0.1:30000";, "http://127.0.0.1:8081"},
           allowCredentials = "true")
   @ConditionalOnProperty(name = "seata.enableConnectionPoolMetrics", 
havingValue = "true")
   public class ConnectionPoolController {
   
       private final ConnectionPoolService connectionPoolService;
   
       public ConnectionPoolController(ConnectionPoolService 
connectionPoolService) {
           this.connectionPoolService = connectionPoolService;
       }
   
       /**
        * Get connection pool metrics by pool type
        *
        * @return list of connection pool metrics
        */
       @GetMapping("/metrics/type/{poolType}")
       public ApiResponse<List<ConnectionPoolMetricsVO>> 
getMetricsByType(@PathVariable("poolType") PoolType poolType) {
           return 
ApiResponse.success(connectionPoolService.getMetricsByType(poolType));
       }
   
       /**
        * Get connection pool metrics for all services
        *
        * @return list of all connection pool metrics
        */
       @GetMapping("/metrics")
       public ApiResponse<List<ConnectionPoolMetricsVO>> getAllMetrics() {
           return ApiResponse.success(connectionPoolService.getAllMetrics());
       }
   
       /**
        * Get connection pool configuration by pool type
        *
        * @return list of connection pool configuration
        */
       @GetMapping("/config/type/{poolType}")
       public ApiResponse<List<ConnectionPoolConfigVO>> 
getConfigByType(@PathVariable("poolType") PoolType poolType) {
           return 
ApiResponse.success(connectionPoolService.getConfigByType(poolType));
       }
   
       /**
        * Get connection pool configuration for all services
        *
        * @return list of all connection pool configuration
        */
       @GetMapping("/config")
       public ApiResponse<List<ConnectionPoolConfigVO>> getAllConfig() {
           return ApiResponse.success(connectionPoolService.getAllConfig());
       }
   
       /**
        * Update connection pool configuration
        *
        * @param poolName connection pool name
        * @param request  configuration update request
        * @return operation result
        */
       @PutMapping("/config/{poolName}")
       public ApiResponse<Boolean> updateConfig(
               @PathVariable("poolName") String poolName, @RequestBody 
@Validated PoolConfigUpdateRequest request) {
           try {
               if (poolName == null || request == null) {
                   return ApiResponse.of(-1, "Invalid request parameters", 
false);
               }
               if (!isValidConfigRequest(request)) {
                   return ApiResponse.of(-1, "Invalid configuration 
parameters", false);
               }
               request.setPoolName(poolName);
               boolean success = connectionPoolService.updateConfig(poolName, 
request);
               if (success) {
                   return ApiResponse.success(true);
               } else {
                   return ApiResponse.of(-1, "Failed to update configuration 
for service: " + poolName, false);
               }
           } catch (Exception e) {
               return ApiResponse.of(-1, "Error updating configuration: " + 
e.getMessage(), false);
           }
       }
   }
   ```
   
   
`server/src/main/java/org/apache/seata/server/metrics/ConnectionPoolService.java`
   
   **Purpose**: Provides the server-side implementation for retrieving 
connection-pool metrics.
   It obtains cached metrics from`ConnectionPoolInfoCache`and returns them to 
callers.
   
   Supporting classes:
   
   - `server/src/main/java/org/apache/seata/server/common/HttpClient.java`
     - Http utility class
   - `core/src/main/java/org/apache/seata/core/model/ApiResponse.java`
     - Unified response wrapper
   - 
`core/src/main/java/org/apache/seata/core/model/PoolConfigUpdateRequest.java`
     - Request body for configuration updates
   
   VO
   
   - 
`server/src/main/java/org/apache/seata/server/metrics/vo/ConnectionPoolConfigVO.java`
   - 
``server/src/main/java/org/apache/seata/server/metrics/vo/ConnectionPoolMetricsVO.java`
   
   ## 2.Client-Side Configuration Update Endpoint
   
   ### 1)Newly Added
   
   
`seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/controller/ClientConnectionPoolController.java`
   
   **Purpose**: Provides connection-pool configuration update endpoints on the 
client side.
   These APIs are invoked by the Seata server.
   
   ```java
   @RestController
   @RequestMapping("/client/pool")
   public class ClientConnectionPoolController {
   
       private static final Logger LOGGER = 
LoggerFactory.getLogger(ClientConnectionPoolController.class);
   
       /**
        * Update connection pool configuration.
        * This endpoint is called by the Seata server to update client-side 
connection pool settings.
        */
       @PostMapping("/update")
       public ResponseEntity<String> updateConfig(@RequestBody 
PoolConfigUpdateRequest request) {
         ......
       }
   }
   
   ```
   
   
   ### Ⅱ. Does this pull request fix one issue?
   <!-- If that, add "fixes #xxx" below in the next line, for example, fixes 
#97. -->
   Yes, it fix #7575 
   
   
   ### Ⅴ. Special notes for reviews
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to