Search in sources :

Example 6 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class ElasticsearchDependenciesTest 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 #writeDependencyLinks(List,
   * long)}} to store them.
   */
@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(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
    writeDependencyLinks(links, midnight);
}
Also used : InMemoryStorage(zipkin.storage.InMemoryStorage) DependencyLink(zipkin.DependencyLink)

Example 7 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(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
    new CassandraDependenciesWriter(storage.session.get()).write(links, midnight);
}
Also used : InMemoryStorage(zipkin.storage.InMemoryStorage) DependencyLink(zipkin.DependencyLink)

Example 8 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class ElasticsearchDependenciesTest method writeDependencyLinks.

protected void writeDependencyLinks(List<DependencyLink> links, long timestampMillis) {
    long midnight = Util.midnightUTC(timestampMillis);
    TransportClient client = ((NativeClient) storage().client()).client;
    BulkRequestBuilder request = client.prepareBulk();
    for (DependencyLink link : links) {
        request.add(client.prepareIndex(storage().indexNameFormatter.indexNameForTimestamp(midnight), ElasticsearchConstants.DEPENDENCY_LINK).setId(// Unique constraint
        link.parent + "|" + link.child).setSource("parent", link.parent, "child", link.child, "callCount", link.callCount));
    }
    request.execute().actionGet();
    client.admin().indices().flush(new FlushRequest()).actionGet();
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) DependencyLink(zipkin.DependencyLink)

Example 9 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class InternalForTests method writeDependencyLinks.

public static void writeDependencyLinks(ElasticsearchHttpStorage es, List<DependencyLink> links, long midnightUTC) {
    String index = es.indexNameFormatter().indexNameForTimestamp(midnightUTC);
    HttpBulkIndexer<DependencyLink> indexer = new HttpBulkIndexer<DependencyLink>(DEPENDENCY_LINK, es) {

        @Override
        byte[] toJsonBytes(DependencyLink link) {
            return Codec.JSON.writeDependencyLink(link);
        }
    };
    for (DependencyLink link : links) {
        // Unique constraint
        indexer.add(index, link, link.parent + "|" + link.child);
    }
    CallbackCaptor<Void> callback = new CallbackCaptor<>();
    indexer.execute(callback);
    callback.get();
}
Also used : CallbackCaptor(zipkin.internal.CallbackCaptor) DependencyLink(zipkin.DependencyLink)

Example 10 with DependencyLink

use of zipkin.DependencyLink in project zipkin by openzipkin.

the class DependenciesTest method manyLinks.

/** Ensure there's no query limit problem around links */
@Test
public void manyLinks() {
    // Larger than 10, which is the default ES search limit that tripped this
    int count = 1000;
    List<Span> spans = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        Endpoint web = WEB_ENDPOINT.toBuilder().serviceName("web-" + i).build();
        Endpoint app = APP_ENDPOINT.toBuilder().serviceName("app-" + i).build();
        Endpoint db = DB_ENDPOINT.toBuilder().serviceName("db-" + i).build();
        spans.add(Span.builder().traceId(i).id(10L).name("get").timestamp((TODAY + 50L) * 1000).duration(250L * 1000).addAnnotation(Annotation.create((TODAY + 50) * 1000, CLIENT_SEND, web)).addAnnotation(Annotation.create((TODAY + 100) * 1000, SERVER_RECV, app)).addAnnotation(Annotation.create((TODAY + 250) * 1000, SERVER_SEND, app)).addAnnotation(Annotation.create((TODAY + 300) * 1000, CLIENT_RECV, web)).build());
        spans.add(Span.builder().traceId(i).parentId(10L).id(11L).name("get").timestamp((TODAY + 150L) * 1000).duration(50L * 1000).addAnnotation(Annotation.create((TODAY + 150) * 1000, CLIENT_SEND, app)).addAnnotation(Annotation.create((TODAY + 200) * 1000, CLIENT_RECV, app)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, db)).build());
    }
    processDependencies(spans);
    List<DependencyLink> links = store().getDependencies(TODAY + 1000L, null);
    // web-? -> app-?, app-? -> db-?
    assertThat(links).hasSize(count * 2);
    assertThat(links).extracting(l -> l.callCount).allSatisfy(callCount -> assertThat(callCount).isEqualTo(1));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Annotation(zipkin.Annotation) CLIENT_ADDR(zipkin.Constants.CLIENT_ADDR) CLIENT_SEND(zipkin.Constants.CLIENT_SEND) LINKS(zipkin.TestObjects.LINKS) DEPENDENCIES(zipkin.TestObjects.DEPENDENCIES) ArrayList(java.util.ArrayList) Endpoint(zipkin.Endpoint) DAY(zipkin.TestObjects.DAY) Span(zipkin.Span) Arrays.asList(java.util.Arrays.asList) SERVER_SEND(zipkin.Constants.SERVER_SEND) WEB_ENDPOINT(zipkin.TestObjects.WEB_ENDPOINT) ApplyTimestampAndDuration(zipkin.internal.ApplyTimestampAndDuration) Before(org.junit.Before) TRACE(zipkin.TestObjects.TRACE) IOException(java.io.IOException) Test(org.junit.Test) BinaryAnnotation(zipkin.BinaryAnnotation) CLIENT_RECV(zipkin.Constants.CLIENT_RECV) DependencyLink(zipkin.DependencyLink) TODAY(zipkin.TestObjects.TODAY) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LOCAL_COMPONENT(zipkin.Constants.LOCAL_COMPONENT) APP_ENDPOINT(zipkin.TestObjects.APP_ENDPOINT) Constants(zipkin.Constants) SERVER_ADDR(zipkin.Constants.SERVER_ADDR) CallbackCaptor(zipkin.internal.CallbackCaptor) SERVER_RECV(zipkin.Constants.SERVER_RECV) DB_ENDPOINT(zipkin.TestObjects.DB_ENDPOINT) Endpoint(zipkin.Endpoint) ArrayList(java.util.ArrayList) DependencyLink(zipkin.DependencyLink) Span(zipkin.Span) Endpoint(zipkin.Endpoint) Test(org.junit.Test)

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