Not throwing an exception when queue size is exceeded

without this change when queue size of spans is exceeded for Stream span propagation, an exception is thrown that terminates business logic processing
with this change we're not propagating the exception - we're incrementing the dropped spans counter

fixes #421
This commit is contained in:
Marcin Grzejszczak
2016-10-11 15:15:11 +02:00
parent d092d62397
commit b8db95bc78
2 changed files with 60 additions and 1 deletions

View File

@@ -83,7 +83,14 @@ public class StreamSpanReporter implements SpanReporter {
@Override
public void report(Span span) {
if (span.isExportable()) {
this.queue.add(span);
try {
this.queue.add(span);
} catch (Exception e) {
this.spanMetricReporter.incrementDroppedSpans(1);
if (log.isDebugEnabled()) {
log.debug("The span " + span + " will not be sent to Zipkin due to [" + e + "]");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("The span " + span + " will not be sent to Zipkin due to sampling");

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.sleuth.stream;
import java.util.concurrent.ArrayBlockingQueue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.metric.SpanMetricReporter;
import static org.mockito.BDDMockito.then;
/**
* @author Marcin Grzejszczak
*/
@RunWith(MockitoJUnitRunner.class)
public class StreamSpanReporterTests {
@Mock HostLocator endpointLocator;
@Mock SpanMetricReporter spanMetricReporter;
@InjectMocks StreamSpanReporter reporter;
@Test
public void should_not_throw_an_exception_when_queue_size_is_exceeded() throws Exception {
ArrayBlockingQueue<Span> queue = new ArrayBlockingQueue<>(1);
queue.add(Span.builder().name("foo").build());
this.reporter.setQueue(queue);
this.reporter.report(Span.builder().name("bar").exportable(true).build());
then(spanMetricReporter).should().incrementDroppedSpans(1);
}
}