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 testProviderSuccess() throws Exception {
          IMetricManager metricManager = MetricManager.getIMetricManager();
          metricManager.clear();
          MetricsFilter metricsFilter = new MetricsFilter();
          Invocation invocation = new RpcInvocation("sayName", DemoService.class.getName(), "", new Class<?>[0], new Object[0]);
          RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345);
          RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER));
          AppResponse response = AppResponseBuilder.create()
              .build();
          onInvokeReturns(response);
          for (int i = 0; i < 100; i++) {
              metricsFilter.invoke(serviceInvoker, invocation);
          }
          FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR));
          FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER_METHOD, new HashMap<String, String>(4) {
              {
                  put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService");
                  put(METHOD, "void sayName()");
              }
          }, MetricLevel.NORMAL));
          long timestamp = System.currentTimeMillis() / 5000 * 5000;
          Assertions.assertEquals(100, dubboClient.getMethodCountPerCategory(0).get("success").get(timestamp));
          timestamp = timestamp / 15000 * 15000;
          Assertions.assertEquals(100, dubboMethod.getMethodCountPerCategory(0).get("success").get(timestamp));
      }
test_case.class_method_signature: MetricsFilterTest.testProviderSuccess()
test_case.full_signature: @Test public void testProviderSuccess()
test_case.identifier: testProviderSuccess
test_case.invocations: getIMetricManager clear getName setLocalAddress setRemoteAddress getContext getLocalHost getLocalHost setUrl getContext addParameter getUrl build create onInvokeReturns invoke getFastCompass getFastCompass put put currentTimeMillis assertEquals get get getMethodCountPerCategory assertEquals get get getMethodCountPerCategory
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testProviderSuccess()
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)