You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/01 03:51:29 UTC

[GitHub] [flink] KarmaGYZ opened a new pull request, #20123: [FLINK-28310][rest] Introduce aggregating task metrics

KarmaGYZ opened a new pull request, #20123:
URL: https://github.com/apache/flink/pull/20123

   We add AggregatedTaskDetailsInfo to JobVertexTaskManagersHandler and JobVertexDetailsHandler
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)*
   
   
   ## Brief change log
   
   *(for example:)*
     - *The TaskInfo is stored in the blob store on job creation time as a persistent artifact*
     - *Deployments RPC transmits only the blob storage reference*
     - *TaskManagers retrieve the TaskInfo from the blob cache*
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (100MB)*
     - *Extended integration test for recovery after master (JobManager) failure*
     - *Added test that validates that TaskInfo is transferred only once across recoveries*
     - *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no)
     - The serializers: (yes / no / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / no / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
     - The S3 file system connector: (yes / no / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] KarmaGYZ commented on pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
KarmaGYZ commented on PR #20123:
URL: https://github.com/apache/flink/pull/20123#issuecomment-1173255081

   PR updated.


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] xintongsong commented on a diff in pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
xintongsong commented on code in PR #20123:
URL: https://github.com/apache/flink/pull/20123#discussion_r911789935


##########
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfo.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.commons.math3.stat.descriptive.rank.Percentile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/** Aggregated info of a set of tasks. */
+public class AggregatedTaskDetailsInfo implements ResponseBody {
+    public static final String FIELD_NAME_METRICS = "metrics";
+    public static final String FIELD_NAME_STATUS_DURATION = "status-duration";
+
+    private static final String[] metricsNames = {
+        IOMetricsInfo.FIELD_NAME_BYTES_READ,
+        IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_RECORDS_READ,
+        IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE,
+        IOMetricsInfo.FIELD_NAME_ACC_BUSY,
+        IOMetricsInfo.FIELD_NAME_ACC_IDLE
+    };
+
+    private static final String[] statusNames = {
+        ExecutionState.CREATED.name(),
+        ExecutionState.SCHEDULED.name(),
+        ExecutionState.INITIALIZING.name(),
+        ExecutionState.DEPLOYING.name(),
+        ExecutionState.RUNNING.name()
+    };
+
+    @JsonProperty(FIELD_NAME_METRICS)
+    private final Map<String, Map<String, Long>> metrics;
+
+    @JsonProperty(FIELD_NAME_STATUS_DURATION)
+    private final Map<String, Map<String, Long>> statusDuration;
+
+    @JsonCreator
+    public AggregatedTaskDetailsInfo(
+            @JsonProperty(FIELD_NAME_METRICS) Map<String, Map<String, Long>> metrics,
+            @JsonProperty(FIELD_NAME_STATUS_DURATION)
+                    Map<String, Map<String, Long>> statusDuration) {
+        this.metrics = Preconditions.checkNotNull(metrics);
+        this.statusDuration = Preconditions.checkNotNull(statusDuration);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        AggregatedTaskDetailsInfo that = (AggregatedTaskDetailsInfo) o;
+        return Objects.equals(metrics, that.metrics)
+                && Objects.equals(statusDuration, that.statusDuration);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(metrics, statusDuration);
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<SubtaskExecutionAttemptDetailsInfo> subtaskInfo) {
+        return create(
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getIoMetricsInfo)
+                        .collect(Collectors.toList()),
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getStatusDuration)
+                        .collect(Collectors.toList()));
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<IOMetricsInfo> ioMetricsInfos, List<Map<ExecutionState, Long>> statusDurations) {
+        Map<String, MetricsStatistics> metrics = new HashMap<>();
+        Map<String, MetricsStatistics> statusDuration = new HashMap<>();
+        Arrays.stream(metricsNames).forEach(name -> metrics.put(name, new MetricsStatistics(name)));
+        Arrays.stream(statusNames)
+                .forEach(name -> statusDuration.put(name, new MetricsStatistics(name)));
+
+        ioMetricsInfos.forEach(
+                ioMetricsInfo -> {
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_READ)
+                            .addValue(ioMetricsInfo.getBytesRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN)
+                            .addValue(ioMetricsInfo.getBytesWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_READ)
+                            .addValue(ioMetricsInfo.getRecordsRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN)
+                            .addValue(ioMetricsInfo.getRecordsWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_IDLE)
+                            .addValue(ioMetricsInfo.getAccumulatedIdle());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE)
+                            .addValue(ioMetricsInfo.getAccumulatedBackpressured());
+                    if (!Double.isNaN(ioMetricsInfo.getAccumulatedBusy())) {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY)
+                                .addValue((long) ioMetricsInfo.getAccumulatedBusy());
+                    } else {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY).addValue(-1);
+                    }
+                });
+
+        statusDurations.forEach(
+                status -> {
+                    statusDuration
+                            .get(ExecutionState.CREATED.name())
+                            .addValue(status.get(ExecutionState.CREATED));
+                    statusDuration
+                            .get(ExecutionState.SCHEDULED.name())
+                            .addValue(status.get(ExecutionState.SCHEDULED));
+                    statusDuration
+                            .get(ExecutionState.INITIALIZING.name())
+                            .addValue(status.get(ExecutionState.INITIALIZING));
+                    statusDuration
+                            .get(ExecutionState.DEPLOYING.name())
+                            .addValue(status.get(ExecutionState.DEPLOYING));
+                    statusDuration
+                            .get(ExecutionState.RUNNING.name())
+                            .addValue(status.get(ExecutionState.RUNNING));
+                });
+        return new AggregatedTaskDetailsInfo(
+                metrics.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)),
+                statusDuration.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)));
+    }
+
+    @VisibleForTesting
+    static class MetricsStatistics {
+        private final List<Long> values = new ArrayList<>();
+        private final String name;
+        private boolean sorted = false;
+        private long sum = 0;
+        private Percentile percentile = null;
+
+        MetricsStatistics(String name) {
+            this.name = name;
+        }
+
+        void addValue(long value) {
+            values.add(value);
+            sum += value;
+            sorted = false;
+        }
+
+        private String getName() {
+            return name;
+        }
+
+        private Map<String, Long> toMap() {
+            Map<String, Long> result = new HashMap<>();
+            result.put("min", getMin());
+            result.put("max", getMax());
+            result.put("avg", getAvg());
+            result.put("sum", getSum());
+            result.put("median", getMedian());
+            result.put("p25", getPercentile(25));
+            result.put("p75", getPercentile(75));
+            result.put("p95", getPercentile(95));
+            return result;
+        }
+
+        long getMin() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty() ? 0 : values.get(0);
+        }
+
+        long getMax() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty() ? 0 : values.get(values.size() - 1);
+        }

Review Comment:
   With `Percentile`, we no longer need to order the entire list.
   
   Min/max can be simplified as:
   ```
   values.stream()
              .reduce(BinaryOperator.minBy(Comparator.naturalOrder()))
              .orElse(0L);
   ```



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] xintongsong commented on a diff in pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
xintongsong commented on code in PR #20123:
URL: https://github.com/apache/flink/pull/20123#discussion_r911789155


##########
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfo.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.apache.commons.math3.stat.descriptive.rank.Percentile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/** Aggregated info of a set of tasks. */
+public class AggregatedTaskDetailsInfo implements ResponseBody {
+    public static final String FIELD_NAME_METRICS = "metrics";
+    public static final String FIELD_NAME_STATUS_DURATION = "status-duration";
+
+    private static final String[] metricsNames = {
+        IOMetricsInfo.FIELD_NAME_BYTES_READ,
+        IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_RECORDS_READ,
+        IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE,
+        IOMetricsInfo.FIELD_NAME_ACC_BUSY,
+        IOMetricsInfo.FIELD_NAME_ACC_IDLE
+    };
+
+    private static final String[] statusNames = {
+        ExecutionState.CREATED.name(),
+        ExecutionState.SCHEDULED.name(),
+        ExecutionState.INITIALIZING.name(),
+        ExecutionState.DEPLOYING.name(),
+        ExecutionState.RUNNING.name()
+    };
+
+    @JsonProperty(FIELD_NAME_METRICS)
+    private final Map<String, Map<String, Long>> metrics;
+
+    @JsonProperty(FIELD_NAME_STATUS_DURATION)
+    private final Map<String, Map<String, Long>> statusDuration;
+
+    @JsonCreator
+    public AggregatedTaskDetailsInfo(
+            @JsonProperty(FIELD_NAME_METRICS) Map<String, Map<String, Long>> metrics,
+            @JsonProperty(FIELD_NAME_STATUS_DURATION)
+                    Map<String, Map<String, Long>> statusDuration) {
+        this.metrics = Preconditions.checkNotNull(metrics);
+        this.statusDuration = Preconditions.checkNotNull(statusDuration);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        AggregatedTaskDetailsInfo that = (AggregatedTaskDetailsInfo) o;
+        return Objects.equals(metrics, that.metrics)
+                && Objects.equals(statusDuration, that.statusDuration);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(metrics, statusDuration);
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<SubtaskExecutionAttemptDetailsInfo> subtaskInfo) {
+        return create(
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getIoMetricsInfo)
+                        .collect(Collectors.toList()),
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getStatusDuration)
+                        .collect(Collectors.toList()));
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<IOMetricsInfo> ioMetricsInfos, List<Map<ExecutionState, Long>> statusDurations) {
+        Map<String, MetricsStatistics> metrics = new HashMap<>();
+        Map<String, MetricsStatistics> statusDuration = new HashMap<>();
+        Arrays.stream(metricsNames).forEach(name -> metrics.put(name, new MetricsStatistics(name)));
+        Arrays.stream(statusNames)
+                .forEach(name -> statusDuration.put(name, new MetricsStatistics(name)));
+
+        ioMetricsInfos.forEach(
+                ioMetricsInfo -> {
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_READ)
+                            .addValue(ioMetricsInfo.getBytesRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN)
+                            .addValue(ioMetricsInfo.getBytesWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_READ)
+                            .addValue(ioMetricsInfo.getRecordsRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN)
+                            .addValue(ioMetricsInfo.getRecordsWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_IDLE)
+                            .addValue(ioMetricsInfo.getAccumulatedIdle());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE)
+                            .addValue(ioMetricsInfo.getAccumulatedBackpressured());
+                    if (!Double.isNaN(ioMetricsInfo.getAccumulatedBusy())) {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY)
+                                .addValue((long) ioMetricsInfo.getAccumulatedBusy());
+                    } else {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY).addValue(-1);
+                    }
+                });
+
+        statusDurations.forEach(
+                status -> {
+                    statusDuration
+                            .get(ExecutionState.CREATED.name())
+                            .addValue(status.get(ExecutionState.CREATED));
+                    statusDuration
+                            .get(ExecutionState.SCHEDULED.name())
+                            .addValue(status.get(ExecutionState.SCHEDULED));
+                    statusDuration
+                            .get(ExecutionState.INITIALIZING.name())
+                            .addValue(status.get(ExecutionState.INITIALIZING));
+                    statusDuration
+                            .get(ExecutionState.DEPLOYING.name())
+                            .addValue(status.get(ExecutionState.DEPLOYING));
+                    statusDuration
+                            .get(ExecutionState.RUNNING.name())
+                            .addValue(status.get(ExecutionState.RUNNING));
+                });
+        return new AggregatedTaskDetailsInfo(
+                metrics.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)),
+                statusDuration.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)));
+    }
+
+    @VisibleForTesting
+    static class MetricsStatistics {
+        private final List<Long> values = new ArrayList<>();
+        private final String name;
+        private boolean sorted = false;
+        private long sum = 0;
+        private Percentile percentile = null;
+
+        MetricsStatistics(String name) {
+            this.name = name;
+        }
+
+        void addValue(long value) {
+            values.add(value);
+            sum += value;
+            sorted = false;
+        }
+
+        private String getName() {
+            return name;
+        }
+
+        private Map<String, Long> toMap() {
+            Map<String, Long> result = new HashMap<>();
+            result.put("min", getMin());
+            result.put("max", getMax());
+            result.put("avg", getAvg());
+            result.put("sum", getSum());
+            result.put("median", getMedian());

Review Comment:
   `getMedian()` can be replaced by `getPercentile(50)`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] reswqa commented on a diff in pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
reswqa commented on code in PR #20123:
URL: https://github.com/apache/flink/pull/20123#discussion_r912152898


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfoTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests for the {@link AggregatedTaskDetailsInfo}. */
+public class AggregatedTaskDetailsInfoTest

Review Comment:
   A friendly reminder: The newly introduced test class needs to use junit5 and assertj, [refer here](https://flink.apache.org/contributing/code-style-and-quality-common.html#testing)



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] KarmaGYZ closed pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
KarmaGYZ closed pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics
URL: https://github.com/apache/flink/pull/20123


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] xintongsong commented on a diff in pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
xintongsong commented on code in PR #20123:
URL: https://github.com/apache/flink/pull/20123#discussion_r911663772


##########
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfo.java:
##########
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/** Aggregated info of a set of tasks. */
+public class AggregatedTaskDetailsInfo implements ResponseBody {
+    public static final String FIELD_NAME_METRICS = "metrics";
+    public static final String FIELD_NAME_STATUS_DURATION = "status-duration";
+
+    private static final String[] metricsNames = {
+        IOMetricsInfo.FIELD_NAME_BYTES_READ,
+        IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_RECORDS_READ,
+        IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE,
+        IOMetricsInfo.FIELD_NAME_ACC_BUSY,
+        IOMetricsInfo.FIELD_NAME_ACC_IDLE
+    };
+
+    private static final String[] statusNames = {
+        ExecutionState.CREATED.name(),
+        ExecutionState.SCHEDULED.name(),
+        ExecutionState.INITIALIZING.name(),
+        ExecutionState.DEPLOYING.name(),
+        ExecutionState.RUNNING.name()
+    };
+
+    @JsonProperty(FIELD_NAME_METRICS)
+    private final Map<String, Map<String, Long>> metrics;
+
+    @JsonProperty(FIELD_NAME_STATUS_DURATION)
+    private final Map<String, Map<String, Long>> statusDuration;
+
+    @JsonCreator
+    public AggregatedTaskDetailsInfo(
+            @JsonProperty(FIELD_NAME_METRICS) Map<String, Map<String, Long>> metrics,
+            @JsonProperty(FIELD_NAME_STATUS_DURATION)
+                    Map<String, Map<String, Long>> statusDuration) {
+        this.metrics = Preconditions.checkNotNull(metrics);
+        this.statusDuration = Preconditions.checkNotNull(statusDuration);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        AggregatedTaskDetailsInfo that = (AggregatedTaskDetailsInfo) o;
+        return Objects.equals(metrics, that.metrics)
+                && Objects.equals(statusDuration, that.statusDuration);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(metrics, statusDuration);
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<SubtaskExecutionAttemptDetailsInfo> subtaskInfo) {
+        return create(
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getIoMetricsInfo)
+                        .collect(Collectors.toList()),
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getStatusDuration)
+                        .collect(Collectors.toList()));
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<IOMetricsInfo> ioMetricsInfos, List<Map<ExecutionState, Long>> statusDurations) {
+        Map<String, MetricsStatistics> metrics = new HashMap<>();
+        Map<String, MetricsStatistics> statusDuration = new HashMap<>();
+        Arrays.stream(metricsNames).forEach(name -> metrics.put(name, new MetricsStatistics(name)));
+        Arrays.stream(statusNames)
+                .forEach(name -> statusDuration.put(name, new MetricsStatistics(name)));
+
+        ioMetricsInfos.forEach(
+                ioMetricsInfo -> {
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_READ)
+                            .addValue(ioMetricsInfo.getBytesRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN)
+                            .addValue(ioMetricsInfo.getBytesWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_READ)
+                            .addValue(ioMetricsInfo.getRecordsRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN)
+                            .addValue(ioMetricsInfo.getRecordsWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_IDLE)
+                            .addValue(ioMetricsInfo.getAccumulatedIdle());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE)
+                            .addValue(ioMetricsInfo.getAccumulatedBackpressured());
+                    if (!Double.isNaN(ioMetricsInfo.getAccumulatedBusy())) {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY)
+                                .addValue((long) ioMetricsInfo.getAccumulatedBusy());
+                    } else {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY).addValue(-1);
+                    }
+                });
+
+        statusDurations.forEach(
+                status -> {
+                    statusDuration
+                            .get(ExecutionState.CREATED.name())
+                            .addValue(status.get(ExecutionState.CREATED));
+                    statusDuration
+                            .get(ExecutionState.SCHEDULED.name())
+                            .addValue(status.get(ExecutionState.SCHEDULED));
+                    statusDuration
+                            .get(ExecutionState.INITIALIZING.name())
+                            .addValue(status.get(ExecutionState.INITIALIZING));
+                    statusDuration
+                            .get(ExecutionState.DEPLOYING.name())
+                            .addValue(status.get(ExecutionState.DEPLOYING));
+                    statusDuration
+                            .get(ExecutionState.RUNNING.name())
+                            .addValue(status.get(ExecutionState.RUNNING));
+                });
+        return new AggregatedTaskDetailsInfo(
+                metrics.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)),
+                statusDuration.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)));
+    }
+
+    @VisibleForTesting
+    static class MetricsStatistics {
+        private final List<Long> values = new ArrayList<>();
+        private final String name;
+        private boolean sorted = false;
+        private long sum = 0;
+
+        MetricsStatistics(String name) {
+            this.name = name;
+        }
+
+        void addValue(long value) {
+            values.add(value);
+            sum += value;
+            sorted = false;
+        }
+
+        private String getName() {
+            return name;
+        }
+
+        private Map<String, Long> toMap() {
+            Map<String, Long> result = new HashMap<>();
+            result.put("min", getMin());
+            result.put("max", getMax());
+            result.put("avg", getAvg());
+            result.put("sum", getSum());
+            result.put("median", getMedian());
+            result.put("p25", getP25());
+            result.put("p75", getP75());
+            result.put("p95", getP95());
+            return result;
+        }
+
+        long getMin() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }

Review Comment:
   This can be deduplicated.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfo.java:
##########
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/** Aggregated info of a set of tasks. */
+public class AggregatedTaskDetailsInfo implements ResponseBody {
+    public static final String FIELD_NAME_METRICS = "metrics";
+    public static final String FIELD_NAME_STATUS_DURATION = "status-duration";
+
+    private static final String[] metricsNames = {
+        IOMetricsInfo.FIELD_NAME_BYTES_READ,
+        IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_RECORDS_READ,
+        IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN,
+        IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE,
+        IOMetricsInfo.FIELD_NAME_ACC_BUSY,
+        IOMetricsInfo.FIELD_NAME_ACC_IDLE
+    };
+
+    private static final String[] statusNames = {
+        ExecutionState.CREATED.name(),
+        ExecutionState.SCHEDULED.name(),
+        ExecutionState.INITIALIZING.name(),
+        ExecutionState.DEPLOYING.name(),
+        ExecutionState.RUNNING.name()
+    };
+
+    @JsonProperty(FIELD_NAME_METRICS)
+    private final Map<String, Map<String, Long>> metrics;
+
+    @JsonProperty(FIELD_NAME_STATUS_DURATION)
+    private final Map<String, Map<String, Long>> statusDuration;
+
+    @JsonCreator
+    public AggregatedTaskDetailsInfo(
+            @JsonProperty(FIELD_NAME_METRICS) Map<String, Map<String, Long>> metrics,
+            @JsonProperty(FIELD_NAME_STATUS_DURATION)
+                    Map<String, Map<String, Long>> statusDuration) {
+        this.metrics = Preconditions.checkNotNull(metrics);
+        this.statusDuration = Preconditions.checkNotNull(statusDuration);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        AggregatedTaskDetailsInfo that = (AggregatedTaskDetailsInfo) o;
+        return Objects.equals(metrics, that.metrics)
+                && Objects.equals(statusDuration, that.statusDuration);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(metrics, statusDuration);
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<SubtaskExecutionAttemptDetailsInfo> subtaskInfo) {
+        return create(
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getIoMetricsInfo)
+                        .collect(Collectors.toList()),
+                subtaskInfo.stream()
+                        .map(SubtaskExecutionAttemptDetailsInfo::getStatusDuration)
+                        .collect(Collectors.toList()));
+    }
+
+    public static AggregatedTaskDetailsInfo create(
+            List<IOMetricsInfo> ioMetricsInfos, List<Map<ExecutionState, Long>> statusDurations) {
+        Map<String, MetricsStatistics> metrics = new HashMap<>();
+        Map<String, MetricsStatistics> statusDuration = new HashMap<>();
+        Arrays.stream(metricsNames).forEach(name -> metrics.put(name, new MetricsStatistics(name)));
+        Arrays.stream(statusNames)
+                .forEach(name -> statusDuration.put(name, new MetricsStatistics(name)));
+
+        ioMetricsInfos.forEach(
+                ioMetricsInfo -> {
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_READ)
+                            .addValue(ioMetricsInfo.getBytesRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_BYTES_WRITTEN)
+                            .addValue(ioMetricsInfo.getBytesWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_READ)
+                            .addValue(ioMetricsInfo.getRecordsRead());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_RECORDS_WRITTEN)
+                            .addValue(ioMetricsInfo.getRecordsWritten());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_IDLE)
+                            .addValue(ioMetricsInfo.getAccumulatedIdle());
+                    metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BACK_PRESSURE)
+                            .addValue(ioMetricsInfo.getAccumulatedBackpressured());
+                    if (!Double.isNaN(ioMetricsInfo.getAccumulatedBusy())) {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY)
+                                .addValue((long) ioMetricsInfo.getAccumulatedBusy());
+                    } else {
+                        metrics.get(IOMetricsInfo.FIELD_NAME_ACC_BUSY).addValue(-1);
+                    }
+                });
+
+        statusDurations.forEach(
+                status -> {
+                    statusDuration
+                            .get(ExecutionState.CREATED.name())
+                            .addValue(status.get(ExecutionState.CREATED));
+                    statusDuration
+                            .get(ExecutionState.SCHEDULED.name())
+                            .addValue(status.get(ExecutionState.SCHEDULED));
+                    statusDuration
+                            .get(ExecutionState.INITIALIZING.name())
+                            .addValue(status.get(ExecutionState.INITIALIZING));
+                    statusDuration
+                            .get(ExecutionState.DEPLOYING.name())
+                            .addValue(status.get(ExecutionState.DEPLOYING));
+                    statusDuration
+                            .get(ExecutionState.RUNNING.name())
+                            .addValue(status.get(ExecutionState.RUNNING));
+                });
+        return new AggregatedTaskDetailsInfo(
+                metrics.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)),
+                statusDuration.values().stream()
+                        .collect(
+                                Collectors.toMap(
+                                        MetricsStatistics::getName, MetricsStatistics::toMap)));
+    }
+
+    @VisibleForTesting
+    static class MetricsStatistics {
+        private final List<Long> values = new ArrayList<>();
+        private final String name;
+        private boolean sorted = false;
+        private long sum = 0;
+
+        MetricsStatistics(String name) {
+            this.name = name;
+        }
+
+        void addValue(long value) {
+            values.add(value);
+            sum += value;
+            sorted = false;
+        }
+
+        private String getName() {
+            return name;
+        }
+
+        private Map<String, Long> toMap() {
+            Map<String, Long> result = new HashMap<>();
+            result.put("min", getMin());
+            result.put("max", getMax());
+            result.put("avg", getAvg());
+            result.put("sum", getSum());
+            result.put("median", getMedian());
+            result.put("p25", getP25());
+            result.put("p75", getP75());
+            result.put("p95", getP95());
+            return result;
+        }
+
+        long getMin() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty() ? 0 : values.get(0);
+        }
+
+        long getMax() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty() ? 0 : values.get(values.size() - 1);
+        }
+
+        long getMedian() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty() ? 0 : values.get(values.size() / 2);
+        }
+
+        long getP25() {
+            if (!sorted) {
+                values.sort(Comparator.naturalOrder());
+                sorted = true;
+            }
+            return values.isEmpty()
+                    ? 0
+                    : values.get(
+                            Math.min(values.size() - 1, (int) Math.rint(values.size() * 0.25)));

Review Comment:
   This is a very common calculation. I wonder if we can leverage some existing libraries. E.g., I find `org.apache.commons.math3.stat.descriptive.rank.Percentile` which might fit our needs.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] xintongsong commented on a diff in pull request #20123: [FLINK-28310][rest] Introduce aggregating task metrics

Posted by GitBox <gi...@apache.org>.
xintongsong commented on code in PR #20123:
URL: https://github.com/apache/flink/pull/20123#discussion_r911793827


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/AggregatedTaskDetailsInfoTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.metrics.IOMetricsInfo;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests for the {@link AggregatedTaskDetailsInfo}. */
+public class AggregatedTaskDetailsInfoTest
+        extends RestResponseMarshallingTestBase<AggregatedTaskDetailsInfo> {
+    @Override
+    protected Class<AggregatedTaskDetailsInfo> getTestResponseClass() {
+        return AggregatedTaskDetailsInfo.class;
+    }
+
+    @Override
+    protected AggregatedTaskDetailsInfo getTestResponseInstance() throws Exception {
+        final Random random = new Random();
+
+        final IOMetricsInfo ioMetricsInfo =
+                new IOMetricsInfo(
+                        Math.abs(random.nextLong()),
+                        random.nextBoolean(),
+                        Math.abs(random.nextLong()),
+                        random.nextBoolean(),
+                        Math.abs(random.nextLong()),
+                        random.nextBoolean(),
+                        Math.abs(random.nextLong()),
+                        random.nextBoolean(),
+                        Math.abs(random.nextLong()),
+                        Math.abs(random.nextLong()),
+                        Math.abs(random.nextDouble()));
+
+        final Map<ExecutionState, Long> statusDuration = new HashMap<>();
+        statusDuration.put(ExecutionState.CREATED, 10L);
+        statusDuration.put(ExecutionState.SCHEDULED, 20L);
+        statusDuration.put(ExecutionState.DEPLOYING, 30L);
+        statusDuration.put(ExecutionState.INITIALIZING, 40L);
+        statusDuration.put(ExecutionState.RUNNING, 50L);
+
+        return AggregatedTaskDetailsInfo.create(
+                Collections.singletonList(
+                        new SubtaskExecutionAttemptDetailsInfo(
+                                Math.abs(random.nextInt()),
+                                ExecutionState.values()[
+                                        random.nextInt(ExecutionState.values().length)],
+                                Math.abs(random.nextInt()),
+                                "localhost:" + random.nextInt(65536),
+                                Math.abs(random.nextLong()),
+                                Math.abs(random.nextLong()),
+                                Math.abs(random.nextLong()),
+                                ioMetricsInfo,
+                                "taskmanagerId",
+                                statusDuration)));
+    }
+
+    @Test
+    public void testMetricsStatistics() {
+        final AggregatedTaskDetailsInfo.MetricsStatistics metricsStatistics =
+                new AggregatedTaskDetailsInfo.MetricsStatistics("test");
+        for (int i = 0; i < 100; ++i) {
+            metricsStatistics.addValue(i);
+        }
+        assertEquals(metricsStatistics.getMin(), 0L);

Review Comment:
   Minor: this affects the error message.
   ```suggestion
           assertEquals(0L, metricsStatistics.getMin());
   ```



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org