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/12/01 00:53:00 UTC

[PR] Feature/cpm client autoconfig [incubator-seata]

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

   <!--
       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
   # Automated Configuration
   
   ## 1.Enabling Connection Pool Monitoring
   
   ### 1)Modification
   
   `seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataProperties.java`
   
   **Purpose**: Add a configuration field to enable or disable the connection pool monitoring feature.
   
   ```java
    /**
     * enable connection pool metrics
     */
    private boolean enableConnectionPoolMetrics = false;
   ```
   
   `spring/src/main/java/org/apache/seata/spring/annotation/GlobalTransactionScanner.java`
   
   **Purpose**: Configure whether to enable the connection pool monitoring feature and initialize the client HTTP port.
   
   ```java
   // init enableConnectionPoolMetrics / httpPort
   try {
       if (applicationContext != null) {
           String enableConnectionPoolMetricsStr =
                   applicationContext.getEnvironment().getProperty("seata.enableConnectionPoolMetrics");
           if (enableConnectionPoolMetricsStr != null
                   && !enableConnectionPoolMetricsStr.trim().isEmpty()) {
               boolean enableConnectionPoolMetrics = Boolean.parseBoolean(enableConnectionPoolMetricsStr);
               RmNettyRemotingClient.getInstance().setEnableConnectionPoolMetrics(enableConnectionPoolMetrics);
           }
           String portStr = applicationContext.getEnvironment().getProperty("server.port");
           if (portStr != null && !portStr.trim().isEmpty()) {
               try {
                   int port = Integer.parseInt(portStr.trim());
                   RmNettyRemotingClient.getInstance().setHttpPort(port);
               } catch (NumberFormatException e) {
                   LOGGER.debug("Invalid server.port in Spring Environment: {}", portStr);
               }
           }
       }
   } catch (Throwable t) {
       LOGGER.debug("Failed to resolve server.port from Spring Environment", t);
   }
   ```
   
   ## 2.Loading Client Endpoint Configuration
   
   ### 1)Modification
   
   `seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/SeataSpringFenceAutoConfiguration.java`
   
   **Purpose**: Load the client-side endpoint (`ClientConnectionPoolController`), which provides the ability to update connection pool configurations.
   
   ```java
   @Bean
   @ConditionalOnProperty(name = "seata.enableConnectionPoolMetrics", havingValue = "true")
   @ConditionalOnClass(name = "org.springframework.web.bind.annotation.RestController")
   public ClientConnectionPoolController connectionPoolController() {
       return new ClientConnectionPoolController();
   }
   ```
   
   # Same-Port Hosting
   
   `namingserver/src/main/java/org/apache/seata/namingserver/controller/SpaController.java`
   
   **Purpose:**: Add a new front-end entry controller `SpaController`, forwarding `GET /cpm`to` forward:/cpm/index.html`
   
   `namingserver/pom.xml`
   
   **Purpose**:
   
   - Use `frontend-maven-plugin` to run `npm ci` and `npm run build` within the front-end directory at build time.
   - Use `maven-resources-plugin` to copy `cpm/build/*` into `namingserver`  `target/classes/static/cpm/`, so it can be packaged into the executable JAR.
   
   ```xml
   <plugin>
       <groupId>com.github.eirslett</groupId>
       <artifactId>frontend-maven-plugin</artifactId>
       <version>1.12.1</version>
       <configuration>
           <workingDirectory>${project.basedir}/../console/src/main/resources/static/cpm</workingDirectory>
       </configuration>
       <executions>
           <execution>
               <id>install-node</id>
               <goals>
                   <goal>install-node-and-npm</goal>
               </goals>
               <configuration>
                   <nodeVersion>v18.18.0</nodeVersion>
               </configuration>
           </execution>
           <execution>
               <id>npm-ci</id>
               <goals>
                   <goal>npm</goal>
               </goals>
               <phase>generate-resources</phase>
               <configuration>
                   <arguments>ci --no-audit --no-fund</arguments>
               </configuration>
           </execution>
           <execution>
               <id>npm-build</id>
               <goals>
                   <goal>npm</goal>
               </goals>
               <phase>generate-resources</phase>
               <configuration>
                   <arguments>run build</arguments>
               </configuration>
           </execution>
       </executions>
   </plugin>
   <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-resources-plugin</artifactId>
       <executions>
           <execution>
               <id>copy-cpm-build</id>
               <phase>process-resources</phase>
               <goals>
                   <goal>copy-resources</goal>
               </goals>
               <configuration>
                   <outputDirectory>${project.build.outputDirectory}/static/cpm</outputDirectory>
                   <resources>
                       <resource>
                           <directory>${project.basedir}/../console/src/main/resources/static/cpm/build</directory>
                           <filtering>false</filtering>
                       </resource>
                   </resources>
               </configuration>
           </execution>
       </executions>
   </plugin>
   ```
   


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