use of zipkin2.Callback in project zipkin by openzipkin.
the class ITActiveMQCollector method skipsOnSpanStorageException.
/**
* Guards against errors that leak from storage, such as InvalidQueryException
*/
@Test
public void skipsOnSpanStorageException() throws Exception {
collector.close();
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();
}
};
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
// tossed on error
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
collector = builder().storage(buildStorage(consumer)).build().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(activemqMetrics.messages()).isEqualTo(3);
// storage failure not message failure
assertThat(activemqMetrics.messagesDropped()).isZero();
assertThat(activemqMetrics.bytes()).isEqualTo(PROTO3.encodeList(spans).length * 3);
assertThat(activemqMetrics.spans()).isEqualTo(spans.size() * 3);
// only one dropped
assertThat(activemqMetrics.spansDropped()).isEqualTo(spans.size());
}
use of zipkin2.Callback 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.Callback in project zipkin by openzipkin.
the class ScribeSpanConsumer method Log.
@Override
public void Log(List<LogEntry> messages, AsyncMethodCallback<ResultCode> resultHandler) {
metrics.incrementMessages();
List<Span> spans = new ArrayList<>();
int byteCount = 0;
try {
for (LogEntry logEntry : messages) {
if (!category.equals(logEntry.category))
continue;
byte[] bytes = logEntry.message.getBytes(StandardCharsets.ISO_8859_1);
// finagle-zipkin uses mime encoding
bytes = Base64.getMimeDecoder().decode(bytes);
byteCount += bytes.length;
spans.add(SpanBytesDecoder.THRIFT.decodeOne(bytes));
}
} catch (RuntimeException e) {
metrics.incrementMessagesDropped();
resultHandler.onError(e);
return;
} finally {
metrics.incrementBytes(byteCount);
}
collector.accept(spans, new Callback<Void>() {
@Override
public void onSuccess(Void value) {
resultHandler.onComplete(ResultCode.OK);
}
@Override
public void onError(Throwable t) {
Exception error = t instanceof Exception ? (Exception) t : new RuntimeException(t);
resultHandler.onError(error);
}
}, CommonPools.blockingTaskExecutor());
}
use of zipkin2.Callback in project zipkin by openzipkin.
the class ITSpanStore method consumer_implementsCall_submit.
@Test
protected void consumer_implementsCall_submit(TestInfo testInfo) throws Exception {
String testSuffix = testSuffix(testInfo);
Span span = spanBuilder(testSuffix).build();
Call<Void> call = storage.spanConsumer().accept(asList(span));
// Ensure the implementation didn't accidentally do I/O at assembly time.
assertGetTraceReturnsEmpty(span.traceId());
CountDownLatch latch = new CountDownLatch(1);
Callback<Void> callback = new Callback<Void>() {
@Override
public void onSuccess(Void value) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
latch.countDown();
}
};
call.enqueue(callback);
latch.await();
blockWhileInFlight();
assertGetTraceReturns(span);
assertThatThrownBy(() -> call.enqueue(callback)).isInstanceOf(IllegalStateException.class);
// no problem to clone a call
call.clone().execute();
}
use of zipkin2.Callback in project OkHttp3 by MrZhousf.
the class HttpHelper method doRequestAsync.
/**
* 异步请求
*/
void doRequestAsync(final OkHttpHelper helper) {
if (httpInfo == null)
return;
final HttpInfo info = httpInfo;
final BaseCallback callback = helper.getCallback();
Request request = helper.getRequest();
String url = info.getUrl();
if (!checkUrl(url)) {
// 主线程回调
Message msg = new CallbackMessage(OkMainHandler.RESPONSE_CALLBACK, callback, retInfo(info, HttpInfo.CheckURL), requestTag, null).build();
OkMainHandler.getInstance().sendMessage(msg);
return;
}
request = request == null ? buildRequest(info, helper.getRequestType(), helper.getProgressCallback()) : request;
showUrlLog(request);
Call call = httpClient.newCall(request);
BaseActivityLifecycleCallbacks.putCall(requestTag, call);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// 主线程回调
int code = HttpInfo.CheckNet;
if (e instanceof UnknownHostException) {
if (!helperInfo.getOkHttpUtil().isNetworkAvailable()) {
code = HttpInfo.CheckNet;
} else {
code = HttpInfo.CheckURL;
}
} else if (e instanceof SocketTimeoutException) {
code = HttpInfo.ConnectionTimeOut;
if (null != e.getMessage()) {
if (e.getMessage().contains("failed to connect to"))
code = HttpInfo.ConnectionTimeOut;
if (e.getMessage().equals("timeout"))
code = HttpInfo.WriteAndReadTimeOut;
}
}
Message msg = new CallbackMessage(OkMainHandler.RESPONSE_CALLBACK, callback, retInfo(info, code, "[" + e.getMessage() + "]"), requestTag, call).build();
OkMainHandler.getInstance().sendMessage(msg);
}
@Override
public void onResponse(Call call, Response res) throws IOException {
// 主线程回调
Message msg = new CallbackMessage(OkMainHandler.RESPONSE_CALLBACK, callback, dealResponse(helper, res), requestTag, call).build();
OkMainHandler.getInstance().sendMessage(msg);
}
});
}
Aggregations