flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [2/2] flink git commit: [FLINK-5261] [metrics] Clean up meters in ScheduledDropwizardReporter
Date Tue, 06 Dec 2016 14:49:23 GMT
[FLINK-5261] [metrics] Clean up meters in ScheduledDropwizardReporter

This closes #2944.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f7f7b487
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f7f7b487
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f7f7b487

Branch: refs/heads/master
Commit: f7f7b487b705e31062e5f00508a92bed5b185674
Parents: e5f4e3d
Author: zentol <chesnay@apache.org>
Authored: Mon Dec 5 14:00:10 2016 +0100
Committer: Ufuk Celebi <uce@apache.org>
Committed: Tue Dec 6 14:06:51 2016 +0100

----------------------------------------------------------------------
 .../dropwizard/ScheduledDropwizardReporter.java | 19 +++-
 .../ScheduledDropwizardReporterTest.java        | 92 ++++++++++++++++++++
 2 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/f7f7b487/flink-metrics/flink-metrics-dropwizard/src/main/java/org/apache/flink/dropwizard/ScheduledDropwizardReporter.java
----------------------------------------------------------------------
diff --git a/flink-metrics/flink-metrics-dropwizard/src/main/java/org/apache/flink/dropwizard/ScheduledDropwizardReporter.java
b/flink-metrics/flink-metrics-dropwizard/src/main/java/org/apache/flink/dropwizard/ScheduledDropwizardReporter.java
index b7e83b6..380abc4 100644
--- a/flink-metrics/flink-metrics-dropwizard/src/main/java/org/apache/flink/dropwizard/ScheduledDropwizardReporter.java
+++ b/flink-metrics/flink-metrics-dropwizard/src/main/java/org/apache/flink/dropwizard/ScheduledDropwizardReporter.java
@@ -21,11 +21,11 @@ package org.apache.flink.dropwizard;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Reporter;
 import com.codahale.metrics.ScheduledReporter;
-
 import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper;
 import org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper;
 import org.apache.flink.dropwizard.metrics.FlinkCounterWrapper;
-import org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper;
 import org.apache.flink.dropwizard.metrics.FlinkGaugeWrapper;
 import org.apache.flink.dropwizard.metrics.FlinkHistogramWrapper;
 import org.apache.flink.dropwizard.metrics.FlinkMeterWrapper;
@@ -82,15 +82,26 @@ public abstract class ScheduledDropwizardReporter implements MetricReporter,
Sch
 	//  Getters
 	// ------------------------------------------------------------------------
 
-	// used for testing purposes
+	@VisibleForTesting
 	Map<Counter, String> getCounters() {
 		return counters;
 	}
 
+	@VisibleForTesting
 	Map<Meter, String> getMeters() {
 		return meters;
 	}
 
+	@VisibleForTesting
+	Map<Gauge<?>, String> getGauges() {
+		return gauges;
+	}
+
+	@VisibleForTesting
+	Map<Histogram, String> getHistograms() {
+		return histograms;
+	}
+
 	// ------------------------------------------------------------------------
 	//  life cycle
 	// ------------------------------------------------------------------------
@@ -157,6 +168,8 @@ public abstract class ScheduledDropwizardReporter implements MetricReporter,
Sch
 				fullName = gauges.remove(metric);
 			} else if (metric instanceof Histogram) {
 				fullName = histograms.remove(metric);
+			} else if (metric instanceof Meter) {
+				fullName = meters.remove(metric);
 			} else {
 				fullName = null;
 			}

http://git-wip-us.apache.org/repos/asf/flink/blob/f7f7b487/flink-metrics/flink-metrics-dropwizard/src/test/java/org/apache/flink/dropwizard/ScheduledDropwizardReporterTest.java
----------------------------------------------------------------------
diff --git a/flink-metrics/flink-metrics-dropwizard/src/test/java/org/apache/flink/dropwizard/ScheduledDropwizardReporterTest.java
b/flink-metrics/flink-metrics-dropwizard/src/test/java/org/apache/flink/dropwizard/ScheduledDropwizardReporterTest.java
index 9385510..87c4ccb 100644
--- a/flink-metrics/flink-metrics-dropwizard/src/test/java/org/apache/flink/dropwizard/ScheduledDropwizardReporterTest.java
+++ b/flink-metrics/flink-metrics-dropwizard/src/test/java/org/apache/flink/dropwizard/ScheduledDropwizardReporterTest.java
@@ -24,9 +24,14 @@ import org.apache.flink.configuration.ConfigConstants;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper;
 import org.apache.flink.metrics.Counter;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.metrics.Histogram;
+import org.apache.flink.metrics.HistogramStatistics;
 import org.apache.flink.metrics.Meter;
 import org.apache.flink.metrics.MetricConfig;
+import org.apache.flink.metrics.MetricGroup;
 import org.apache.flink.metrics.SimpleCounter;
+import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
 import org.apache.flink.metrics.reporter.MetricReporter;
 import org.apache.flink.runtime.metrics.MetricRegistry;
 import org.apache.flink.runtime.metrics.MetricRegistryConfiguration;
@@ -124,6 +129,93 @@ public class ScheduledDropwizardReporterTest {
 		metricRegistry.shutdown();
 	}
 
+	/**
+	 * This test verifies that metrics are properly added and removed to/from the ScheduledDropwizardReporter
and
+	 * the underlying Dropwizard MetricRegistry.
+	 */
+	@Test
+	public void testMetricCleanup() {
+		TestingScheduledDropwizardReporter rep = new TestingScheduledDropwizardReporter();
+
+		MetricGroup mp = new UnregisteredMetricsGroup();
+
+		Counter c = new SimpleCounter();
+		Meter m = new Meter() {
+			@Override
+			public void markEvent() {
+			}
+
+			@Override
+			public void markEvent(long n) {
+			}
+
+			@Override
+			public double getRate() {
+				return 0;
+			}
+
+			@Override
+			public long getCount() {
+				return 0;
+			}
+		};
+		Histogram h = new Histogram() {
+			@Override
+			public void update(long value) {
+
+			}
+
+			@Override
+			public long getCount() {
+				return 0;
+			}
+
+			@Override
+			public HistogramStatistics getStatistics() {
+				return null;
+			}
+		};
+		Gauge g = new Gauge() {
+			@Override
+			public Object getValue() {
+				return null;
+			}
+		};
+
+		rep.notifyOfAddedMetric(c, "counter", mp);
+		assertEquals(1, rep.getCounters().size());
+		assertEquals(1, rep.registry.getCounters().size());
+
+		rep.notifyOfAddedMetric(m, "meter", mp);
+		assertEquals(1, rep.getMeters().size());
+		assertEquals(1, rep.registry.getMeters().size());
+
+		rep.notifyOfAddedMetric(h, "histogram", mp);
+		assertEquals(1, rep.getHistograms().size());
+		assertEquals(1, rep.registry.getHistograms().size());
+
+		rep.notifyOfAddedMetric(g, "gauge", mp);
+		assertEquals(1, rep.getGauges().size());
+		assertEquals(1, rep.registry.getGauges().size());
+
+
+		rep.notifyOfRemovedMetric(c, "counter", mp);
+		assertEquals(0, rep.getCounters().size());
+		assertEquals(0, rep.registry.getCounters().size());
+
+		rep.notifyOfRemovedMetric(m, "meter", mp);
+		assertEquals(0, rep.getMeters().size());
+		assertEquals(0, rep.registry.getMeters().size());
+
+		rep.notifyOfRemovedMetric(h, "histogram", mp);
+		assertEquals(0, rep.getHistograms().size());
+		assertEquals(0, rep.registry.getHistograms().size());
+
+		rep.notifyOfRemovedMetric(g, "gauge", mp);
+		assertEquals(0, rep.getGauges().size());
+		assertEquals(0, rep.registry.getGauges().size());
+	}
+
 	public static class TestingScheduledDropwizardReporter extends ScheduledDropwizardReporter
{
 
 		@Override


Mime
View raw message