16
16
17
17
package com .alibaba .nacos .client .naming .remote .gprc ;
18
18
19
+ import com .alibaba .nacos .api .PropertyKeyConst ;
19
20
import com .alibaba .nacos .api .ability .constant .AbilityKey ;
20
21
import com .alibaba .nacos .api .ability .constant .AbilityStatus ;
21
22
import com .alibaba .nacos .api .common .Constants ;
@@ -94,6 +95,8 @@ public class NamingGrpcClientProxy extends AbstractNamingClientProxy {
94
95
95
96
private final NamingGrpcRedoService redoService ;
96
97
98
+ private boolean enableClientMetrics = true ;
99
+
97
100
public NamingGrpcClientProxy (String namespaceId , SecurityProxy securityProxy , ServerListFactory serverListFactory ,
98
101
NacosClientProperties properties , ServiceInfoHolder serviceInfoHolder ) throws NacosException {
99
102
super (securityProxy );
@@ -108,6 +111,8 @@ public NamingGrpcClientProxy(String namespaceId, SecurityProxy securityProxy, Se
108
111
.createGrpcClientConfig (properties .asProperties (), labels );
109
112
this .rpcClient = RpcClientFactory .createClient (uuid , ConnectionType .GRPC , grpcClientConfig );
110
113
this .redoService = new NamingGrpcRedoService (this , properties );
114
+ this .enableClientMetrics = Boolean .parseBoolean (
115
+ properties .getProperty (PropertyKeyConst .ENABLE_CLIENT_METRICS , "true" ));
111
116
NAMING_LOGGER .info ("Create naming rpc client for uuid->{}" , uuid );
112
117
start (serverListFactory , serviceInfoHolder );
113
118
}
@@ -478,13 +483,21 @@ private <T extends Response> T requestToServer(AbstractNamingRequest request, Cl
478
483
* @param response The response object containing registration result information, or null if registration failed.
479
484
*/
480
485
private void recordRequestFailedMetrics (AbstractNamingRequest request , Exception exception , Response response ) {
481
- if (Objects .isNull (response )) {
482
- MetricsMonitor .getNamingRequestFailedMonitor (request .getClass ().getSimpleName (), MONITOR_LABEL_NONE ,
483
- MONITOR_LABEL_NONE , exception .getClass ().getSimpleName ()).inc ();
484
- } else {
485
- MetricsMonitor .getNamingRequestFailedMonitor (request .getClass ().getSimpleName (),
486
- String .valueOf (response .getResultCode ()), String .valueOf (response .getErrorCode ()),
487
- MONITOR_LABEL_NONE ).inc ();
486
+ if (!enableClientMetrics ) {
487
+ return ;
488
+ }
489
+
490
+ try {
491
+ if (Objects .isNull (response )) {
492
+ MetricsMonitor .getNamingRequestFailedMonitor (request .getClass ().getSimpleName (), MONITOR_LABEL_NONE ,
493
+ MONITOR_LABEL_NONE , exception .getClass ().getSimpleName ()).inc ();
494
+ } else {
495
+ MetricsMonitor .getNamingRequestFailedMonitor (request .getClass ().getSimpleName (),
496
+ String .valueOf (response .getResultCode ()), String .valueOf (response .getErrorCode ()),
497
+ MONITOR_LABEL_NONE ).inc ();
498
+ }
499
+ } catch (Throwable t ) {
500
+ NAMING_LOGGER .warn ("Fail to record metrics for request {}" , request .getClass ().getSimpleName (), t );
488
501
}
489
502
}
490
503
0 commit comments