STORM-2152: address additional review comments
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/44cd8ac3 Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/44cd8ac3 Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/44cd8ac3 Branch: refs/heads/1.x-branch Commit: 44cd8ac3b4b55cfa86b63d45db2c0407f4c26417 Parents: 8af4fca Author: P. Taylor Goetz <[email protected]> Authored: Tue Jan 9 15:07:16 2018 -0500 Committer: P. Taylor Goetz <[email protected]> Committed: Tue Jan 9 15:07:16 2018 -0500 ---------------------------------------------------------------------- .../storm/metrics2/StormMetricRegistry.java | 20 ++++++++++++-------- .../org/apache/storm/task/TopologyContext.java | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/44cd8ac3/storm-core/src/jvm/org/apache/storm/metrics2/StormMetricRegistry.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/metrics2/StormMetricRegistry.java b/storm-core/src/jvm/org/apache/storm/metrics2/StormMetricRegistry.java index 2bab4e9..789367b 100644 --- a/storm-core/src/jvm/org/apache/storm/metrics2/StormMetricRegistry.java +++ b/storm-core/src/jvm/org/apache/storm/metrics2/StormMetricRegistry.java @@ -23,6 +23,7 @@ import com.codahale.metrics.MetricRegistry; import org.apache.storm.Config; import org.apache.storm.cluster.DaemonType; import org.apache.storm.metrics2.reporters.StormReporter; +import org.apache.storm.task.TopologyContext; import org.apache.storm.task.WorkerTopologyContext; import org.apache.storm.utils.Utils; import org.slf4j.Logger; @@ -46,12 +47,11 @@ public class StormMetricRegistry { private static String hostName = null; public static <T> SimpleGauge<T> gauge(T initialValue, String name, String topologyId, String componentId, Integer port){ - SimpleGauge<T> gauge = new SimpleGauge<>(initialValue); String metricName = metricName(name, topologyId, componentId, port); if(REGISTRY.getGauges().containsKey(metricName)){ return (SimpleGauge)REGISTRY.getGauges().get(metricName); } else { - return REGISTRY.register(metricName, gauge); + return REGISTRY.register(metricName, new SimpleGauge<>(initialValue)); } } @@ -79,7 +79,6 @@ public class StormMetricRegistry { } public static void start(Map<String, Object> stormConfig, DaemonType type){ - String localHost = "localhost"; try { hostName = dotToUnderScore(Utils.localHostname()); } catch (UnknownHostException e) { @@ -110,11 +109,7 @@ public class StormMetricRegistry { String clazz = (String)reporterConfig.get("class"); StormReporter reporter = null; LOG.info("Attempting to instantiate reporter class: {}", clazz); - try{ - reporter = (StormReporter)Metrics2Utils.instantiate(clazz); - } catch(Exception e){ - LOG.warn("Unable to instantiate metrics reporter class: {}. Will skip this reporter.", clazz, e); - } + reporter = Utils.newInstance(clazz); if(reporter != null){ reporter.prepare(REGISTRY, stormConfig, reporterConfig); reporter.start(); @@ -150,6 +145,15 @@ public class StormMetricRegistry { name); } + public static String metricName(String name, TopologyContext context){ + return String.format("storm.topology.%s.%s.%s.%s.%s-%s", + context.getStormId(), + hostName, + dotToUnderScore(context.getThisComponentId()), + context.getThisWorkerPort(), + name); + } + private static String dotToUnderScore(String str){ return str.replace('.', '_'); } http://git-wip-us.apache.org/repos/asf/storm/blob/44cd8ac3/storm-core/src/jvm/org/apache/storm/task/TopologyContext.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/task/TopologyContext.java b/storm-core/src/jvm/org/apache/storm/task/TopologyContext.java index 444a8a7..330fee1 100644 --- a/storm-core/src/jvm/org/apache/storm/task/TopologyContext.java +++ b/storm-core/src/jvm/org/apache/storm/task/TopologyContext.java @@ -410,6 +410,6 @@ public class TopologyContext extends WorkerTopologyContext implements IMetricsCo } private String metricName(String name){ - return String.format("storm.topology.%s.%s.%s-%s", getStormId(), getThisComponentId(), getThisWorkerPort(), name); + return StormMetricRegistry.metricName(name, this); } }
