You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2018/11/27 16:08:46 UTC
[flink] branch release-1.6 updated: [FLINK-10990][metrics] Enforce
minimum timespan in MeterView
This is an automated email from the ASF dual-hosted git repository.
chesnay pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.6 by this push:
new 05d969e [FLINK-10990][metrics] Enforce minimum timespan in MeterView
05d969e is described below
commit 05d969e7b7bd0e54935eeda3f95d4a7711cef6e8
Author: Aitozi <we...@aitozi.com>
AuthorDate: Wed Nov 28 00:04:42 2018 +0800
[FLINK-10990][metrics] Enforce minimum timespan in MeterView
---
.../src/main/java/org/apache/flink/metrics/MeterView.java | 6 +++++-
.../src/test/java/org/apache/flink/metrics/MeterViewTest.java | 11 +++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
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 8df0e86..6d53325 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 class MeterView implements Meter, View {
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 a7a63b0..7752a6e 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 @@ package org.apache.flink.metrics;
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 class MeterViewTest {
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);
+ }
}