You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/10/23 08:22:46 UTC

[incubator-servicecomb-java-chassis] 04/08: [SCB-837] make http2 production ready: optimize endpointMetric set logic

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 4049e39ad17c6d63a0631c24b047ca34c3e64d98
Author: heyile <he...@huawei.com>
AuthorDate: Thu Oct 11 07:17:22 2018 +0800

    [SCB-837] make http2 production ready: optimize endpointMetric set logic
---
 .../vertx/metrics/DefaultHttpClientMetrics.java    | 28 +++++++---------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java
index 71d4ca1..3fb9af3 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/metrics/DefaultHttpClientMetrics.java
@@ -27,7 +27,6 @@ import io.vertx.core.http.HttpClientOptions;
 import io.vertx.core.http.HttpClientRequest;
 import io.vertx.core.http.HttpClientResponse;
 import io.vertx.core.http.WebSocket;
-import io.vertx.core.http.impl.HttpClientImpl;
 import io.vertx.core.net.SocketAddress;
 import io.vertx.core.net.impl.SocketAddressImpl;
 import io.vertx.core.spi.metrics.HttpClientMetrics;
@@ -83,13 +82,9 @@ public class DefaultHttpClientMetrics implements
 
   @Override
   public void endpointConnected(DefaultClientEndpointMetric endpointMetric, DefaultHttpSocketMetric socketMetric) {
-    //only http1.1 will invoke this method, just make a check
-    if (endpointMetric != null) {
-      if (endpointMetric != socketMetric.getEndpointMetric()) {
-        socketMetric.setEndpointMetric(endpointMetric);
-      }
-      endpointMetric.onConnect();
-    }
+    // as http2 client will not invoke this method, the endpointMetric info will lost.
+    // you can get more details from https://github.com/eclipse-vertx/vert.x/issues/2660
+    // hence, we will set endpointMetric info in the method connected(SocketAddress remoteAddress, String remoteName)
   }
 
   @Override
@@ -144,18 +139,11 @@ public class DefaultHttpClientMetrics implements
 
   @Override
   public DefaultHttpSocketMetric connected(SocketAddress remoteAddress, String remoteName) {
-
-    DefaultHttpSocketMetric socketMetric = new DefaultHttpSocketMetric(null);
-    try {
-      DefaultHttpClientMetrics clientMetrics = (DefaultHttpClientMetrics) ((HttpClientImpl) client).getMetrics();
-      DefaultClientEndpointMetric clientEndpointMetric = clientMetrics.clientEndpointMetricManager
-          .getClientEndpointMetricMap().get(remoteAddress);
-      // set endPointMetric when use http2
-      socketMetric.setEndpointMetric(clientEndpointMetric);
-    } catch (Exception e) {
-      LOGGER.warn("if you use http2, there may cause a null pointer exception. {}/{}", remoteAddress, remoteName);
-    }
-    return socketMetric;
+    //we can get endpointMetric info here, so set the endpointMetric info directly
+    DefaultClientEndpointMetric clientEndpointMetric = this.clientEndpointMetricManager
+        .getClientEndpointMetric(remoteAddress);
+    clientEndpointMetric.onConnect();
+    return new DefaultHttpSocketMetric(clientEndpointMetric);
   }
 
   @Override