hejianchao commented on a change in pull request #11913: URL: https://github.com/apache/flink/pull/11913#discussion_r415593198
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/util/MutableIOMetrics.java ########## @@ -96,41 +122,67 @@ public void addIOMetrics(AccessExecution attempt, @Nullable MetricFetcher fetche * In case a metric is missing for a parallel instance of a task, we set the complete flag as * false. */ - if (metrics.getMetric(MetricNames.IO_NUM_BYTES_IN) == null){ - this.numBytesInComplete = false; - } - else { - this.numBytesIn += Long.valueOf(metrics.getMetric(MetricNames.IO_NUM_BYTES_IN)); - } - - if (metrics.getMetric(MetricNames.IO_NUM_BYTES_OUT) == null){ - this.numBytesOutComplete = false; - } - else { - this.numBytesOut += Long.valueOf(metrics.getMetric(MetricNames.IO_NUM_BYTES_OUT)); - } - - if (metrics.getMetric(MetricNames.IO_NUM_RECORDS_IN) == null){ - this.numRecordsInComplete = false; - } - else { - this.numRecordsIn += Long.valueOf(metrics.getMetric(MetricNames.IO_NUM_RECORDS_IN)); - } - - if (metrics.getMetric(MetricNames.IO_NUM_RECORDS_OUT) == null){ - this.numRecordsOutComplete = false; - } - else { - this.numRecordsOut += Long.valueOf(metrics.getMetric(MetricNames.IO_NUM_RECORDS_OUT)); - } + update(metrics, MetricNames.IO_NUM_BYTES_IN, + (String value) -> this.numBytesInComplete = false, + (String value) -> this.numBytesIn += Long.valueOf(value) + ); + + update(metrics, MetricNames.IO_NUM_BYTES_OUT, + (String value) -> this.numBytesOutComplete = false, + (String value) -> this.numBytesOut += Long.valueOf(value) + ); + + update(metrics, MetricNames.IO_NUM_RECORDS_IN, + (String value) -> this.numRecordsInComplete = false, + (String value) -> this.numRecordsIn += Long.valueOf(value) + ); + + update(metrics, MetricNames.IO_NUM_RECORDS_OUT, + (String value) -> this.numRecordsOutComplete = false, + (String value) -> this.numRecordsOut += Long.valueOf(value) + ); + + update(metrics, MetricNames.USAGE_SHUFFLE_NETTY_INPUT_FLOATING_BUFFERS, + (String value) -> this.usageInputFloatingBuffersComplete = false, + (String value) -> this.usageInputFloatingBuffers += Float.valueOf(value) + ); + + update(metrics, MetricNames.USAGE_SHUFFLE_NETTY_INPUT_EXCLUSIVE_BUFFERS, + (String value) -> this.usageInputExclusiveBuffersComplete = false, + (String value) -> this.usageInputExclusiveBuffers += Float.valueOf(value) + ); + + update(metrics, MetricNames.USAGE_SHUFFLE_NETTY_OUTPUT_POOL_USAGE, + (String value) -> this.usageOutPoolComplete = false, + (String value) -> this.usageOutPool += Float.valueOf(value) + ); + + update(metrics, MetricNames.IS_BACKPRESSURED, + (String value) -> this.isBackPressuredComplete = false, + (String value) -> this.isBackPressured |= Boolean.valueOf(value) + ); } else { this.numBytesInComplete = false; this.numBytesOutComplete = false; this.numRecordsInComplete = false; this.numRecordsOutComplete = false; + this.usageInputFloatingBuffersComplete = false; + this.usageInputExclusiveBuffersComplete = false; + this.usageOutPoolComplete = false; + this.isBackPressuredComplete = false; } } } } + + private void update(MetricStore.ComponentMetricStore metrics, String metricKey, Consumer<String> emptyFunction, Consumer<String> noEmptyFunction) { Review comment: The introduction of this method is a good refactoring, 👍. Better to change to multiple lines. Maybe rename `noEmptyFunction` to `nonEmptyFunction`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org