XComp commented on code in PR #23737: URL: https://github.com/apache/flink/pull/23737#discussion_r1396275250
########## flink-tests/src/test/java/org/apache/flink/test/streaming/runtime/SinkV2MetricsITCase.java: ########## @@ -228,32 +228,54 @@ private void assertSinkCommitterMetrics( for (OperatorMetricGroup group : groups) { Map<String, Metric> metrics = reporter.getMetricsByGroup(group); - aggregated.merge( - MetricNames.SUCCESSFUL_COMMITTABLES, - ((Counter) metrics.get(MetricNames.SUCCESSFUL_COMMITTABLES)).getCount(), - Long::sum); - aggregated.merge( - MetricNames.ALREADY_COMMITTED_COMMITTABLES, - ((Counter) metrics.get(MetricNames.ALREADY_COMMITTED_COMMITTABLES)).getCount(), - Long::sum); - aggregated.merge( - MetricNames.RETRIED_COMMITTABLES, - ((Counter) metrics.get(MetricNames.RETRIED_COMMITTABLES)).getCount(), - Long::sum); - aggregated.merge( - MetricNames.FAILED_COMMITTABLES, - ((Counter) metrics.get(MetricNames.FAILED_COMMITTABLES)).getCount(), - Long::sum); - aggregated.merge( - MetricNames.TOTAL_COMMITTABLES, - ((Counter) metrics.get(MetricNames.TOTAL_COMMITTABLES)).getCount(), - Long::sum); - aggregated.merge( - MetricNames.PENDING_COMMITTABLES, - ((Gauge<Integer>) metrics.get(MetricNames.PENDING_COMMITTABLES)) - .getValue() - .longValue(), - Long::sum); + if (metrics == null) { + continue; + } + + Counter successCounter = (Counter) metrics.get(MetricNames.SUCCESSFUL_COMMITTABLES); Review Comment: Can't we move the following lines into a single for loop? ```java for (String metricName : Arrays.asList( MetricNames.SUCCESSFUL_COMMITTABLES, MetricNames.ALREADY_COMMITTED_COMMITTABLES, MetricNames.RETRIED_COMMITTABLES, MetricNames.FAILED_COMMITTABLES, MetricNames.TOTAL_COMMITTABLES)) { final Counter counter = (Counter) metrics.get(metricName); if (counter != null) { aggregated.merge(metricName, counter.getCount(), Long::sum); } } ``` I'm wondering whether we could reduce the code redundancy here a bit. Only `PENDING_COMMITTABLES` would have to be handled separately as far as I can see. That would only work if my [remark above](https://github.com/apache/flink/pull/23737#discussion_r1396272660) is correct. WDYT? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org