Search in sources :

Example 1 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder in project phoenix by apache.

the class PhoenixTracingEndToEndIT method testScanTracing.

@Test
public void testScanTracing() throws Exception {
    // separate connections to minimize amount of traces that are generated
    Connection traceable = getTracingConnection();
    Connection conn = getConnectionWithoutTracing();
    // one call for client side, one call for server side
    latch = new CountDownLatch(2);
    testTraceWriter = new TestTraceWriter(tracingTableName, defaultTracingThreadPoolForTest, defaultTracingBatchSizeForTest);
    // create a dummy table
    createTestTable(conn, false);
    // update the table, but don't trace these, to simplify the traces we read
    LOG.debug("Doing dummy the writes to the tracked table");
    String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
    PreparedStatement stmt = conn.prepareStatement(insert);
    stmt.setString(1, "key1");
    stmt.setLong(2, 1);
    stmt.execute();
    conn.commit();
    conn.rollback();
    // setup for next set of updates
    stmt.setString(1, "key2");
    stmt.setLong(2, 2);
    stmt.execute();
    conn.commit();
    conn.rollback();
    // do a scan of the table
    String read = "SELECT * FROM " + enabledForLoggingTable;
    ResultSet results = traceable.createStatement().executeQuery(read);
    assertTrue("Didn't get first result", results.next());
    assertTrue("Didn't get second result", results.next());
    results.close();
    assertTrue("Get expected updates to trace table", latch.await(200, TimeUnit.SECONDS));
    // don't trace reads either
    boolean tracingComplete = checkStoredTraces(conn, new TraceChecker() {

        @Override
        public boolean foundTrace(TraceHolder currentTrace) {
            String traceInfo = currentTrace.toString();
            return traceInfo.contains("Parallel scanner");
        }
    });
    assertTrue("Didn't find the parallel scanner in the tracing", tracingComplete);
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder 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)

Example 3 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder in project phoenix by apache.

the class PhoenixTracingEndToEndIT method testScanTracingOnServer.

@Test
public void testScanTracingOnServer() throws Exception {
    // separate connections to minimize amount of traces that are generated
    Connection traceable = getTracingConnection();
    Connection conn = getConnectionWithoutTracing();
    // one call for client side, one call for server side
    latch = new CountDownLatch(5);
    testTraceWriter = new TestTraceWriter(tracingTableName, defaultTracingThreadPoolForTest, defaultTracingBatchSizeForTest);
    // create a dummy table
    createTestTable(conn, false);
    // update the table, but don't trace these, to simplify the traces we read
    LOG.debug("Doing dummy the writes to the tracked table");
    String insert = "UPSERT INTO " + enabledForLoggingTable + " VALUES (?, ?)";
    PreparedStatement stmt = conn.prepareStatement(insert);
    stmt.setString(1, "key1");
    stmt.setLong(2, 1);
    stmt.execute();
    conn.commit();
    // setup for next set of updates
    stmt.setString(1, "key2");
    stmt.setLong(2, 2);
    stmt.execute();
    conn.commit();
    // do a scan of the table
    String read = "SELECT COUNT(*) FROM " + enabledForLoggingTable;
    ResultSet results = traceable.createStatement().executeQuery(read);
    assertTrue("Didn't get count result", results.next());
    // make sure we got the expected count
    assertEquals("Didn't get the expected number of row", 2, results.getInt(1));
    results.close();
    assertTrue("Didn't get expected updates to trace table", latch.await(60, TimeUnit.SECONDS));
    // don't trace reads either
    boolean found = checkStoredTraces(conn, new TraceChecker() {

        @Override
        public boolean foundTrace(TraceHolder trace) {
            String traceInfo = trace.toString();
            return traceInfo.contains(BaseScannerRegionObserver.SCANNER_OPENED_TRACE_INFO);
        }
    });
    assertTrue("Didn't find the parallel scanner in the tracing", found);
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder in project phoenix by apache.

the class PhoenixTracingEndToEndIT method validateTraces.

private void validateTraces(List<Span> spans, Connection conn, long traceid, String tableName) throws Exception {
    TraceReader reader = new TraceReader(conn, tableName);
    Collection<TraceHolder> traces = reader.readAll(1);
    assertEquals("Got an unexpected number of traces!", 1, traces.size());
    // make sure the trace matches what we wrote
    TraceHolder trace = traces.iterator().next();
    assertEquals("Got an unexpected traceid", traceid, trace.traceid);
    assertEquals("Got an unexpected number of spans", spans.size(), trace.spans.size());
    validateTrace(spans, trace);
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder)

Example 5 with TraceHolder

use of org.apache.phoenix.trace.TraceReader.TraceHolder in project phoenix by apache.

the class PhoenixTracingEndToEndIT method testWriteSpans.

/**
     * Simple test that we can correctly write spans to the phoenix table
     * @throws Exception on failure
     */
@Test
public void testWriteSpans() throws Exception {
    // watch our sink so we know when commits happen
    latch = new CountDownLatch(1);
    testTraceWriter = new TestTraceWriter(tracingTableName, defaultTracingThreadPoolForTest, defaultTracingBatchSizeForTest);
    // write some spans
    TraceScope trace = Trace.startSpan("Start write test", Sampler.ALWAYS);
    Span span = trace.getSpan();
    // add a child with some annotations
    Span child = span.child("child 1");
    child.addTimelineAnnotation("timeline annotation");
    TracingUtils.addAnnotation(child, "test annotation", 10);
    child.stop();
    // sleep a little bit to get some time difference
    Thread.sleep(100);
    trace.close();
    // pass the trace on
    Tracing.getTraceSpanReceiver().receiveSpan(span);
    // wait for the tracer to actually do the write
    assertTrue("Sink not flushed. commit() not called on the connection", latch.await(60, TimeUnit.SECONDS));
    // look for the writes to make sure they were made
    Connection conn = getConnectionWithoutTracing();
    checkStoredTraces(conn, new TraceChecker() {

        @Override
        public boolean foundTrace(TraceHolder trace, SpanInfo info) {
            if (info.description.equals("child 1")) {
                assertEquals("Not all annotations present", 1, info.annotationCount);
                assertEquals("Not all tags present", 1, info.tagCount);
                boolean found = false;
                for (String annotation : info.annotations) {
                    if (annotation.startsWith("test annotation")) {
                        found = true;
                    }
                }
                assertTrue("Missing the annotations in span: " + info, found);
                found = false;
                for (String tag : info.tags) {
                    if (tag.endsWith("timeline annotation")) {
                        found = true;
                    }
                }
                assertTrue("Missing the tags in span: " + info, found);
                return true;
            }
            return false;
        }
    });
}
Also used : TraceHolder(org.apache.phoenix.trace.TraceReader.TraceHolder) TraceScope(org.apache.htrace.TraceScope) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) SpanInfo(org.apache.phoenix.trace.TraceReader.SpanInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Span(org.apache.htrace.Span) Test(org.junit.Test)

Aggregations

TraceHolder (org.apache.phoenix.trace.TraceReader.TraceHolder)6 Connection (java.sql.Connection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Test (org.junit.Test)5 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)4 PreparedStatement (java.sql.PreparedStatement)3 SpanInfo (org.apache.phoenix.trace.TraceReader.SpanInfo)3 ResultSet (java.sql.ResultSet)2 Span (org.apache.htrace.Span)2 TraceScope (org.apache.htrace.TraceScope)1