test_class.declarator: serviceInvoker
test_class.modifier: private
test_class.original_string: private Invoker<DemoService> serviceInvoker;
test_class.type: Invoker<DemoService>
test_class.var_name: serviceInvoker
test_class.declarator: timeoutInvoker = new Invoker<DemoService>() {
          @Override
          public Class<DemoService> getInterface() {
              return DemoService.class;
          }
  
          public URL getUrl() {
              return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/org.apache.dubbo.monitor.dubbo.service.DemoService");
          }
  
          @Override
          public boolean isAvailable() {
              return false;
          }
  
          @Override
          public Result invoke(Invocation invocation) throws RpcException {
              throw new RpcException(RpcException.TIMEOUT_EXCEPTION);
          }
  
          @Override
          public void destroy() {
          }
      }
test_class.modifier: private final
test_class.original_string: private final Invoker<DemoService> timeoutInvoker = new Invoker<DemoService>() {
          @Override
          public Class<DemoService> getInterface() {
              return DemoService.class;
          }
  
          public URL getUrl() {
              return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/org.apache.dubbo.monitor.dubbo.service.DemoService");
          }
  
          @Override
          public boolean isAvailable() {
              return false;
          }
  
          @Override
          public Result invoke(Invocation invocation) throws RpcException {
              throw new RpcException(RpcException.TIMEOUT_EXCEPTION);
          }
  
          @Override
          public void destroy() {
          }
      };
test_class.type: Invoker<DemoService>
test_class.var_name: timeoutInvoker
test_class.file: dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java
test_class.identifier: MetricsFilterTest
test_case.body: @Test
      public void testInvokeMetricsMethodService() {
          IMetricManager metricManager = MetricManager.getIMetricManager();
          metricManager.clear();
          MetricsFilter metricsFilter = new MetricsFilter();
          Invocation sayNameInvocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
          Invocation echoInvocation = new RpcInvocation("echo", DemoService.class.getName(), "", new Class<?>[]{Integer.class}, new Integer[]{1});
          RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
          RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER_SIDE)
                  .addParameter(TIMEOUT_KEY, 300));
          AppResponse response = AppResponseBuilder.create()
                  .build();
          onInvokeReturns(response);
          for (int i = 0; i < 50; i++) {
              metricsFilter.invoke(serviceInvoker, sayNameInvocation);
              metricsFilter.invoke(serviceInvoker, echoInvocation);
              try {
                  metricsFilter.invoke(timeoutInvoker, sayNameInvocation);
              } catch (RpcException e) {
                  // ignore
              }
              try {
                  metricsFilter.invoke(timeoutInvoker, echoInvocation);
              } catch (RpcException e) {
                  // ignore
              }
          }
  
          Protocol protocol = new DubboProtocol();
          URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":20880/" + MetricsService.class.getName());
          Invoker<MetricsService> invoker = protocol.refer(MetricsService.class, url);
          Invocation invocation = new RpcInvocation("getMetricsByGroup", DemoService.class.getName(), "", new Class<?>[]{String.class}, new Object[]{DUBBO_GROUP});
          try {
              Thread.sleep(15000);
          } catch (Exception e) {
              // ignore
          }
          String resStr = invoker.invoke(invocation).getValue().toString();
          List<MetricObject> metricObjectList = new Gson().fromJson(resStr, new TypeToken<List<MetricObject>>() {
          }.getType());
          Map<String, Map<String, Object>> methodMetricMap = new HashMap<>();
          for (int i = 0; i < metricObjectList.size(); i++) {
              MetricObject object = metricObjectList.get(i);
              String service = object.getTags().get("service");
              String method = service + "." + object.getTags().get("method");
              String metric = object.getMetric().substring(object.getMetric().lastIndexOf(".") + 1);
              Map map = methodMetricMap.get(method);
              if (map == null) {
                  map = new HashMap();
                  methodMetricMap.put(method, map);
              }
              map.put(metric, object.getValue());
          }
  
          Assertions.assertEquals(50.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void sayName()").get("success_bucket_count"));
          Assertions.assertEquals(50.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void echo(Integer)").get("success_bucket_count"));
  
          Assertions.assertEquals(50.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void sayName()").get("timeoutError_bucket_count"));
          Assertions.assertEquals(50.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void echo(Integer)").get("timeoutError_bucket_count"));
  
          Assertions.assertEquals(100.0 / 15,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void sayName()").get("qps"));
          Assertions.assertEquals(100.0 / 15,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void echo(Integer)").get("qps"));
  
          Assertions.assertEquals(50.0 / 100.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void sayName()").get("success_rate"));
          Assertions.assertEquals(50.0 / 100.0,
              methodMetricMap.get("org.apache.dubbo.monitor.dubbo.service.DemoService.void echo(Integer)").get("success_rate"));
      }
test_case.class_method_signature: MetricsFilterTest.testInvokeMetricsMethodService()
test_case.full_signature: @Test public void testInvokeMetricsMethodService()
test_case.identifier: testInvokeMetricsMethodService
test_case.invocations: getIMetricManager clear getName getName setLocalAddress setRemoteAddress getContext getLocalHost getLocalHost setUrl getContext addParameter addParameter getUrl build create onInvokeReturns invoke invoke invoke invoke valueOf getHostName getLocalAddress getName refer getName sleep toString getValue invoke fromJson getType size get get getTags get getTags substring getMetric lastIndexOf getMetric get put put getValue assertEquals get get assertEquals get get assertEquals get get assertEquals get get assertEquals get get assertEquals get get assertEquals get get assertEquals get get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInvokeMetricsMethodService()
focal_class.declarator: logger = LoggerFactory.getLogger(MetricsFilter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(MetricsFilter.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: exported = new AtomicBoolean(false)
focal_class.modifier: private static volatile
focal_class.original_string: private static volatile AtomicBoolean exported = new AtomicBoolean(false);
focal_class.type: AtomicBoolean
focal_class.var_name: exported
focal_class.declarator: port
focal_class.modifier: private
focal_class.original_string: private Integer port;
focal_class.type: Integer
focal_class.var_name: port
focal_class.declarator: protocolName
focal_class.modifier: private
focal_class.original_string: private String protocolName;
focal_class.type: String
focal_class.var_name: protocolName
focal_class.file: dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java
focal_class.identifier: MetricsFilter
focal_class.interfaces: implements Filter
focal_class.class_method_signature: MetricsFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_class.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (Invoker<?> invoker, Invocation invocation)
focal_class.return: Result
focal_class.signature: Result invoke(Invoker<?> invoker, Invocation invocation)
focal_class.class_method_signature: MetricsFilter.buildMethodName(Invocation invocation)
focal_class.full_signature: private String buildMethodName(Invocation invocation)
focal_class.identifier: buildMethodName
focal_class.modifiers: private
focal_class.parameters: (Invocation invocation)
focal_class.return: String
focal_class.signature: String buildMethodName(Invocation invocation)
focal_class.class_method_signature: MetricsFilter.reportMetrics(Invoker<?> invoker, Invocation invocation, long duration, String result, boolean isProvider)
focal_class.full_signature: private void reportMetrics(Invoker<?> invoker, Invocation invocation, long duration, String result, boolean isProvider)
focal_class.identifier: reportMetrics
focal_class.modifiers: private
focal_class.parameters: (Invoker<?> invoker, Invocation invocation, long duration, String result, boolean isProvider)
focal_class.return: void
focal_class.signature: void reportMetrics(Invoker<?> invoker, Invocation invocation, long duration, String result, boolean isProvider)
focal_class.class_method_signature: MetricsFilter.setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames)
focal_class.full_signature: private void setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames)
focal_class.identifier: setCompassQuantity
focal_class.modifiers: private
focal_class.parameters: (String groupName, String result, long duration, MetricName... metricNames)
focal_class.return: void
focal_class.signature: void setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames)
focal_class.class_method_signature: MetricsFilter.getThreadPoolMessage()
focal_class.full_signature: private List<MetricObject> getThreadPoolMessage()
focal_class.identifier: getThreadPoolMessage
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: List<MetricObject>
focal_class.signature: List<MetricObject> getThreadPoolMessage()
focal_class.class_method_signature: MetricsFilter.value2MetricObject(String metric, Integer value, MetricLevel level)
focal_class.full_signature: private MetricObject value2MetricObject(String metric, Integer value, MetricLevel level)
focal_class.identifier: value2MetricObject
focal_class.modifiers: private
focal_class.parameters: (String metric, Integer value, MetricLevel level)
focal_class.return: MetricObject
focal_class.signature: MetricObject value2MetricObject(String metric, Integer value, MetricLevel level)
focal_class.class_method_signature: MetricsFilter.initMetricsInvoker()
focal_class.full_signature: private Invoker<MetricsService> initMetricsInvoker()
focal_class.identifier: initMetricsInvoker
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Invoker<MetricsService>
focal_class.signature: Invoker<MetricsService> initMetricsInvoker()
focal_method.body: @Override
      public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
          if (exported.compareAndSet(false, true)) {
              this.protocolName = invoker.getUrl().getParameter(METRICS_PROTOCOL) == null ?
                      DEFAULT_PROTOCOL : invoker.getUrl().getParameter(METRICS_PROTOCOL);
  
              Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(protocolName);
  
              this.port = invoker.getUrl().getParameter(METRICS_PORT) == null ?
                      protocol.getDefaultPort() : Integer.valueOf(invoker.getUrl().getParameter(METRICS_PORT));
  
              Invoker<MetricsService> metricsInvoker = initMetricsInvoker();
  
              try {
                  protocol.export(metricsInvoker);
              } catch (RuntimeException e) {
                  logger.error("Metrics Service need to be configured" +
                          " when multiple processes are running on a host" + e.getMessage());
              }
          }
  
          RpcContext context = RpcContext.getContext();
          boolean isProvider = context.isProviderSide();
          long start = System.currentTimeMillis();
          try {
              Result result = invoker.invoke(invocation); // proceed invocation chain
              long duration = System.currentTimeMillis() - start;
              reportMetrics(invoker, invocation, duration, "success", isProvider);
              return result;
          } catch (RpcException e) {
              long duration = System.currentTimeMillis() - start;
              String result = "error";
              if (e.isTimeout()) {
                  result = "timeoutError";
              }
              if (e.isBiz()) {
                  result = "bisError";
              }
              if (e.isNetwork()) {
                  result = "networkError";
              }
              if (e.isSerialization()) {
                  result = "serializationError";
              }
              reportMetrics(invoker, invocation, duration, result, isProvider);
              throw e;
          }
      }
focal_method.class_method_signature: MetricsFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_method.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_method.identifier: invoke
focal_method.invocations: compareAndSet getParameter getUrl getParameter getUrl getExtension getExtensionLoader getParameter getUrl getDefaultPort valueOf getParameter getUrl initMetricsInvoker export error getMessage getContext isProviderSide currentTimeMillis invoke currentTimeMillis reportMetrics currentTimeMillis isTimeout isBiz isNetwork isSerialization reportMetrics
focal_method.modifiers: @Override public
focal_method.parameters: (Invoker<?> invoker, Invocation invocation)
focal_method.return: Result
focal_method.signature: Result invoke(Invoker<?> invoker, Invocation invocation)