AMBARI-21079. Add ability to sink Raw metrics to external system via Http. Compilatio...
authorSiddharth Wagle <swagle@hortonworks.com>
Thu, 8 Jun 2017 23:14:24 +0000 (16:14 -0700)
committeravijayanhwx <avijayan@hortonworks.com>
Sun, 1 Apr 2018 19:13:52 +0000 (12:13 -0700)
ambari-metrics-common/pom.xml
ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/cache/TimelineMetricsEhCacheSizeOfEngine.java
ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/source/cache/InternalMetricsCacheSizeOfEngine.java

index bd94ad1..4f08820 100644 (file)
@@ -74,7 +74,7 @@
                 </relocation>
                 <relocation>
                   <pattern>org.apache.commons.io</pattern>
-                  <shadedPattern>org.apache.ambari.metrics.sink.relocated.commons.io</shadedPattern>StormTimelineMetricsReporter
+                  <shadedPattern>org.apache.ambari.metrics.sink.relocated.commons.io</shadedPattern>
                 </relocation>
                 <relocation>
                   <pattern>org.apache.commons.lang</pattern>
index ea694b7..0e23e17 100644 (file)
@@ -24,6 +24,9 @@ import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import net.sf.ehcache.Element;
+import net.sf.ehcache.pool.Size;
 import net.sf.ehcache.pool.SizeOfEngine;
 import net.sf.ehcache.pool.impl.DefaultSizeOfEngine;
 import net.sf.ehcache.pool.sizeof.ReflectionSizeOf;
@@ -51,6 +54,7 @@ public abstract class TimelineMetricsEhCacheSizeOfEngine implements SizeOfEngine
   // Map entry sizing
   private long sizeOfMapEntry;
   private long sizeOfMapEntryOverhead;
+  private long sizeOfElement;
 
   protected TimelineMetricsEhCacheSizeOfEngine(SizeOfEngine underlying) {
     this.underlying = underlying;
@@ -62,6 +66,8 @@ public abstract class TimelineMetricsEhCacheSizeOfEngine implements SizeOfEngine
     this.sizeOfMapEntry = reflectionSizeOf.sizeOf(new Long(1)) +
       reflectionSizeOf.sizeOf(new Double(2.0));
 
+    this.sizeOfElement = reflectionSizeOf.sizeOf(new Element(new Object(), new Object()));
+
     //SizeOfMapEntryOverhead = SizeOfMapWithOneEntry - (SizeOfEmptyMap + SizeOfOneEntry)
     TreeMap<Long, Double> map = new TreeMap<>();
     long emptyMapSize = reflectionSizeOf.sizeOf(map);
@@ -112,4 +118,20 @@ public abstract class TimelineMetricsEhCacheSizeOfEngine implements SizeOfEngine
     }
     return size;
   }
+
+  // Get size of the Cache entry for final size calculation
+  protected abstract long getSizeOfEntry(Object key, Object value);
+
+  @Override
+  public Size sizeOf(Object key, Object value, Object container) {
+    return new Size(sizeOfElement + getSizeOfEntry(key, value), false);
+  }
+
+  @Override
+  public SizeOfEngine copyWith(int maxDepth, boolean abortWhenMaxDepthExceeded) {
+    LOG.debug("Copying tracing sizeof engine, maxdepth: {}, abort: {}", maxDepth, abortWhenMaxDepthExceeded);
+
+    return underlying.copyWith(maxDepth, abortWhenMaxDepthExceeded);
+  }
+
 }
index 071dcd4..e36c981 100644 (file)
@@ -20,48 +20,33 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline
 import org.apache.hadoop.metrics2.sink.timeline.cache.TimelineMetricsEhCacheSizeOfEngine;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import net.sf.ehcache.pool.Size;
-import net.sf.ehcache.pool.SizeOfEngine;
 
-public class InternalMetricsCacheSizeOfEngine {
-// extends TimelineMetricsEhCacheSizeOfEngine {
-//  private final static Logger LOG = LoggerFactory.getLogger(InternalMetricsCacheSizeOfEngine.class);
-//
-//  private InternalMetricsCacheSizeOfEngine(SizeOfEngine underlying) {
-//    super(underlying);
-//  }
-//
-//  public InternalMetricsCacheSizeOfEngine() {
-//    // Invoke default constructor in base class
-//  }
-//
-//  @Override
-//  public Size sizeOf(Object key, Object value, Object container) {
-//    try {
-//      LOG.debug("BEGIN - Sizeof, key: {}, value: {}", key, value);
-//      long size = 0;
-//      if (key instanceof InternalMetricCacheKey) {
-//        InternalMetricCacheKey metricCacheKey = (InternalMetricCacheKey) key;
-//        size += reflectionSizeOf.sizeOf(metricCacheKey.getMetricName());
-//        size += reflectionSizeOf.sizeOf(metricCacheKey.getAppId());
-//        size += reflectionSizeOf.sizeOf(metricCacheKey.getInstanceId()); // null safe
-//        size += reflectionSizeOf.sizeOf(metricCacheKey.getHostname());
-//      }
-//      if (value instanceof InternalMetricCacheValue) {
-//        size += getValueMapSize(((InternalMetricCacheValue) value).getMetricValues());
-//      }
-//      // Mark size as not being exact
-//      return new Size(size, false);
-//    } finally {
-//      LOG.debug("END - Sizeof, key: {}", key);
-//    }
-//  }
-//
-//  @Override
-//  public SizeOfEngine copyWith(int maxDepth, boolean abortWhenMaxDepthExceeded) {
-//    LOG.debug("Copying tracing sizeof engine, maxdepth: {}, abort: {}",
-//      maxDepth, abortWhenMaxDepthExceeded);
-//
-//    return new InternalMetricsCacheSizeOfEngine(underlying.copyWith(maxDepth, abortWhenMaxDepthExceeded));
-//  }
+public class InternalMetricsCacheSizeOfEngine extends TimelineMetricsEhCacheSizeOfEngine {
+  private final static Logger LOG = LoggerFactory.getLogger(InternalMetricsCacheSizeOfEngine.class);
+
+  public InternalMetricsCacheSizeOfEngine() {
+    // Invoke default constructor in base class
+  }
+
+  @Override
+  protected long getSizeOfEntry(Object key, Object value) {
+    try {
+      LOG.debug("BEGIN - Sizeof, key: {}, value: {}", key, value);
+      long size = 0;
+      if (key instanceof InternalMetricCacheKey) {
+        InternalMetricCacheKey metricCacheKey = (InternalMetricCacheKey) key;
+        size += reflectionSizeOf.sizeOf(metricCacheKey.getMetricName());
+        size += reflectionSizeOf.sizeOf(metricCacheKey.getAppId());
+        size += reflectionSizeOf.sizeOf(metricCacheKey.getInstanceId()); // null safe
+        size += reflectionSizeOf.sizeOf(metricCacheKey.getHostname());
+      }
+      if (value instanceof InternalMetricCacheValue) {
+        size += getValueMapSize(((InternalMetricCacheValue) value).getMetricValues());
+      }
+      // Mark size as not being exact
+      return size;
+    } finally {
+      LOG.debug("END - Sizeof, key: {}", key);
+    }
+  }
 }