[ https://issues.apache.org/jira/browse/FLINK-10990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16700626#comment-16700626 ]
ASF GitHub Bot commented on FLINK-10990: ---------------------------------------- zentol closed pull request #7165: [FLINK-10990][Metric]Pre-check timespan in meterview to avoid NAN URL: https://github.com/apache/flink/pull/7165 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/metrics/MeterView.java b/flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/metrics/MeterView.java index 8df0e868f8f..6d53325edaf 100644 --- a/flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/metrics/MeterView.java +++ b/flink-metrics/flink-metrics-core/src/main/java/org/apache/flink/metrics/MeterView.java @@ -50,7 +50,11 @@ public MeterView(int timeSpanInSeconds) { public MeterView(Counter counter, int timeSpanInSeconds) { this.counter = counter; - this.timeSpanInSeconds = timeSpanInSeconds - (timeSpanInSeconds % UPDATE_INTERVAL_SECONDS); + // the time-span must be larger than the update-interval as otherwise the array has a size of 1, + // for which no rate can be computed as no distinct before/after measurement exists. + this.timeSpanInSeconds = Math.max( + timeSpanInSeconds - (timeSpanInSeconds % UPDATE_INTERVAL_SECONDS), + UPDATE_INTERVAL_SECONDS); this.values = new long[this.timeSpanInSeconds / UPDATE_INTERVAL_SECONDS + 1]; } diff --git a/flink-metrics/flink-metrics-core/src/test/java/org/apache/flink/metrics/MeterViewTest.java b/flink-metrics/flink-metrics-core/src/test/java/org/apache/flink/metrics/MeterViewTest.java index a7a63b09949..7752a6e80bb 100644 --- a/flink-metrics/flink-metrics-core/src/test/java/org/apache/flink/metrics/MeterViewTest.java +++ b/flink-metrics/flink-metrics-core/src/test/java/org/apache/flink/metrics/MeterViewTest.java @@ -20,6 +20,7 @@ import org.junit.Test; +import static org.apache.flink.metrics.View.UPDATE_INTERVAL_SECONDS; import static org.junit.Assert.assertEquals; /** @@ -94,4 +95,14 @@ public void testGetRate() { assertEquals(0.0, m.getRate(), 0.1); // 480 - 480 / 60 } + + @Test + public void testTimeSpanBelowUpdateRate() { + int timeSpanInSeconds = 1; + MeterView m = new MeterView(timeSpanInSeconds); + assert timeSpanInSeconds < UPDATE_INTERVAL_SECONDS; + m.markEvent(); + m.update(); + assertEquals(0.2, m.getRate(), 0.0); + } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 > Pre-check timespan in meterview to avoid NAN > -------------------------------------------- > > Key: FLINK-10990 > URL: https://issues.apache.org/jira/browse/FLINK-10990 > Project: Flink > Issue Type: Bug > Components: Metrics > Affects Versions: 1.7.0 > Reporter: aitozi > Assignee: aitozi > Priority: Minor > Labels: pull-request-available > Fix For: 1.7.0 > > > In the metric tool MeterView. If user use the meterview with the timespan > smaller than UPDATE_INTERVAL_SECONDS = 5 , the getRate will always return 0/0 > = NAN. And this is not friendly , I think we should pre-check it. -- This message was sent by Atlassian JIRA (v7.6.3#76005)