Search in sources :

Example 1 with DependencyLink

use of zipkin2.DependencyLink in project zipkin by openzipkin.

the class InternalForTests method writeDependencyLinks.

static void writeDependencyLinks(CassandraStorage storage, List<DependencyLink> links, long midnightUTC) {
    CqlSession session = storage.session();
    PreparedStatement prepared = session.prepare("INSERT INTO " + Schema.TABLE_DEPENDENCY + " (day,parent,child,calls,errors)" + " VALUES (?,?,?,?,?)");
    LocalDate day = Instant.ofEpochMilli(midnightUTC).atZone(ZoneOffset.UTC).toLocalDate();
    for (DependencyLink link : links) {
        int i = 0;
        storage.session().execute(prepared.bind().setLocalDate(i++, day).setString(i++, link.parent()).setString(i++, link.child()).setLong(i++, link.callCount()).setLong(i, link.errorCount()));
    }
}
Also used : PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) DependencyLink(zipkin2.DependencyLink) CqlSession(com.datastax.oss.driver.api.core.CqlSession) LocalDate(java.time.LocalDate)

Example 2 with DependencyLink

use of zipkin2.DependencyLink in project zipkin by openzipkin.

the class InternalForTests method writeDependencyLinks.

public static void writeDependencyLinks(ElasticsearchStorage es, List<DependencyLink> links, long midnightUTC) {
    String index = ((ElasticsearchSpanConsumer) es.spanConsumer()).formatTypeAndTimestampForInsert("dependency", midnightUTC);
    BulkCallBuilder indexer = new BulkCallBuilder(es, es.version(), "indexlinks");
    for (DependencyLink link : links) indexer.index(index, "dependency", link, DEPENDENCY_LINK_WRITER);
    try {
        indexer.build().execute();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : BulkCallBuilder(zipkin2.elasticsearch.internal.BulkCallBuilder) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) DependencyLink(zipkin2.DependencyLink)

Example 3 with DependencyLink

use of zipkin2.DependencyLink in project zipkin by openzipkin.

the class KryoTest method kryoJavaSerialization_dependencyLink.

@Test
public void kryoJavaSerialization_dependencyLink() {
    Kryo kryo = new Kryo();
    kryo.register(DependencyLink.class, new JavaSerializer());
    DependencyLink link = DependencyLink.newBuilder().parent("client").child("server").callCount(2L).errorCount(23L).build();
    Output output = new Output(4096);
    kryo.writeObject(output, link);
    output.flush();
    byte[] serialized = output.getBuffer();
    assertThat(kryo.readObject(new Input(serialized), DependencyLink.class)).isEqualTo(link);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output) DependencyLink(zipkin2.DependencyLink) JavaSerializer(com.esotericsoftware.kryo.serializers.JavaSerializer) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 4 with DependencyLink

use of zipkin2.DependencyLink in project zipkin by openzipkin.

the class ITMySQLStorage method aggregateDependencies.

static void aggregateDependencies(MySQLStorage storage, List<zipkin2.Span> spans) throws SQLException {
    try (Connection conn = storage.datasource.getConnection()) {
        DSLContext context = storage.context.get(conn);
        // batch insert the rows at timestamp midnight
        List<Query> inserts = new ArrayList<>();
        aggregateLinks(spans).forEach((midnight, links) -> {
            LocalDate day = Instant.ofEpochMilli(midnight).atZone(ZoneId.of("UTC")).toLocalDate();
            for (DependencyLink link : links) {
                inserts.add(context.insertInto(ZIPKIN_DEPENDENCIES).set(ZIPKIN_DEPENDENCIES.DAY, day).set(ZIPKIN_DEPENDENCIES.PARENT, link.parent()).set(ZIPKIN_DEPENDENCIES.CHILD, link.child()).set(ZIPKIN_DEPENDENCIES.CALL_COUNT, link.callCount()).set(ZIPKIN_DEPENDENCIES.ERROR_COUNT, link.errorCount()).onDuplicateKeyIgnore());
            }
        });
        context.batch(inserts).execute();
    }
}
Also used : Query(org.jooq.Query) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext) DependencyLink(zipkin2.DependencyLink) LocalDate(java.time.LocalDate)

Example 5 with DependencyLink

use of zipkin2.DependencyLink in project zipkin by openzipkin.

the class ITDependenciesHeavy method manyLinks.

/**
 * Ensure there's no query limit problem around links
 */
@Test
protected void manyLinks() throws Exception {
    // 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++) {
        String traceId = newTraceId();
        Endpoint web = FRONTEND.toBuilder().serviceName("web-" + i).build();
        Endpoint app = BACKEND.toBuilder().serviceName("app-" + i).build();
        Endpoint db = DB.toBuilder().serviceName("db-" + i).build();
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").timestamp((TODAY + 50L) * 1000L).duration(250L * 1000L).kind(Kind.CLIENT).localEndpoint(web).build());
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").shared(true).timestamp((TODAY + 100) * 1000L).duration(150 * 1000L).kind(Kind.SERVER).localEndpoint(app).build());
        spans.add(Span.newBuilder().traceId(traceId).parentId("10").id("11").name("get").timestamp((TODAY + 150L) * 1000L).duration(50L * 1000L).kind(Kind.CLIENT).localEndpoint(app).remoteEndpoint(db).build());
    }
    processDependencies(spans);
    List<DependencyLink> links = store().getDependencies(endTs(spans), DAY).execute();
    // web-? -> app-?, app-? -> db-?
    assertThat(links).hasSize(count * 2);
    assertThat(links).extracting(DependencyLink::callCount).allSatisfy(callCount -> assertThat(callCount).isEqualTo(1));
}
Also used : Endpoint(zipkin2.Endpoint) ArrayList(java.util.ArrayList) DependencyLink(zipkin2.DependencyLink) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint) Test(org.junit.jupiter.api.Test)

Aggregations

DependencyLink (zipkin2.DependencyLink)9 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Span (zipkin2.Span)3 LocalDate (java.time.LocalDate)2 LinkedHashMap (java.util.LinkedHashMap)2 DependencyLinker (zipkin2.internal.DependencyLinker)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 Output (com.esotericsoftware.kryo.io.Output)1 JavaSerializer (com.esotericsoftware.kryo.serializers.JavaSerializer)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 Connection (java.sql.Connection)1 Arrays.asList (java.util.Arrays.asList)1 Iterator (java.util.Iterator)1 List (java.util.List)1