You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "Oscarcheng0312 (via GitHub)" <gi...@apache.org> on 2025/11/28 00:17:00 UTC

[PR] Feature/cpm server endpoints [incubator-seata]

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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] Feature/cpm server endpoints [incubator-seata]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #7812:
URL: https://github.com/apache/incubator-seata/pull/7812#discussion_r2570191242


##########
seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/controller/ClientConnectionPoolController.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.seata.spring.boot.autoconfigure.controller;
+
+import org.apache.seata.core.model.PoolConfigUpdateRequest;
+import org.apache.seata.core.rpc.netty.DataSourceConnectionPoolCollector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * Client-side REST controller for handling connection pool configuration updates.
+ *
+ */
+@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.
+     *
+     * @param request the configuration update request containing new parameter values
+     * @return ResponseEntity indicating success or failure
+     */
+    @PostMapping("/update")
+    public ResponseEntity<String> updateConfig(@RequestBody PoolConfigUpdateRequest request) {
+        try {
+            // Validate request parameters
+            if (request == null
+                    || request.getPoolName() == null
+                    || request.getPoolName().trim().isEmpty()) {
+                LOGGER.warn("Invalid configuration update request: {}", request);
+                return ResponseEntity.badRequest().body("Invalid request: poolName is required");
+            }
+
+            LOGGER.info("Received connection pool configuration update request for pool: {}", request.getPoolName());
+            LOGGER.debug("Configuration update details: {}", request);
+
+            // Validate configuration parameters
+            if (!isValidConfigRequest(request)) {
+                LOGGER.warn("Invalid configuration parameters in request: {}", request);
+                return ResponseEntity.badRequest().body("Invalid configuration parameters");
+            }
+
+            // Apply configuration update using DataSourceConnectionPoolCollector
+            boolean success = DataSourceConnectionPoolCollector.updateConfig(request.getPoolName(), request);
+
+            if (success) {
+                LOGGER.info("Successfully updated connection pool configuration for pool: {}", request.getPoolName());
+                return ResponseEntity.ok("Configuration updated successfully");
+            } else {
+                LOGGER.warn("Failed to update connection pool configuration for pool: {}", request.getPoolName());
+                return ResponseEntity.internalServerError().body("Failed to update configuration");
+            }
+
+        } catch (Exception e) {
+            LOGGER.error(
+                    "Error processing configuration update request for pool: {}",
+                    request != null ? request.getPoolName() : "unknown",
+                    e);
+            return ResponseEntity.internalServerError().body("Internal server error: " + e.getMessage());

Review Comment:
   ## Information exposure through an error message
   
   [Error information](1) can be exposed to an external user.
   [Error information](2) can be exposed to an external user.
   [Error information](3) can be exposed to an external user.
   
   [Show more details](https://github.com/apache/incubator-seata/security/code-scanning/51)



-- 
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: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org