use of zipkin2.elasticsearch.internal.client.HttpCall in project zipkin by openzipkin.
the class ElasticsearchSpanStore method getTraces.
@Override
public Call<List<List<Span>>> getTraces(QueryRequest request) {
if (!searchEnabled)
return Call.emptyList();
long endMillis = request.endTs();
long beginMillis = Math.max(endMillis - request.lookback(), EARLIEST_MS);
SearchRequest.Filters filters = new SearchRequest.Filters();
filters.addRange("timestamp_millis", beginMillis, endMillis);
if (request.serviceName() != null) {
filters.addTerm("localEndpoint.serviceName", request.serviceName());
}
if (request.remoteServiceName() != null) {
filters.addTerm("remoteEndpoint.serviceName", request.remoteServiceName());
}
if (request.spanName() != null) {
filters.addTerm("name", request.spanName());
}
for (Map.Entry<String, String> kv : request.annotationQuery().entrySet()) {
if (kv.getValue().isEmpty()) {
filters.addTerm("_q", kv.getKey());
} else {
filters.addTerm("_q", kv.getKey() + "=" + kv.getValue());
}
}
if (request.minDuration() != null) {
filters.addRange("duration", request.minDuration(), request.maxDuration());
}
// We need to filter to traces that contain at least one span that matches the request,
// but the zipkin API is supposed to order traces by first span, regardless of if it was
// filtered or not. This is not possible without either multiple, heavyweight queries
// or complex multiple indexing, defeating much of the elegance of using elasticsearch for this.
// So we fudge and order on the first span among the filtered spans - in practice, there should
// be no significant difference in user experience since span start times are usually very
// close to each other in human time.
Aggregation traceIdTimestamp = Aggregation.terms("traceId", request.limit()).addSubAggregation(Aggregation.min("timestamp_millis")).orderBy("timestamp_millis", "desc");
List<String> indices = indexNameFormatter.formatTypeAndRange(TYPE_SPAN, beginMillis, endMillis);
if (indices.isEmpty())
return Call.emptyList();
SearchRequest esRequest = SearchRequest.create(indices).filters(filters).addAggregation(traceIdTimestamp);
HttpCall<List<String>> traceIdsCall = search.newCall(esRequest, BodyConverters.KEYS);
Call<List<List<Span>>> result = traceIdsCall.flatMap(new GetSpansByTraceId(search, indices)).map(groupByTraceId);
// clash on lower-64 bit. When strict trace ID is enabled, we only filter client-side on clash.
return strictTraceId ? result.map(StrictTraceId.filterTraces(request)) : result;
}
use of zipkin2.elasticsearch.internal.client.HttpCall in project zipkin by openzipkin.
the class BulkCallBuilder method build.
/**
* Creates a bulk request when there is more than one object to store
*/
public HttpCall<Void> build() {
QueryStringEncoder urlBuilder = new QueryStringEncoder("/_bulk");
if (pipeline != null)
urlBuilder.addParam("pipeline", pipeline);
if (waitForRefresh)
urlBuilder.addParam("refresh", "wait_for");
ByteBufAllocator alloc = RequestContext.mapCurrent(RequestContext::alloc, () -> PooledByteBufAllocator.DEFAULT);
HttpCall.RequestSupplier request = new BulkRequestSupplier(entries, shouldAddType, RequestHeaders.of(HttpMethod.POST, urlBuilder.toString(), HttpHeaderNames.CONTENT_TYPE, MediaType.JSON_UTF_8), alloc);
return http.newCall(request, CHECK_FOR_ERRORS, tag);
}
Aggregations