flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject flink git commit: [FLINK-4229] [metrics] Only start JMX server when port is specified
Date Fri, 22 Jul 2016 09:48:47 GMT
Repository: flink
Updated Branches:
  refs/heads/master 5dd85e286 -> 73836f7ac


[FLINK-4229] [metrics] Only start JMX server when port is specified

This closes #2279


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

Branch: refs/heads/master
Commit: 73836f7ac07399e47c506db6c1ef5c0a61437e9e
Parents: 5dd85e2
Author: Aljoscha Krettek <aljoscha.krettek@gmail.com>
Authored: Thu Jul 21 16:44:06 2016 +0200
Committer: Stephan Ewen <sewen@apache.org>
Committed: Thu Jul 21 17:02:51 2016 +0200

----------------------------------------------------------------------
 docs/apis/metrics.md                            |  5 ++-
 .../flink/metrics/reporter/JMXReporter.java     | 43 +++++++++++---------
 .../flink/metrics/reporter/JMXReporterTest.java |  4 +-
 3 files changed, 29 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/73836f7a/docs/apis/metrics.md
----------------------------------------------------------------------
diff --git a/docs/apis/metrics.md b/docs/apis/metrics.md
index f50f6ae..e6bcfaf 100644
--- a/docs/apis/metrics.md
+++ b/docs/apis/metrics.md
@@ -249,8 +249,9 @@ but not activated.
 Parameters:
 
 - `port` - the port on which JMX listens for connections. This can also be a port range.
When a
-range is specified the actual port is shown in the relevant job or task manager log. Default:
-`9010-9025`.
+range is specified the actual port is shown in the relevant job or task manager log. If you
don't
+specify a port no extra JMX server will be started. Metrics are still available on the default
+local JMX interface.
 
 ### Ganglia (org.apache.flink.metrics.ganglia.GangliaReporter)
 Dependency:

http://git-wip-us.apache.org/repos/asf/flink/blob/73836f7a/flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java b/flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java
index 17fbb91..d84cd5e 100644
--- a/flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java
+++ b/flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java
@@ -90,31 +90,33 @@ public class JMXReporter implements MetricReporter {
 
 	@Override
 	public void open(Configuration config) {
-		this.jmxServer = startJmxServer(config);
-	}
-
-	private static JMXServer startJmxServer(Configuration config) {
-		String portsConfig = config.getString(ARG_PORT, "9010-9025");
+		String portsConfig = config.getString(ARG_PORT, null);
 
-		Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);
+		if (portsConfig != null) {
+			Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);
 
-		JMXServer server = new JMXServer();
-		while (ports.hasNext()) {
-			int port = ports.next();
-			try {
-				server.start(port);
-				LOG.info("Started JMX server on port " + port + ".");
-				return server;
-			} catch (IOException ioe) { //assume port conflict
-				LOG.debug("Could not start JMX server on port " + port + ".", ioe);
+			JMXServer server = new JMXServer();
+			while (ports.hasNext()) {
+				int port = ports.next();
 				try {
-					server.stop();
-				} catch (Exception e) {
-					LOG.debug("Could not stop JMX server.", e);
+					server.start(port);
+					LOG.info("Started JMX server on port " + port + ".");
+					// only set our field if the server was actually started
+					jmxServer = server;
+					break;
+				} catch (IOException ioe) { //assume port conflict
+					LOG.debug("Could not start JMX server on port " + port + ".", ioe);
+					try {
+						server.stop();
+					} catch (Exception e) {
+						LOG.debug("Could not stop JMX server.", e);
+					}
 				}
 			}
+			if (jmxServer == null) {
+				throw new RuntimeException("Could not start JMX server on any configured port. Ports:
" + portsConfig);
+			}
 		}
-		throw new RuntimeException("Could not start JMX server on any configured port.");
 	}
 
 	@Override
@@ -129,6 +131,9 @@ public class JMXReporter implements MetricReporter {
 	}
 	
 	public int getPort() {
+		if (jmxServer == null) {
+			throw new NullPointerException("No server was opened. Did you specify a port?");
+		}
 		return jmxServer.port;
 	}
 

http://git-wip-us.apache.org/repos/asf/flink/blob/73836f7a/flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
b/flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
index f03ee11..06bcdf3 100644
--- a/flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
+++ b/flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
@@ -88,7 +88,7 @@ public class JMXReporterTest extends TestLogger {
 		JMXReporter rep2 = new JMXReporter();
 
 		Configuration cfg1 = new Configuration();
-		cfg1.setString(ConfigConstants.METRICS_REPORTER_ARGUMENTS, "-port 9020-9035");
+		cfg1.setString("port", "9020-9035");
 
 		rep1.open(cfg1);
 		rep2.open(cfg1);
@@ -137,7 +137,7 @@ public class JMXReporterTest extends TestLogger {
 		JMXReporter rep2 = new JMXReporter();
 
 		Configuration cfg1 = new Configuration();
-		cfg1.setString(ConfigConstants.METRICS_REPORTER_ARGUMENTS, "-port 9040-9055");
+		cfg1.setString("port", "9040-9055");
 		rep1.open(cfg1);
 		rep2.open(cfg1);
 


Mime
View raw message