hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravip...@apache.org
Subject git commit: HADOOP-11181. GraphiteSink emits wrong timestamps (Sascha Coenen via raviprak)
Date Wed, 15 Oct 2014 22:50:51 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 0af1a2b5b -> 466f08792


HADOOP-11181. GraphiteSink emits wrong timestamps (Sascha Coenen via raviprak)


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

Branch: refs/heads/trunk
Commit: 466f08792f11c2f95bf293ac9b6facd7018a5bb8
Parents: 0af1a2b
Author: Ravi Prakash <raviprak@apache.org>
Authored: Wed Oct 15 15:49:46 2014 -0700
Committer: Ravi Prakash <raviprak@apache.org>
Committed: Wed Oct 15 15:49:46 2014 -0700

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../hadoop/metrics2/sink/GraphiteSink.java      |  4 +-
 .../metrics2/impl/TestGraphiteMetrics.java      | 44 +++++++++++++++++++-
 3 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/466f0879/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 9f43937..f617137 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -661,6 +661,8 @@ Release 2.6.0 - UNRELEASED
 
   BUG FIXES
 
+    HADOOP-11181. GraphiteSink emits wrong timestamps (Sascha Coenen via raviprak)
+
     HADOOP-10781. Unportable getgrouplist() usage breaks FreeBSD (Dmitry
     Sivachenko via Colin Patrick McCabe)
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/466f0879/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java
index f474d82..9bc3f15 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java
@@ -89,8 +89,8 @@ public class GraphiteSink implements MetricsSink, Closeable {
             }
         }
 
-        // Round the timestamp to second as Graphite accepts it in such format.
-        int timestamp = Math.round(record.timestamp() / 1000.0f);
+        // The record timestamp is in milliseconds while Graphite expects an epoc time in
seconds.
+        long timestamp = record.timestamp() / 1000L;
 
         // Collect datapoints.
         for (AbstractMetric metric : record.metrics()) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/466f0879/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java
index f54c27d..09f0081 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGraphiteMetrics.java
@@ -19,11 +19,16 @@
 package org.apache.hadoop.metrics2.impl;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -34,8 +39,6 @@ import org.apache.hadoop.metrics2.MetricsRecord;
 import org.apache.hadoop.metrics2.MetricsTag;
 import org.apache.hadoop.metrics2.sink.GraphiteSink;
 import org.junit.Test;
-
-import static org.mockito.Mockito.*;
 import org.mockito.ArgumentCaptor;
 import org.mockito.internal.util.reflection.Whitebox;
 
@@ -108,6 +111,43 @@ public class TestGraphiteMetrics {
             result.equals("null.all.Context.Context=all.foo2 2 10\n" + 
             "null.all.Context.Context=all.foo1 1 10\n"));
     }
+
+    /**
+     * Assert that timestamps are converted correctly, ticket HADOOP-11182
+     */
+    @Test
+    public void testPutMetrics3() {
+
+      // setup GraphiteSink
+      GraphiteSink sink = new GraphiteSink();
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      Whitebox.setInternalState(sink, "writer", new OutputStreamWriter(out));
+
+      // given two metrics records with timestamps 1000 milliseconds apart.
+      List<MetricsTag> tags = Collections.emptyList();
+      Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
+      metrics.add(makeMetric("foo1", 1));
+      MetricsRecord record1 = new MetricsRecordImpl(MsInfo.Context, 1000000000000L, tags,
metrics);
+      MetricsRecord record2 = new MetricsRecordImpl(MsInfo.Context, 1000000001000L, tags,
metrics);
+
+      sink.putMetrics(record1);
+      sink.putMetrics(record2);
+
+      sink.flush();
+      try {
+        sink.close();
+      } catch(IOException e) {
+        e.printStackTrace();
+      }
+
+      // then the timestamps in the graphite stream should differ by one second.
+      String expectedOutput
+        = "null.default.Context.foo1 1 1000000000\n"
+        + "null.default.Context.foo1 1 1000000001\n";
+      assertEquals(expectedOutput, out.toString());
+    }
+
+
     @Test(expected=MetricsException.class)
     public void testCloseAndWrite() throws IOException {
       GraphiteSink sink = new GraphiteSink();


Mime
View raw message