use of zipkin.storage.QueryRequest in project zipkin by openzipkin.
the class CassandraSpanStoreTest method searchingByAnnotationShouldFilterBeforeLimiting.
@Test
public void searchingByAnnotationShouldFilterBeforeLimiting() {
long now = System.currentTimeMillis();
int queryLimit = 2;
Endpoint endpoint = TestObjects.LOTS_OF_SPANS[0].annotations.get(0).endpoint;
BinaryAnnotation ba = BinaryAnnotation.create("host.name", "host1", endpoint);
int nbTraceFetched = queryLimit * storage.indexFetchMultiplier;
IntStream.range(0, nbTraceFetched).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).build()));
// Add two traces with the binary annotation we're looking for
IntStream.range(nbTraceFetched, nbTraceFetched + 2).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).addBinaryAnnotation(ba).build()));
QueryRequest queryRequest = QueryRequest.builder().addBinaryAnnotation(ba.key, new String(ba.value, Util.UTF_8)).serviceName(endpoint.serviceName).limit(queryLimit).build();
assertThat(store().getTraces(queryRequest)).hasSize(queryLimit);
}
use of zipkin.storage.QueryRequest in project zipkin by openzipkin.
the class ZipkinDispatcher method dispatch.
@Override
public MockResponse dispatch(RecordedRequest request) {
HttpUrl url = server.url(request.getPath());
if (request.getMethod().equals("GET")) {
if (url.encodedPath().equals("/health")) {
return new MockResponse().setBody("OK\n");
} else if (url.encodedPath().equals("/api/v1/services")) {
return jsonResponse(Codec.JSON.writeStrings(store.getServiceNames()));
} else if (url.encodedPath().equals("/api/v1/spans")) {
String serviceName = url.queryParameter("serviceName");
return jsonResponse(Codec.JSON.writeStrings(store.getSpanNames(serviceName)));
} else if (url.encodedPath().equals("/api/v1/dependencies")) {
Long endTs = maybeLong(url.queryParameter("endTs"));
Long lookback = maybeLong(url.queryParameter("lookback"));
List<DependencyLink> result = store.getDependencies(endTs, lookback);
return jsonResponse(Codec.JSON.writeDependencyLinks(result));
} else if (url.encodedPath().equals("/api/v1/traces")) {
QueryRequest queryRequest = toQueryRequest(url);
return jsonResponse(Codec.JSON.writeTraces(store.getTraces(queryRequest)));
} else if (url.encodedPath().startsWith("/api/v1/trace/")) {
String traceIdHex = url.encodedPath().replace("/api/v1/trace/", "");
long traceIdHigh = traceIdHex.length() == 32 ? lowerHexToUnsignedLong(traceIdHex, 0) : 0L;
long traceIdLow = lowerHexToUnsignedLong(traceIdHex);
List<Span> trace = url.queryParameterNames().contains("raw") ? store.getRawTrace(traceIdHigh, traceIdLow) : store.getTrace(traceIdHigh, traceIdLow);
if (trace != null)
return jsonResponse(Codec.JSON.writeSpans(trace));
}
} else if (request.getMethod().equals("POST")) {
if (url.encodedPath().equals("/api/v1/spans")) {
metrics.incrementMessages();
byte[] body = request.getBody().readByteArray();
String encoding = request.getHeader("Content-Encoding");
if (encoding != null && encoding.contains("gzip")) {
try {
Buffer result = new Buffer();
GzipSource source = new GzipSource(new Buffer().write(body));
while (source.read(result, Integer.MAX_VALUE) != -1) ;
body = result.readByteArray();
} catch (IOException e) {
metrics.incrementMessagesDropped();
return new MockResponse().setResponseCode(400).setBody("Cannot gunzip spans");
}
}
String type = request.getHeader("Content-Type");
Codec codec = type != null && type.contains("/x-thrift") ? Codec.THRIFT : Codec.JSON;
final MockResponse result = new MockResponse();
consumer.acceptSpans(body, codec, new Callback<Void>() {
@Override
public void onSuccess(Void value) {
result.setResponseCode(202);
}
@Override
public void onError(Throwable t) {
String message = t.getMessage();
result.setBody(message).setResponseCode(message.startsWith("Cannot store") ? 500 : 400);
}
});
return result;
}
} else {
// unsupported method
return new MockResponse().setResponseCode(405);
}
return new MockResponse().setResponseCode(404);
}
use of zipkin.storage.QueryRequest in project zipkin by openzipkin.
the class HttpSpanStore method getTraces.
@Override
public List<List<Span>> getTraces(QueryRequest request) {
HttpUrl.Builder url = baseUrl.newBuilder("/api/v1/traces");
maybeAddQueryParam(url, "serviceName", request.serviceName);
maybeAddQueryParam(url, "spanName", request.spanName);
maybeAddQueryParam(url, "annotationQuery", request.toAnnotationQuery());
maybeAddQueryParam(url, "minDuration", request.minDuration);
maybeAddQueryParam(url, "maxDuration", request.maxDuration);
maybeAddQueryParam(url, "endTs", request.endTs);
maybeAddQueryParam(url, "lookback", request.lookback);
maybeAddQueryParam(url, "limit", request.limit);
Response response = call(new Request.Builder().url(url.build()).build());
return Codec.JSON.readTraces(responseBytes(response));
}
use of zipkin.storage.QueryRequest in project zipkin by openzipkin.
the class ZipkinDispatcherTest method toQueryRequest_parseBinaryAnnotations_withSlash.
@Test
public void toQueryRequest_parseBinaryAnnotations_withSlash() {
HttpUrl url = baseUrl.newBuilder().addQueryParameter("serviceName", "myService").addQueryParameter("annotationQuery", "http.path=/sessions").build();
QueryRequest request = ZipkinDispatcher.toQueryRequest(url);
assertThat(request.binaryAnnotations).hasSize(1).containsEntry(TraceKeys.HTTP_PATH, "/sessions");
}
use of zipkin.storage.QueryRequest in project zipkin by openzipkin.
the class ZipkinDispatcherTest method toQueryRequest_parseBinaryAnnotations.
@Test
public void toQueryRequest_parseBinaryAnnotations() {
HttpUrl url = baseUrl.newBuilder().addQueryParameter("serviceName", "myService").addQueryParameter("annotationQuery", "http.status_code=500").build();
QueryRequest request = ZipkinDispatcher.toQueryRequest(url);
assertThat(request.binaryAnnotations).hasSize(1).containsEntry(TraceKeys.HTTP_STATUS_CODE, "500");
}
Aggregations