zipkin2.internal.DependencyLinker Java Examples

The following examples show how to use zipkin2.internal.DependencyLinker. 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 File: ZipkinTracerIntegrationTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void configOverridesLocalServiceName_client() throws Exception {
  tracer.close();
  tracer = newTracer("web");

  tracer.record(new Record(root, fromMilliseconds(TODAY), new ServiceName("web"), empty()));
  tracer.record(new Record(root, fromMilliseconds(TODAY), new Rpc("get"), empty()));
  tracer.record(new Record(root, fromMilliseconds(TODAY), ServerRecv$.MODULE$, empty()));
  tracer.record(new Record(root, fromMilliseconds(TODAY + 1), ServerSend$.MODULE$, empty()));

  // Here we simulate someone setting the client ServiceName to the remote host
  tracer.record(new Record(child, fromMilliseconds(TODAY), new ServiceName("app"), empty()));
  tracer.record(new Record(child, fromMilliseconds(TODAY), new Rpc("get"), empty()));
  tracer.record(new Record(child, fromMilliseconds(TODAY), ClientSend$.MODULE$, empty()));
  tracer.record(new Record(child, fromMilliseconds(TODAY + 1), ClientRecv$.MODULE$, empty()));

  Thread.sleep(2000); // the AsyncReporter thread has a default interval of 1s

  assertThat(new DependencyLinker().putTrace(getTraces().get(0)).link()).containsExactly(
      DependencyLink.newBuilder().parent("web").child("app").callCount(1).build()
  );
}
 
Example #2
Source File: SpansToDependencyLinks.java    From zipkin-dependencies with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<DependencyLink> call(Iterable<Span> spans) {
  if (logInitializer != null) logInitializer.run();
  List<Span> sameTraceId = new ArrayList<>();
  for (Span span : spans) {
    // check to see if the trace is within the interval
    if (span.parentId() == null) {
      long timestamp = span.timestampAsLong();
      if (timestamp == 0 || timestamp < startTs || timestamp > endTs) {
        return Collections.emptyList();
      }
    }
    sameTraceId.add(span);
  }
  return new DependencyLinker().putTrace(sameTraceId).link();
}
 
Example #3
Source File: RowsToDependencyLinks.java    From zipkin-dependencies with Apache License 2.0 6 votes vote down vote up
@Override public Iterable<DependencyLink> call(Iterable<Row> rows) {
  if (logInitializer != null) logInitializer.run();
  Iterator<Iterator<Span>> traces =
      new DependencyLinkSpanIterator.ByTraceId(rows.iterator(), hasTraceIdHigh);

  if (!traces.hasNext()) return Collections.emptyList();

  DependencyLinker linker = new DependencyLinker();
  List<Span> nextTrace = new ArrayList<>();
  while (traces.hasNext()) {
    Iterator<Span> i = traces.next();
    while (i.hasNext()) nextTrace.add(i.next());
    linker.putTrace(nextTrace);
    nextTrace.clear();
  }
  return linker.link();
}
 
Example #4
Source File: SpanAggregationTopology.java    From zipkin-storage-kafka with Apache License 2.0 5 votes vote down vote up
ValueMapper<List<Span>, List<DependencyLink>> spansToDependencyLinks() {
  return (spans) -> {
    if (spans == null) return new ArrayList<>();
    DependencyLinker linker = new DependencyLinker();
    return linker.putTrace(spans).link();
  };
}
 
Example #5
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 5 votes vote down vote up
@Get("/dependencies")
public AggregatedHttpResponse getDependencies(
    @Param("endTs") long endTs,
    @Param("lookback") long lookback
) {
  try {
    if (!storage.dependencyQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    ReadOnlyWindowStore<Long, DependencyLink> store =
        storage.getDependencyStorageStream()
            .store(DEPENDENCIES_STORE_NAME, QueryableStoreTypes.windowStore());
    List<DependencyLink> links = new ArrayList<>();
    Instant from = Instant.ofEpochMilli(endTs - lookback);
    Instant to = Instant.ofEpochMilli(endTs);
    try (KeyValueIterator<Windowed<Long>, DependencyLink> iterator = store.fetchAll(from, to)) {
      iterator.forEachRemaining(keyValue -> links.add(keyValue.value));
    }
    List<DependencyLink> mergedLinks = DependencyLinker.merge(links);
    LOG.debug("Dependencies found from={}-to={}: {}", from, to, mergedLinks.size());
    return AggregatedHttpResponse.of(
        HttpStatus.OK,
        MediaType.JSON,
        DependencyLinkBytesEncoder.JSON_V1.encodeList(mergedLinks));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #6
Source File: CassandraRowsToDependencyLinks.java    From zipkin-dependencies with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<DependencyLink> call(Iterable<CassandraRow> rows) {
  if (logInitializer != null) logInitializer.run();
  V1ThriftSpanReader reader = V1ThriftSpanReader.create();
  V1SpanConverter converter = V1SpanConverter.create();
  List<Span> sameTraceId = new ArrayList<>();
  for (CassandraRow row : rows) {
    try {
      V1Span v1Span = reader.read(ReadBuffer.wrapUnsafe(row.getBytes("span")));
      for (Span span : converter.convert(v1Span)) {
        // check to see if the trace is within the interval
        if (span.parentId() == null) {
          long timestamp = span.timestampAsLong();
          if (timestamp == 0 || timestamp < startTs || timestamp > endTs) {
            return Collections.emptyList();
          }
        }
        sameTraceId.add(span);
      }
    } catch (RuntimeException e) {
      log.warn(
          String.format(
              "Unable to decode span from traces where trace_id=%s and ts=%s and span_name='%s'",
              row.getLong("trace_id"), row.getDate("ts").getTime(), row.getString("span_name")),
          e);
    }
  }
  return new DependencyLinker().putTrace(sameTraceId).link();
}
 
Example #7
Source File: TraceIdAndJsonToDependencyLinks.java    From zipkin-dependencies with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<DependencyLink> call(Iterable<Tuple2<String, String>> traceIdJson) {
  if (logInitializer != null) logInitializer.run();
  List<Span> sameTraceId = new ArrayList<>();
  for (Tuple2<String, String> row : traceIdJson) {
    try {
      decoder.decode(row._2.getBytes(ElasticsearchDependenciesJob.UTF_8), sameTraceId);
    } catch (Exception e) {
      log.warn("Unable to decode span from traces where trace_id=" + row._1, e);
    }
  }
  DependencyLinker linker = new DependencyLinker();
  linker.putTrace(sameTraceId);
  return linker.link();
}