bitgorust opened a new issue, #13684:
URL: https://github.com/apache/dubbo/issues/13684

   <!-- If you need to report a security issue please visit 
https://github.com/apache/dubbo/security/policy -->
   
   - [x] I have searched the [issues](https://github.com/apache/dubbo/issues) 
of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 3.2.9
   * Operating System version: CentOS 8
   * Java version: Oracle JDK 8u221
   
   ### Steps to reproduce this issue
   
   1. set system property `dubbo.metrics.enabled=false`
   2. define dubbo references by exporting `ReferenceConfig.get()` as `Bean`s 
   3. start
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Behavior
   
   Project starts successfully. References created without metrics 
configuration.
   
   ### Actual Behavior
   
   References created with metrics enabled, but port is null.
   
   Exception trace:
   
   ```
   2024-01-22 17:55:47.207 |-ERROR [main] 
org.apache.dubbo.config.deploy.DefaultApplicationDeployer []-[traceId:] -|  
[DUBBO] Dubbo Application[1.1](qijian-rec-service-41-prod) an exception 
occurred when handle starting event, dubbo version: 3.2.9, current host: 
10.5.139.33, error code: 5-14. This may be caused by , go to 
https://dubbo.apache.org/faq/5/14 to find instructions. 
   java.lang.IllegalArgumentException: Metrics port cannot be null
        at org.apache.dubbo.common.utils.Assert.notEmptyString(Assert.java:33) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.AbstractInterfaceConfig.appendMetricsCompatible(AbstractInterfaceConfig.java:280)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ServiceConfig.buildAttributes(ServiceConfig.java:662) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:587)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:579) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:540) 
~[dubbo-3.2.9.jar:3.2.9]
        at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:340) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ServiceConfigBase.export(ServiceConfigBase.java:422) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter.export(ConfigurableMetadataServiceExporter.java:76)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.metadata.ExporterDeployListener.onModuleStarted(ExporterDeployListener.java:85)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultApplicationDeployer.exportMetadataService(DefaultApplicationDeployer.java:1263)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultApplicationDeployer.prepareApplicationInstance(DefaultApplicationDeployer.java:764)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultApplicationDeployer.checkState(DefaultApplicationDeployer.java:1149)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultApplicationDeployer.notifyModuleChanged(DefaultApplicationDeployer.java:1137)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultModuleDeployer.onModuleStarted(DefaultModuleDeployer.java:363)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultModuleDeployer.startSync(DefaultModuleDeployer.java:188)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:156)
 ~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:235) 
~[dubbo-3.2.9.jar:3.2.9]
        at 
org.apache.dubbo.config.ReferenceConfigBase.get(ReferenceConfigBase.java:395) 
~[dubbo-3.2.9.jar:3.2.9]
   ```
   
   ### Analysis
   
   In 
https://github.com/apache/dubbo/blob/2cf54f7947596abbf92f907853a2df7cbfc8b7fb/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java#L274-L277
 (though it is marked as deprecated but is still used now), `MetricsConfig` is 
got by `getConfigManager().getMetrics().orElse(null)`. Dive in we can know that 
the instance actually comes from 
https://github.com/apache/dubbo/blob/2cf54f7947596abbf92f907853a2df7cbfc8b7fb/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java#L294-L296.
 It is added here 
https://github.com/apache/dubbo/blob/2cf54f7947596abbf92f907853a2df7cbfc8b7fb/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java#L554-L566
 because the statement `ConfigurationUtils.hasSubProperties(configurationMaps, 
AbstractConfig.getTypePrefix(cls))` is `true` here, which I think it should do 
more than just looking for properties with `dubbo.metrics` prefix.
   
   ### Workaround
   
   Now we work it around by adding 
`org.apache.dubbo:dubbo-spring-boot-observability-starter` to avoid null port 
exceptions.
   
   ### Solution
   
   One reasonable solution I think is to add one more condition after 
https://github.com/apache/dubbo/blob/2cf54f7947596abbf92f907853a2df7cbfc8b7fb/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java#L554
 to check if contains `${prefix}.enabled=false` configuration. Or maybe some 
solutions are on the way as `appendMetricsCompatible` is deprecated.


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