wxbty commented on code in PR #12892: URL: https://github.com/apache/dubbo/pull/12892#discussion_r1294638053
########## dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java: ########## @@ -123,12 +124,56 @@ public boolean isSupport(MetricsEvent event) { public void onEvent(RequestEvent event) { if (enableQps) { MethodMetric metric = calcWindowCounter(event, MetricsKey.METRIC_REQUESTS); + if(event instanceof RequestInitEvent) { + onInitMetricRequest(event); + onInitQpsRequest(metric); + onInitRtRequest(metric); + onInitRtAgrRequest(metric); + return; + } TimeWindowCounter qpsCounter = ConcurrentHashMapUtils.computeIfAbsent(qps, metric, methodMetric -> new TimeWindowCounter(bucketNum, qpsTimeWindowMillSeconds)); qpsCounter.increment(); } } + public void onInitMetricRequest(RequestEvent event){ + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_TOTAL_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_SUCCEED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_FAILED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUEST_BUSINESS_FAILED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_TIMEOUT_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_LIMIT_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_TOTAL_FAILED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_NETWORK_FAILED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_CODEC_FAILED_AGG); + initWindowCounter(event,MetricsKey.METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG); + } Review Comment: These constants can be placed in DefaultConstants in the form of List, and then foreach does init, which can reduce duplication ########## dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java: ########## @@ -54,6 +55,13 @@ public void initWrapper(List<MetricsKeyWrapper> metricsKeyWrappers) { metricsKeyWrappers.forEach(appKey -> methodNumStats.put(appKey, new ConcurrentHashMap<>())); } + public void initMethodKey(MetricsKeyWrapper wrapper, Invocation invocation, int size) { + if (!methodNumStats.containsKey(wrapper)) { + return; + } + methodNumStats.get(wrapper).computeIfAbsent(new MethodMetric(getApplicationModel(), invocation), k -> new AtomicLong(0L)).set(size); + } + Review Comment: The init method can directly set 0, no need to transfer parameters ########## dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/AggregateMetricsCollector.java: ########## @@ -123,12 +124,56 @@ public boolean isSupport(MetricsEvent event) { public void onEvent(RequestEvent event) { if (enableQps) { MethodMetric metric = calcWindowCounter(event, MetricsKey.METRIC_REQUESTS); + if(event instanceof RequestInitEvent) { + onInitMetricRequest(event); + onInitQpsRequest(metric); + onInitRtRequest(metric); + onInitRtAgrRequest(metric); + return; + } Review Comment: RequestInitEvent and RequestEvent look different, one is triggered by app init, the other is triggered by rpc request, is it better to separate the listener? -- 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: notifications-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org