Search in sources :

Example 6 with Span

use of org.apache.htrace.Span in project hbase by apache.

the class TestHTraceHooks method testTraceCreateTable.

@Test
public void testTraceCreateTable() throws Exception {
    TraceScope tableCreationSpan = Trace.startSpan("creating table", Sampler.ALWAYS);
    Table table;
    try {
        table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY_BYTES);
    } finally {
        tableCreationSpan.close();
    }
    // Some table creation is async.  Need to make sure that everything is full in before
    // checking to see if the spans are there.
    TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return rcvr.getSpans().size() >= 5;
        }
    });
    Collection<Span> spans = rcvr.getSpans();
    TraceTree traceTree = new TraceTree(spans);
    Collection<Span> roots = traceTree.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(1, roots.size());
    Span createTableRoot = roots.iterator().next();
    assertEquals("creating table", createTableRoot.getDescription());
    int createTableCount = 0;
    for (Span s : traceTree.getSpansByParent().find(createTableRoot.getSpanId())) {
        if (s.getDescription().startsWith("MasterService.CreateTable")) {
            createTableCount++;
        }
    }
    assertTrue(createTableCount >= 1);
    assertTrue(traceTree.getSpansByParent().find(createTableRoot.getSpanId()).size() > 3);
    assertTrue(spans.size() > 5);
    Put put = new Put("row".getBytes());
    put.addColumn(FAMILY_BYTES, "col".getBytes(), "value".getBytes());
    TraceScope putSpan = Trace.startSpan("doing put", Sampler.ALWAYS);
    try {
        table.put(put);
    } finally {
        putSpan.close();
    }
    spans = rcvr.getSpans();
    traceTree = new TraceTree(spans);
    roots = traceTree.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(2, roots.size());
    Span putRoot = null;
    for (Span root : roots) {
        if (root.getDescription().equals("doing put")) {
            putRoot = root;
        }
    }
    assertNotNull(putRoot);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TraceScope(org.apache.htrace.TraceScope) Waiter(org.apache.hadoop.hbase.Waiter) Span(org.apache.htrace.Span) TraceTree(org.apache.htrace.TraceTree) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 7 with Span

use of org.apache.htrace.Span in project phoenix by apache.

the class TraceMetricsSourceTest method testNonIntegerAnnotations.

/**
   * 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
    TraceSpanReceiver source = new TraceSpanReceiver();
    source.receiveSpan(span);
    assertTrue(source.getSpanQueue().size() == 1);
}
Also used : MilliSpan(org.apache.htrace.impl.MilliSpan) Span(org.apache.htrace.Span) Test(org.junit.Test)

Example 8 with Span

use of org.apache.htrace.Span in project phoenix by apache.

the class TraceMetricsSourceTest method testIntegerAnnotations.

@Test
public void testIntegerAnnotations() {
    Span span = getSpan();
    // add annotation through the phoenix interfaces
    TracingUtils.addAnnotation(span, "message", 10);
    TraceSpanReceiver source = new TraceSpanReceiver();
    source.receiveSpan(span);
    assertTrue(source.getSpanQueue().size() == 1);
}
Also used : MilliSpan(org.apache.htrace.impl.MilliSpan) Span(org.apache.htrace.Span) Test(org.junit.Test)

Example 9 with Span

use of org.apache.htrace.Span in project phoenix by apache.

the class PhoenixTransactionalIndexer method preBatchMutate.

@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    Mutation m = miniBatchOp.getOperation(0);
    if (!codec.isEnabled(m)) {
        super.preBatchMutate(c, miniBatchOp);
        return;
    }
    Map<String, byte[]> updateAttributes = m.getAttributesMap();
    PhoenixIndexMetaData indexMetaData = new PhoenixIndexMetaData(c.getEnvironment(), updateAttributes);
    byte[] txRollbackAttribute = m.getAttribute(TxConstants.TX_ROLLBACK_ATTRIBUTE_KEY);
    Collection<Pair<Mutation, byte[]>> indexUpdates = null;
    // get the current span, or just use a null-span to avoid a bunch of if statements
    try (TraceScope scope = Trace.startSpan("Starting to build index updates")) {
        Span current = scope.getSpan();
        if (current == null) {
            current = NullSpan.INSTANCE;
        }
        // get the index updates for all elements in this batch
        indexUpdates = getIndexUpdates(c.getEnvironment(), indexMetaData, getMutationIterator(miniBatchOp), txRollbackAttribute);
        current.addTimelineAnnotation("Built index updates, doing preStep");
        TracingUtils.addAnnotation(current, "index update count", indexUpdates.size());
        // no index updates, so we are done
        if (!indexUpdates.isEmpty()) {
            this.writer.write(indexUpdates, true);
        }
    } catch (Throwable t) {
        String msg = "Failed to update index with entries:" + indexUpdates;
        LOG.error(msg, t);
        ServerUtil.throwIOException(msg, t);
    }
}
Also used : TraceScope(org.apache.htrace.TraceScope) Mutation(org.apache.hadoop.hbase.client.Mutation) MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) Span(org.apache.htrace.Span) NullSpan(org.apache.phoenix.trace.util.NullSpan) Pair(org.apache.hadoop.hbase.util.Pair)

Example 10 with Span

use of org.apache.htrace.Span in project phoenix by apache.

the class PhoenixTableMetricsWriterIT method writeMetrics.

/**
     * Simple metrics writing and reading check, that uses the standard wrapping in the
     * {@link TraceWriter}
     * @throws Exception on failure
     */
@Test
public void writeMetrics() throws Exception {
    Connection conn = getConnectionWithoutTracing();
    String tableName = generateUniqueName();
    TraceSpanReceiver traceSpanReceiver = new TraceSpanReceiver();
    latch = new CountDownLatch(1);
    testTraceWriter = new TestTraceWriter(tableName, defaultTracingThreadPoolForTest, defaultTracingBatchSizeForTest);
    // create a simple metrics record
    long traceid = 987654;
    String description = "Some generic trace";
    long spanid = 10;
    long parentid = 11;
    long startTime = 12;
    long endTime = 13;
    String processid = "Some process";
    String annotation = "test annotation for a span";
    Span span = createNewSpan(traceid, parentid, spanid, description, startTime, endTime, processid, annotation);
    traceSpanReceiver.getSpanQueue().add(span);
    assertTrue("Span never committed to table", latch.await(30, TimeUnit.SECONDS));
    // make sure we only get expected stat entry (matcing the trace id), otherwise we could the
    // stats for the update as well
    TraceReader reader = new TraceReader(conn, tableName);
    Collection<TraceHolder> traces = reader.readAll(10);
    assertEquals("Wrong number of traces in the tracing table", 1, traces.size());
    // validate trace
    TraceHolder trace = traces.iterator().next();
    // we are just going to get an orphan span b/c we don't send in a parent
    assertEquals("Didn't get expected orphaned spans!" + trace.orphans, 1, trace.orphans.size());
    assertEquals(traceid, trace.traceid);
    SpanInfo spanInfo = trace.orphans.get(0);
    assertEquals(description, spanInfo.description);
    assertEquals(parentid, spanInfo.getParentIdForTesting());
    assertEquals(startTime, spanInfo.start);
    assertEquals(endTime, spanInfo.end);
    assertEquals("Wrong number of tags", 0, spanInfo.tagCount);
    assertEquals("Wrong number of annotations", 1, spanInfo.annotationCount);
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder) Connection(java.sql.Connection) SpanInfo(org.apache.phoenix.trace.TraceReader.SpanInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Span(org.apache.htrace.Span) Test(org.junit.Test)

Aggregations

Span (org.apache.htrace.Span)15 TraceScope (org.apache.htrace.TraceScope)7 Test (org.junit.Test)7 Connection (java.sql.Connection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Pair (org.apache.hadoop.hbase.util.Pair)4 Mutation (org.apache.hadoop.hbase.client.Mutation)3 MilliSpan (org.apache.htrace.impl.MilliSpan)3 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)3 SpanInfo (org.apache.phoenix.trace.TraceReader.SpanInfo)3 NullSpan (org.apache.phoenix.trace.util.NullSpan)3 IOException (java.io.IOException)2 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)2 TraceHolder (org.apache.phoenix.trace.TraceReader.TraceHolder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 InterruptedIOException (java.io.InterruptedIOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1