Search in sources :

Example 1 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class DependencyLinker method merge.

/** links are merged by mapping to parent/child and summing corresponding links */
public static List<DependencyLink> merge(Iterable<DependencyLink> in) {
    Map<Pair<String>, Long> links = new LinkedHashMap<>();
    for (DependencyLink link : in) {
        Pair<String> parentChild = Pair.create(link.parent, link.child);
        long callCount = links.containsKey(parentChild) ? links.get(parentChild) : 0L;
        callCount += link.callCount;
        links.put(parentChild, callCount);
    }
    List<DependencyLink> result = new ArrayList<>(links.size());
    for (Map.Entry<Pair<String>, Long> link : links.entrySet()) {
        result.add(DependencyLink.create(link.getKey()._1, link.getKey()._2, link.getValue()));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DependencyLink(zipkin.DependencyLink) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class CassandraDependenciesTest method processDependencies.

/**
   * The current implementation does not include dependency aggregation. It includes retrieval of
   * pre-aggregated links.
   *
   * <p>This uses {@link InMemorySpanStore} to prepare links and {@link CassandraDependenciesWriter}
   * to store them.
   *
   * <p>Note: The zipkin-dependencies-spark doesn't use any of these classes: it reads and writes to
   * the keyspace directly.
   */
@Override
public void processDependencies(List<Span> spans) {
    InMemoryStorage mem = new InMemoryStorage();
    mem.spanConsumer().accept(spans);
    List<DependencyLink> links = mem.spanStore().getDependencies(TODAY + DAY, null);
    // This gets or derives a timestamp from the spans
    long midnight = midnightUTC(MergeById.apply(spans).get(0).timestamp / 1000);
    new CassandraDependenciesWriter(storage.session.get()).write(links, midnight);
}
Also used : InMemoryStorage(zipkin.storage.InMemoryStorage) DependencyLink(zipkin.DependencyLink)

Example 3 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class MySQLSpanStore method getDependencies.

@Override
public List<DependencyLink> getDependencies(long endTs, @Nullable Long lookback) {
    try (Connection conn = datasource.getConnection()) {
        if (schema.hasPreAggregatedDependencies) {
            List<Date> days = getDays(endTs, lookback);
            List<DependencyLink> unmerged = context.get(conn).selectFrom(ZIPKIN_DEPENDENCIES).where(ZIPKIN_DEPENDENCIES.DAY.in(days)).fetch((Record l) -> DependencyLink.create(l.get(ZIPKIN_DEPENDENCIES.PARENT), l.get(ZIPKIN_DEPENDENCIES.CHILD), l.get(ZIPKIN_DEPENDENCIES.CALL_COUNT)));
            return DependencyLinker.merge(unmerged);
        } else {
            return aggregateDependencies(endTs, lookback, conn);
        }
    } catch (SQLException e) {
        throw new RuntimeException("Error querying dependencies for endTs " + endTs + " and lookback " + lookback + ": " + e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) Record(org.jooq.Record) DependencyLink(zipkin.DependencyLink) Date(java.util.Date)

Example 4 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class JsonAdaptersTest method dependencyLinkRoundTrip.

@Test
public void dependencyLinkRoundTrip() throws IOException {
    DependencyLink link = DependencyLink.create("foo", "bar", 2);
    Buffer bytes = new Buffer();
    bytes.write(Codec.JSON.writeDependencyLink(link));
    assertThat(JsonAdapters.DEPENDENCY_LINK_ADAPTER.fromJson(bytes)).isEqualTo(link);
}
Also used : Buffer(okio.Buffer) ByteBuffer(java.nio.ByteBuffer) DependencyLink(zipkin.DependencyLink) Test(org.junit.Test)

Example 5 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class ElasticsearchHttpDependenciesTest method processDependencies.

/**
   * The current implementation does not include dependency aggregation. It includes retrieval of
   * pre-aggregated links.
   */
@Override
public void processDependencies(List<Span> spans) {
    InMemoryStorage mem = new InMemoryStorage();
    mem.spanConsumer().accept(spans);
    List<DependencyLink> links = mem.spanStore().getDependencies(TODAY + DAY, null);
    // This gets or derives a timestamp from the spans
    long midnightUTC = midnightUTC(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
    InternalForTests.writeDependencyLinks(storage(), links, midnightUTC);
}
Also used : InMemoryStorage(zipkin.storage.InMemoryStorage) DependencyLink(zipkin.DependencyLink)

Aggregations

DependencyLink (zipkin.DependencyLink)10 InMemoryStorage (zipkin.storage.InMemoryStorage)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CallbackCaptor (zipkin.internal.CallbackCaptor)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Buffer (okio.Buffer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 FlushRequest (org.elasticsearch.action.admin.indices.flush.FlushRequest)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1