Java Code Examples for org.apache.htrace.Span

The following examples show how to use org.apache.htrace.Span. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: DFSInputStream.java    License: Apache License 2.0 6 votes vote down vote up
private Callable<ByteBuffer> getFromOneDataNode(final DNAddrPair datanode,
    final LocatedBlock block, final long start, final long end,
    final ByteBuffer bb,
    final Map<ExtendedBlock, Set<DatanodeInfo>> corruptedBlockMap,
    final int hedgedReadId) {
  final Span parentSpan = Trace.currentSpan();
  return new Callable<ByteBuffer>() {
    @Override
    public ByteBuffer call() throws Exception {
      byte[] buf = bb.array();
      int offset = bb.position();
      TraceScope scope =
          Trace.startSpan("hedgedRead" + hedgedReadId, parentSpan);
      try {
        actualGetFromOneDataNode(datanode, block, start, end, buf, offset,
            corruptedBlockMap);
        return bb;
      } finally {
        scope.close();
      }
    }
  };
}
 
Example 2
Source Project: hadoop   Source File: ProtoUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static RpcRequestHeaderProto makeRpcRequestHeader(RPC.RpcKind rpcKind,
    RpcRequestHeaderProto.OperationProto operation, int callId,
    int retryCount, byte[] uuid) {
  RpcRequestHeaderProto.Builder result = RpcRequestHeaderProto.newBuilder();
  result.setRpcKind(convert(rpcKind)).setRpcOp(operation).setCallId(callId)
      .setRetryCount(retryCount).setClientId(ByteString.copyFrom(uuid));

  // Add tracing info if we are currently tracing.
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    result.setTraceInfo(RPCTraceInfoProto.newBuilder()
        .setParentId(s.getSpanId())
        .setTraceId(s.getTraceId()).build());
  }

  return result.build();
}
 
Example 3
Source Project: big-c   Source File: DFSInputStream.java    License: Apache License 2.0 6 votes vote down vote up
private Callable<ByteBuffer> getFromOneDataNode(final DNAddrPair datanode,
    final LocatedBlock block, final long start, final long end,
    final ByteBuffer bb,
    final Map<ExtendedBlock, Set<DatanodeInfo>> corruptedBlockMap,
    final int hedgedReadId) {
  final Span parentSpan = Trace.currentSpan();
  return new Callable<ByteBuffer>() {
    @Override
    public ByteBuffer call() throws Exception {
      byte[] buf = bb.array();
      int offset = bb.position();
      TraceScope scope =
          Trace.startSpan("hedgedRead" + hedgedReadId, parentSpan);
      try {
        actualGetFromOneDataNode(datanode, block, start, end, buf, offset,
            corruptedBlockMap);
        return bb;
      } finally {
        scope.close();
      }
    }
  };
}
 
Example 4
Source Project: big-c   Source File: ProtoUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static RpcRequestHeaderProto makeRpcRequestHeader(RPC.RpcKind rpcKind,
    RpcRequestHeaderProto.OperationProto operation, int callId,
    int retryCount, byte[] uuid) {
  RpcRequestHeaderProto.Builder result = RpcRequestHeaderProto.newBuilder();
  result.setRpcKind(convert(rpcKind)).setRpcOp(operation).setCallId(callId)
      .setRetryCount(retryCount).setClientId(ByteString.copyFrom(uuid));

  // Add tracing info if we are currently tracing.
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    result.setTraceInfo(RPCTraceInfoProto.newBuilder()
        .setParentId(s.getSpanId())
        .setTraceId(s.getTraceId()).build());
  }

  return result.build();
}
 
Example 5
Source Project: phoenix   Source File: TraceReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Do the same sorting that we would get from reading the table with a {@link TraceReader},
 * specifically, by trace and then by start/end. However, these are only every stored in a
 * single trace, so we can just sort on start/end times.
 */
@Override
public int compareTo(SpanInfo o) {
    // root span always comes first
    if (this.parentId == Span.ROOT_SPAN_ID) {
        return -1;
    } else if (o.parentId == Span.ROOT_SPAN_ID) {
        return 1;
    }

    int compare = Longs.compare(start, o.start);
    if (compare == 0) {
        compare = Longs.compare(end, o.end);
        if (compare == 0) {
            return Longs.compare(id, o.id);
        }
    }
    return compare;
}
 
Example 6
Source Project: phoenix   Source File: TraceReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder("Span: " + id + "\n");
    sb.append("\tdescription=" + description);
    sb.append("\n");
    sb.append("\tparent="
            + (parent == null ? (parentId == Span.ROOT_SPAN_ID ? "ROOT" : "[orphan - id: "
                    + parentId + "]") : parent.id));
    sb.append("\n");
    sb.append("\tstart,end=" + start + "," + end);
    sb.append("\n");
    sb.append("\telapsed=" + (end - start));
    sb.append("\n");
    sb.append("\thostname=" + hostname);
    sb.append("\n");
    sb.append("\ttags=(" + tagCount + ") " + tags);
    sb.append("\n");
    sb.append("\tannotations=(" + annotationCount + ") " + annotations);
    sb.append("\n");
    sb.append("\tchildren=");
    for (SpanInfo child : children) {
        sb.append(child.id + ", ");
    }
    sb.append("\n");
    return sb.toString();
}
 
Example 7
Source Project: phoenix   Source File: PhoenixTraceReaderIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void singleSpan() throws Exception {
    PhoenixMetricsSink sink = new PhoenixMetricsSink();
    Properties props = new Properties(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    sink.initForTesting(conn);

    // create a simple metrics record
    long traceid = 987654;
    MetricsRecord record =
            createAndFlush(sink, traceid, Span.ROOT_SPAN_ID, 10, "root", 12, 13,
                "host-name.value", "test annotation for a span");

    // start a reader
    validateTraces(Collections.singletonList(record), conn, traceid);
}
 
Example 8
Source Project: phoenix   Source File: TraceMetricsSourceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source Project: phoenix   Source File: IndexRegionObserver.java    License: Apache License 2.0 6 votes vote down vote up
private void doIndexWritesWithExceptions(BatchMutateContext context, boolean post)
          throws IOException {
    ListMultimap<HTableInterfaceReference, Mutation> indexUpdates = post ? context.postIndexUpdates : context.preIndexUpdates;
    //short circuit, if we don't need to do any work

    if (context == null || indexUpdates == null || indexUpdates.isEmpty()) {
        return;
    }

    // get the current span, or just use a null-span to avoid a bunch of if statements
    try (TraceScope scope = Trace.startSpan("Completing " + (post ? "post" : "pre") + " index writes")) {
        Span current = scope.getSpan();
        if (current == null) {
            current = NullSpan.INSTANCE;
        }
        current.addTimelineAnnotation("Actually doing " + (post ? "post" : "pre") + " index update for first time");
        if (post) {
            postWriter.write(indexUpdates, false, context.clientVersion);
        } else {
            preWriter.write(indexUpdates, false, context.clientVersion);
        }
    }
}
 
Example 10
Source Project: phoenix   Source File: TraceReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Do the same sorting that we would get from reading the table with a {@link TraceReader},
 * specifically, by trace and then by start/end. However, these are only every stored in a
 * single trace, so we can just sort on start/end times.
 */
@Override
public int compareTo(SpanInfo o) {
    // root span always comes first
    if (this.parentId == Span.ROOT_SPAN_ID) {
        return -1;
    } else if (o.parentId == Span.ROOT_SPAN_ID) {
        return 1;
    }

    int compare = Longs.compare(start, o.start);
    if (compare == 0) {
        compare = Longs.compare(end, o.end);
        if (compare == 0) {
            return Longs.compare(id, o.id);
        }
    }
    return compare;
}
 
Example 11
Source Project: phoenix   Source File: TraceReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder("Span: " + id + "\n");
    sb.append("\tdescription=" + description);
    sb.append("\n");
    sb.append("\tparent="
            + (parent == null ? (parentId == Span.ROOT_SPAN_ID ? "ROOT" : "[orphan - id: "
                    + parentId + "]") : parent.id));
    sb.append("\n");
    sb.append("\tstart,end=" + start + "," + end);
    sb.append("\n");
    sb.append("\telapsed=" + (end - start));
    sb.append("\n");
    sb.append("\thostname=" + hostname);
    sb.append("\n");
    sb.append("\ttags=(" + tagCount + ") " + tags);
    sb.append("\n");
    sb.append("\tannotations=(" + annotationCount + ") " + annotations);
    sb.append("\n");
    sb.append("\tchildren=");
    for (SpanInfo child : children) {
        sb.append(child.id + ", ");
    }
    sb.append("\n");
    return sb.toString();
}
 
Example 12
Source Project: phoenix   Source File: TraceWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    if (conn == null) return;
    while (!traceSpanReceiver.isSpanAvailable()) {
        Span span = traceSpanReceiver.getSpan();
        if (null == span) break;
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Span received: " + span.toJson());
        }
        addToBatch(span);
        counter++;
        if (counter >= batchSize) {
            commitBatch(conn);
            counter = 0;
        }
    }
}
 
Example 13
Source Project: phoenix   Source File: TraceSpanReceiverTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  Trace.addReceiver(source);

  Tracer.getInstance().deliver(span);

  assertTrue(source.getNumSpans() == 1);
}
 
Example 14
Source Project: hadoop   Source File: Sender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void releaseShortCircuitFds(SlotId slotId) throws IOException {
  ReleaseShortCircuitAccessRequestProto.Builder builder =
      ReleaseShortCircuitAccessRequestProto.newBuilder().
      setSlotId(PBHelper.convert(slotId));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ReleaseShortCircuitAccessRequestProto proto = builder.build();
  send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto);
}
 
Example 15
Source Project: hadoop   Source File: Sender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void requestShortCircuitShm(String clientName) throws IOException {
  ShortCircuitShmRequestProto.Builder builder =
      ShortCircuitShmRequestProto.newBuilder().
      setClientName(clientName);
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ShortCircuitShmRequestProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto);
}
 
Example 16
Source Project: hadoop   Source File: DataTransferProtoUtil.java    License: Apache License 2.0 5 votes vote down vote up
static BaseHeaderProto buildBaseHeader(ExtendedBlock blk,
    Token<BlockTokenIdentifier> blockToken) {
  BaseHeaderProto.Builder builder =  BaseHeaderProto.newBuilder()
    .setBlock(PBHelper.convert(blk))
    .setToken(PBHelper.convert(blockToken));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId())
        .setParentId(s.getSpanId()));
  }
  return builder.build();
}
 
Example 17
Source Project: hadoop   Source File: DFSClient.java    License: Apache License 2.0 5 votes vote down vote up
TraceScope getPathTraceScope(String description, String path) {
  TraceScope scope = Trace.startSpan(description, traceSampler);
  Span span = scope.getSpan();
  if (span != null) {
    if (path != null) {
      span.addKVAnnotation(PATH,
          path.getBytes(Charset.forName("UTF-8")));
    }
  }
  return scope;
}
 
Example 18
Source Project: hadoop   Source File: DFSClient.java    License: Apache License 2.0 5 votes vote down vote up
TraceScope getSrcDstTraceScope(String description, String src, String dst) {
  TraceScope scope = Trace.startSpan(description, traceSampler);
  Span span = scope.getSpan();
  if (span != null) {
    if (src != null) {
      span.addKVAnnotation(SRC,
          src.getBytes(Charset.forName("UTF-8")));
    }
    if (dst != null) {
      span.addKVAnnotation(DST,
          dst.getBytes(Charset.forName("UTF-8")));
    }
  }
  return scope;
}
 
Example 19
Source Project: hadoop   Source File: BlockStorageLocationUtil.java    License: Apache License 2.0 5 votes vote down vote up
VolumeBlockLocationCallable(Configuration configuration,
    DatanodeInfo datanode, String poolId, long []blockIds,
    List<Token<BlockTokenIdentifier>> dnTokens, int timeout, 
    boolean connectToDnViaHostname, Span parentSpan) {
  this.configuration = configuration;
  this.timeout = timeout;
  this.datanode = datanode;
  this.poolId = poolId;
  this.blockIds = blockIds;
  this.dnTokens = dnTokens;
  this.connectToDnViaHostname = connectToDnViaHostname;
  this.parentSpan = parentSpan;
}
 
Example 20
Source Project: hadoop   Source File: TestTracing.java    License: Apache License 2.0 5 votes vote down vote up
public void readWithTracing() throws Exception {
  String fileName = "testReadTraceHooks.dat";
  writeTestFile(fileName);
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS);
  readTestFile(fileName);
  ts.close();
  long endTime = System.currentTimeMillis();

  String[] expectedSpanNames = {
    "testReadTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations",
    "ClientNamenodeProtocol#getBlockLocations",
    "OpReadBlockProto"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testReadTraceHooks").get(0);
  Assert.assertNotNull(s);

  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();
  Assert.assertTrue(spanStart - startTime < 100);
  Assert.assertTrue(spanEnd - endTime < 100);

  // There should only be one trace id as it should all be homed in the
  // top trace.
  for (Span span : SetSpanReceiver.SetHolder.spans.values()) {
    Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
  }
  SetSpanReceiver.SetHolder.spans.clear();
}
 
Example 21
Source Project: hadoop   Source File: TestTracing.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<String, List<Span>> getMap() {
  Map<String, List<Span>> map = new HashMap<String, List<Span>>();

  for (Span s : spans.values()) {
    List<Span> l = map.get(s.getDescription());
    if (l == null) {
      l = new LinkedList<Span>();
      map.put(s.getDescription(), l);
    }
    l.add(s);
  }
  return map;
}
 
Example 22
Source Project: hadoop   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
public Call(int id, int retryCount, Writable param, Connection connection,
    RPC.RpcKind kind, byte[] clientId, Span span) {
  this.callId = id;
  this.retryCount = retryCount;
  this.rpcRequest = param;
  this.connection = connection;
  this.timestamp = Time.now();
  this.rpcResponse = null;
  this.rpcKind = kind;
  this.clientId = clientId;
  this.traceSpan = span;
}
 
Example 23
Source Project: big-c   Source File: Sender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void releaseShortCircuitFds(SlotId slotId) throws IOException {
  ReleaseShortCircuitAccessRequestProto.Builder builder =
      ReleaseShortCircuitAccessRequestProto.newBuilder().
      setSlotId(PBHelper.convert(slotId));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ReleaseShortCircuitAccessRequestProto proto = builder.build();
  send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto);
}
 
Example 24
Source Project: big-c   Source File: Sender.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void requestShortCircuitShm(String clientName) throws IOException {
  ShortCircuitShmRequestProto.Builder builder =
      ShortCircuitShmRequestProto.newBuilder().
      setClientName(clientName);
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ShortCircuitShmRequestProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto);
}
 
Example 25
Source Project: big-c   Source File: DataTransferProtoUtil.java    License: Apache License 2.0 5 votes vote down vote up
static BaseHeaderProto buildBaseHeader(ExtendedBlock blk,
    Token<BlockTokenIdentifier> blockToken) {
  BaseHeaderProto.Builder builder =  BaseHeaderProto.newBuilder()
    .setBlock(PBHelper.convert(blk))
    .setToken(PBHelper.convert(blockToken));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId())
        .setParentId(s.getSpanId()));
  }
  return builder.build();
}
 
Example 26
Source Project: big-c   Source File: DFSClient.java    License: Apache License 2.0 5 votes vote down vote up
TraceScope getPathTraceScope(String description, String path) {
  TraceScope scope = Trace.startSpan(description, traceSampler);
  Span span = scope.getSpan();
  if (span != null) {
    if (path != null) {
      span.addKVAnnotation(PATH,
          path.getBytes(Charset.forName("UTF-8")));
    }
  }
  return scope;
}
 
Example 27
Source Project: big-c   Source File: DFSClient.java    License: Apache License 2.0 5 votes vote down vote up
TraceScope getSrcDstTraceScope(String description, String src, String dst) {
  TraceScope scope = Trace.startSpan(description, traceSampler);
  Span span = scope.getSpan();
  if (span != null) {
    if (src != null) {
      span.addKVAnnotation(SRC,
          src.getBytes(Charset.forName("UTF-8")));
    }
    if (dst != null) {
      span.addKVAnnotation(DST,
          dst.getBytes(Charset.forName("UTF-8")));
    }
  }
  return scope;
}
 
Example 28
Source Project: big-c   Source File: BlockStorageLocationUtil.java    License: Apache License 2.0 5 votes vote down vote up
VolumeBlockLocationCallable(Configuration configuration,
    DatanodeInfo datanode, String poolId, long []blockIds,
    List<Token<BlockTokenIdentifier>> dnTokens, int timeout, 
    boolean connectToDnViaHostname, Span parentSpan) {
  this.configuration = configuration;
  this.timeout = timeout;
  this.datanode = datanode;
  this.poolId = poolId;
  this.blockIds = blockIds;
  this.dnTokens = dnTokens;
  this.connectToDnViaHostname = connectToDnViaHostname;
  this.parentSpan = parentSpan;
}
 
Example 29
Source Project: big-c   Source File: TestTracing.java    License: Apache License 2.0 5 votes vote down vote up
public void readWithTracing() throws Exception {
  String fileName = "testReadTraceHooks.dat";
  writeTestFile(fileName);
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS);
  readTestFile(fileName);
  ts.close();
  long endTime = System.currentTimeMillis();

  String[] expectedSpanNames = {
    "testReadTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations",
    "ClientNamenodeProtocol#getBlockLocations",
    "OpReadBlockProto"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testReadTraceHooks").get(0);
  Assert.assertNotNull(s);

  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();
  Assert.assertTrue(spanStart - startTime < 100);
  Assert.assertTrue(spanEnd - endTime < 100);

  // There should only be one trace id as it should all be homed in the
  // top trace.
  for (Span span : SetSpanReceiver.SetHolder.spans.values()) {
    Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
  }
  SetSpanReceiver.SetHolder.spans.clear();
}
 
Example 30
Source Project: big-c   Source File: TestTracing.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<String, List<Span>> getMap() {
  Map<String, List<Span>> map = new HashMap<String, List<Span>>();

  for (Span s : spans.values()) {
    List<Span> l = map.get(s.getDescription());
    if (l == null) {
      l = new LinkedList<Span>();
      map.put(s.getDescription(), l);
    }
    l.add(s);
  }
  return map;
}