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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations