phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jya...@apache.org
Subject git commit: PHOENIX-1226 Exception in Tracing
Date Fri, 05 Sep 2014 23:44:42 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 4a1ec7ec4 -> 284435b5a


PHOENIX-1226 Exception in Tracing

Phoenix tracing expects annotation values to be integers, but HBase writes
non-integer values in its traces (which end up in the phoenix sink)


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

Branch: refs/heads/master
Commit: 284435b5ab4e749febf13ad00f9050f6f25f9e15
Parents: 4a1ec7e
Author: Jesse Yates <jyates@apache.org>
Authored: Fri Sep 5 16:44:15 2014 -0700
Committer: Jesse Yates <jyates@apache.org>
Committed: Fri Sep 5 16:44:36 2014 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/trace/TracingCompat.java |  4 +-
 .../phoenix/trace/TraceMetricsSourceTest.java   | 96 ++++++++++++++++++++
 2 files changed, 98 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/284435b5/phoenix-hadoop-compat/src/main/java/org/apache/phoenix/trace/TracingCompat.java
----------------------------------------------------------------------
diff --git a/phoenix-hadoop-compat/src/main/java/org/apache/phoenix/trace/TracingCompat.java
b/phoenix-hadoop-compat/src/main/java/org/apache/phoenix/trace/TracingCompat.java
index 783bfd6..032e38a 100644
--- a/phoenix-hadoop-compat/src/main/java/org/apache/phoenix/trace/TracingCompat.java
+++ b/phoenix-hadoop-compat/src/main/java/org/apache/phoenix/trace/TracingCompat.java
@@ -49,11 +49,11 @@ public class TracingCompat {
     public static final String METRICS_MARKER_CONTEXT = "marker";
 
     public static void addAnnotation(Span span, String message, int value) {
-        span.addKVAnnotation(message.getBytes(), Bytes.toBytes(value));
+        span.addKVAnnotation(message.getBytes(), Bytes.toBytes(Integer.toString(value)));
     }
 
     public static Pair<String, String> readAnnotation(byte[] key, byte[] value) {
-        return new Pair<String, String>(new String(key), Integer.toString(Bytes.toInt(value)));
+        return new Pair<String, String>(new String(key), Bytes.toString(value));
     }
 
     public static MetricsWriter initializeWriter(String clazz) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/284435b5/phoenix-hadoop2-compat/src/test/java/org/apache/phoenix/trace/TraceMetricsSourceTest.java
----------------------------------------------------------------------
diff --git a/phoenix-hadoop2-compat/src/test/java/org/apache/phoenix/trace/TraceMetricsSourceTest.java
b/phoenix-hadoop2-compat/src/test/java/org/apache/phoenix/trace/TraceMetricsSourceTest.java
new file mode 100644
index 0000000..3258e8a
--- /dev/null
+++ b/phoenix-hadoop2-compat/src/test/java/org/apache/phoenix/trace/TraceMetricsSourceTest.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.trace;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.metrics2.MetricsCollector;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.cloudera.htrace.Span;
+import org.cloudera.htrace.impl.MilliSpan;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test that the @{link TraceMetricSource} correctly handles different kinds of traces
+ */
+public class TraceMetricsSourceTest {
+
+  @BeforeClass
+  public static void setup() throws Exception{
+    DefaultMetricsSystem.setMiniClusterMode(true);
+  }
+
+  /**
+   * For PHOENIX-1126, Phoenix originally assumed all the annotation values were integers,
+   * but HBase writes some strings as well, so we need to be able to handle that too
+   */
+  @Test
+  public void testNonIntegerAnnotations(){
+    Span span = getSpan();
+    // make sure its less than the length of an integer
+    byte[] value = Bytes.toBytes("a");
+    byte[] someInt = Bytes.toBytes(1);
+    assertTrue(someInt.length >value.length);
+
+    // an annotation that is not an integer
+    span.addKVAnnotation(Bytes.toBytes("key"), value);
+
+    // Create the sink and write the span
+    TraceMetricSource source = new TraceMetricSource();
+    source.receiveSpan(span);
+  }
+
+  @Test
+  public void testIntegerAnnotations(){
+    Span span = getSpan();
+
+    // add annotation through the phoenix interfaces
+    TracingCompat.addAnnotation(span, "message", 10);
+
+    TraceMetricSource source = new TraceMetricSource();
+    source.receiveSpan(span);
+  }
+
+  /**
+   * If the source does not write any metrics when there are no spans, i.e. when initialized,
+   * then the metrics system will discard the source, so it needs to always emit some metrics.
+   */
+  @Test
+  public void testWritesInfoWhenNoSpans(){
+    TraceMetricSource source = new TraceMetricSource();
+    MetricsCollector collector = Mockito.mock(MetricsCollector.class);
+    MetricsRecordBuilder builder = Mockito.mock(MetricsRecordBuilder.class);
+    Mockito.when(collector.addRecord(Mockito.anyString())).thenReturn(builder);
+
+    source.getMetrics(collector, true);
+
+    // verify that we add a record and that the record has some info
+    Mockito.verify(collector).addRecord(Mockito.anyString());
+    Mockito.verify(builder).add(Mockito.any(MetricsTag.class));
+  }
+
+  private Span getSpan(){
+    return new MilliSpan("test span", 0, 1 , 2, "pid");
+  }
+}
\ No newline at end of file


Mime
View raw message