/** * {@link CollectorSampler#isSampled(Span) samples spans} to reduce load on the storage system. * Defaults to always sample. */ public Builder sampler(CollectorSampler sampler) { this.sampler = checkNotNull(sampler, "sampler"); return this; }
@Override public String toString() { return "(" + table + "," + partitionKey + "," + Util.toLowerHex(traceId) + ")"; }
if (equal(saService, caService)) caService = null; .traceId(toLowerHex(traceIdHi != null ? traceIdHi : 0L, traceIdLo)) .parentId(parentId != null ? toLowerHex(parentId) : null) .id(toLowerHex(spanId));
static List<String> annotationKeys(QueryRequest request) { if (request.annotations.isEmpty() && request.binaryAnnotations.isEmpty()) { return Collections.emptyList(); } checkArgument(request.serviceName != null, "serviceName needed with annotation query"); Set<String> annotationKeys = new LinkedHashSet<>(); for (String a : request.annotations) { // doesn't include CORE_ANNOTATIONS annotationKeys.add(request.serviceName + ":" + a); } for (Map.Entry<String, String> b : request.binaryAnnotations.entrySet()) { annotationKeys.add(request.serviceName + ":" + b.getKey() + ":" + b.getValue()); } return sortedList(annotationKeys); }
static GregorianCalendar midnightUTC(long epochMillis) { GregorianCalendar result = new GregorianCalendar(UTC); result.setTimeInMillis(Util.midnightUTC(epochMillis)); return result; }
@Override public ListenableFuture<List<DependencyLink>> getDependencies(long endTs, @Nullable Long lookback) { List<Date> days = getDays(endTs, lookback); try { BoundStatement bound = CassandraUtil.bindWithName(selectDependencies, "select-dependencies") .setList("days", days); return transform(session.executeAsync(bound), ConvertDependenciesResponse.INSTANCE); } catch (RuntimeException ex) { return immediateFailedFuture(ex); } }
/** Note: this runs on the {@link okhttp3.OkHttpClient#dispatcher() dispatcher} thread! */ @Override public void onResponse(okhttp3.Call call, Response response) { try { delegate.onSuccess(parseResponse(response, bodyConverter)); } catch (Throwable e) { propagateIfFatal(e); delegate.onError(e); } } }
@Override public List<String> apply(SearchResponse input) { Iterator<Aggregation> aggregations = input.getAggregations() != null ? input.getAggregations().iterator() : null; if (aggregations == null) { return ImmutableList.of(); } ImmutableSet.Builder<String> result = ImmutableSet.builder(); while (aggregations.hasNext()) { addBucketKeys(aggregations.next(), result); } return Util.sortedList(result.build()); }
@VisibleForTesting void write(List<DependencyLink> links, long timestampMillis) { long midnight = Util.midnightUTC(timestampMillis); Dependencies deps = Dependencies.create(midnight, midnight /* ignored */, links); ByteBuffer thrift = deps.toThrift(); Futures.getUnchecked(storeDependencies(midnight, thrift)); }
@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) .select(schema.dependencyLinkFields) .from(ZIPKIN_DEPENDENCIES) .where(ZIPKIN_DEPENDENCIES.DAY.in(days)) .fetch((Record l) -> DependencyLink.builder() .parent(l.get(ZIPKIN_DEPENDENCIES.PARENT)) .child(l.get(ZIPKIN_DEPENDENCIES.CHILD)) .callCount(l.get(ZIPKIN_DEPENDENCIES.CALL_COUNT)) .errorCount(maybeGet(l, ZIPKIN_DEPENDENCIES.ERROR_COUNT, 0L)) .build() ); 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()); } }
@Override public void accept(List<Span> spans, Callback<Void> callback) { if (spans.isEmpty()) { callback.onSuccess(null); return; } try { indexSpans(client.bulkSpanIndexer(), spans).execute(callback); } catch (Throwable t) { propagateIfFatal(t); callback.onError(t); } }
/** The zookeeper connect string, ex. 127.0.0.1:2181. No default */ public Builder zookeeper(String zookeeper) { this.zookeeper = checkNotNull(zookeeper, "zookeeper"); return this; }
@Override public ListenableFuture<List<Span>> getRawTrace(long traceIdHigh, long traceIdLow) { String traceIdHex = Util.toLowerHex(strictTraceId ? traceIdHigh : 0L, traceIdLow); return client.findSpans(catchAll, termQuery("traceId", traceIdHex)); }
/** * The index prefix to use when generating daily index names. Defaults to zipkin. */ public Builder index(String index) { this.index = checkNotNull(index, "index"); return this; }
@Override public void getRawTrace(long traceIdHigh, long traceIdLow, Callback<List<Span>> callback) { String traceIdHex = Util.toLowerHex(strictTraceId ? traceIdHigh : 0L, traceIdLow); SearchRequest request = SearchRequest.create(asList(allIndices), SPAN) .term("traceId", traceIdHex); submit(search.newCall(request, NULLABLE_SPANS), callback); }
/** Keyspace to store span and index data. Defaults to "zipkin" */ public Builder keyspace(String keyspace) { this.keyspace = checkNotNull(keyspace, "keyspace"); return this; }
static void streamSpansToStorage( JavaDStream<byte[]> stream, ReadSpans readSpans, AdjustAndConsumeSpansSharingTraceId adjustAndConsumeSpansSharingTraceId ) { JavaDStream<Span> spans = stream.flatMap(readSpans); // TODO: plug in some filter to drop spans regardless of trace ID // spans = spans.filter(spanFilter); JavaPairDStream<String, Iterable<Span>> tracesById = spans .mapToPair(s -> new Tuple2<>(Util.toLowerHex(s.traceIdHigh, s.traceId), s)) .groupByKey(); tracesById.foreachRDD(rdd -> { rdd.values().foreachPartition(adjustAndConsumeSpansSharingTraceId); }); }
/** Comma separated list of host addresses part of Cassandra cluster. You can also specify a custom port with 'host:port'. Defaults to localhost on port 9042 **/ public Builder contactPoints(String contactPoints) { this.contactPoints = checkNotNull(contactPoints, "contactPoints"); return this; }
/** Category zipkin spans will be consumed from. Defaults to "zipkin" */ public Builder category(String category) { this.category = checkNotNull(category, "category"); return this; }
/** * {@link CollectorSampler#isSampled(Span) samples spans} to reduce load on the storage system. * Defaults to always sample. */ public Builder sampler(CollectorSampler sampler) { this.sampler = checkNotNull(sampler, "sampler"); return this; }