Skip to content

Conversation

@Oscarcheng0312
Copy link
Contributor

@Oscarcheng0312 Oscarcheng0312 commented Nov 28, 2025

Ⅰ. 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.

@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 fromConnectionPoolInfoCacheand 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.

@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?

Yes, it fix #7575

Ⅴ. Special notes for reviews

"Error processing configuration update request for pool: {}",
request != null ? request.getPoolName() : "unknown",
e);
return ResponseEntity.internalServerError().body("Internal server error: " + e.getMessage());

Check warning

Code scanning / CodeQL

Information exposure through an error message Medium

Error information
can be exposed to an external user.
Error information
can be exposed to an external user.
Error information
can be exposed to an external user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: add Controller and Service for the connection-pool

1 participant