use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.
the class ITRabbitMQCollector method skipsOnSpanStorageException.
/**
* Guards against errors that leak from storage, such as InvalidQueryException
*/
@Test
void skipsOnSpanStorageException() throws Exception {
AtomicInteger counter = new AtomicInteger();
consumer = (input) -> new Call.Base<Void>() {
@Override
protected Void doExecute() {
throw new AssertionError();
}
@Override
protected void doEnqueue(Callback<Void> callback) {
if (counter.getAndIncrement() == 1) {
callback.onError(new RuntimeException("storage fell over"));
} else {
receivedSpans.add(spans);
callback.onSuccess(null);
}
}
@Override
public Call<Void> clone() {
throw new AssertionError();
}
};
final StorageComponent storage = buildStorage(consumer);
RabbitMQCollector.Builder builder = builder("storage_exception").storage(storage);
produceSpans(THRIFT.encodeList(spans), builder.queue);
// tossed on error
produceSpans(THRIFT.encodeList(spans), builder.queue);
produceSpans(THRIFT.encodeList(spans), builder.queue);
try (RabbitMQCollector collector = builder.build()) {
collector.start();
assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
// the only way we could read this, is if the malformed span was skipped.
assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
}
assertThat(rabbitmqMetrics.messages()).isEqualTo(3);
// storage failure isn't a message failure
assertThat(rabbitmqMetrics.messagesDropped()).isZero();
assertThat(rabbitmqMetrics.bytes()).isEqualTo(THRIFT.encodeList(spans).length * 3);
assertThat(rabbitmqMetrics.spans()).isEqualTo(spans.size() * 3);
// only one dropped
assertThat(rabbitmqMetrics.spansDropped()).isEqualTo(spans.size());
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.
the class SelectSpansAndAnnotationsTest method processAnnotationRecord_address_skipWrongKey.
@Test
public void processAnnotationRecord_address_skipWrongKey() {
Record4<Integer, Long, String, byte[]> annotationRecord = annotationRecord(0, null, "sr", new byte[] { 1 });
Endpoint ep = Endpoint.newBuilder().serviceName("foo").build();
V1Span.Builder builder = V1Span.newBuilder().traceId(1).id(1);
SelectSpansAndAnnotations.processAnnotationRecord(annotationRecord, builder, ep);
assertThat(builder.build().binaryAnnotations()).isEmpty();
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.
the class SelectSpansAndAnnotationsTest method processAnnotationRecord_address.
@Test
public void processAnnotationRecord_address() {
Record4<Integer, Long, String, byte[]> annotationRecord = annotationRecord(0, null, "ca", new byte[] { 1 });
Endpoint ep = Endpoint.newBuilder().serviceName("foo").build();
V1Span.Builder builder = V1Span.newBuilder().traceId(1).id(1);
SelectSpansAndAnnotations.processAnnotationRecord(annotationRecord, builder, ep);
assertThat(builder.build().binaryAnnotations().get(0)).isEqualTo(V1BinaryAnnotation.createAddress("ca", ep));
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.
the class TracingStatementInterceptor method parseServerAddress.
/**
* MySQL exposes the host connecting to, but not the port. This attempts to get the port from the
* JDBC URL. Ex. 5555 from {@code jdbc:mysql://localhost:5555/database}, or 3306 if absent.
*/
static void parseServerAddress(MysqlConnection connection, Span span) {
try {
// strip "jdbc:"
URI url = URI.create(connection.getURL().substring(5));
int port = url.getPort() == -1 ? 3306 : url.getPort();
String remoteServiceName = connection.getProperties().getProperty("zipkinServiceName");
if (remoteServiceName == null || "".equals(remoteServiceName)) {
String databaseName = getDatabaseName(connection);
if (databaseName != null && !databaseName.isEmpty()) {
remoteServiceName = "mysql-" + databaseName;
} else {
remoteServiceName = "mysql";
}
}
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(remoteServiceName).port(port);
if (!builder.parseIp(getHost(connection)))
return;
span.remoteEndpoint(builder.build());
} catch (Exception e) {
// remote address is optional
}
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.
the class TracingInterceptor method parseServerAddress.
/**
* This is different than default because the request does not hold the address
*/
void parseServerAddress(Connection connection, Span span) {
if (span.isNoop())
return;
InetSocketAddress remoteAddress = connection.route().socketAddress();
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(remoteServiceName);
builder.parseIp(remoteAddress.getAddress());
builder.port(remoteAddress.getPort());
span.remoteEndpoint(builder.build());
}
Aggregations