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;
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations