Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for timeout exception #76

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public void onError(Throwable t) {
return;
}

logger.log(Level.WARNING, t, "Encountered gRPC exception");
if (!isConnectionTimeoutException(t)) {
logger.log(Level.WARNING, t, "Encountered gRPC exception");
}

metricAggregator.incrementCounter("Supportability/InfiniteTracing/Response/Error");

Status status = null;
Expand All @@ -70,6 +73,14 @@ private boolean isChannelClosing(Throwable t) {
return t instanceof StatusRuntimeException && t.getCause() instanceof ChannelClosingException;
}

/**
* Detects if the error received was a connection timeout exception. This can happen if the agent hasn't sent any spans for more than 15 seconds.
*/
private boolean isConnectionTimeoutException(Throwable t) {
return t instanceof StatusRuntimeException
&& t.getMessage().startsWith("INTERNAL: No error: A GRPC status of OK should have been sent");
}

/**
* Attempts to detect if the error received indicates that ALPN support is not provided by this JVM.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;

class ResponseObserverTest {

AtomicBoolean shouldRecreateCall = new AtomicBoolean();

@Test
public void shouldIncrementCounterOnNext() {
MetricAggregator metricAggregator = mock(MetricAggregator.class);
Expand Down Expand Up @@ -115,5 +120,56 @@ public void shouldTerminateOnALPNError() {
verify(disconnectionHandler).terminate();
}

AtomicBoolean shouldRecreateCall = new AtomicBoolean();
@Test
public void testIsConnectionTimeoutException() {
DisconnectionHandler disconnectionHandler = mock(DisconnectionHandler.class);
MetricAggregator metricAggregator = mock(MetricAggregator.class);
Logger logger = mock(Logger.class);

ResponseObserver target = new ResponseObserver(
metricAggregator,
logger,
disconnectionHandler, shouldRecreateCall);

Throwable exception = new StatusRuntimeException(
Status.fromCode(Status.Code.INTERNAL).withDescription("No error: A GRPC status of OK should have been sent\nRst Stream"));
target.onError(exception);

verify(logger, never()).log(Level.WARNING, exception, "Encountered gRPC exception");
}

@Test
public void testConnectionTimeoutExceptionWrongType() {
DisconnectionHandler disconnectionHandler = mock(DisconnectionHandler.class);
MetricAggregator metricAggregator = mock(MetricAggregator.class);
Logger logger = mock(Logger.class);

ResponseObserver target = new ResponseObserver(
metricAggregator,
logger,
disconnectionHandler, shouldRecreateCall);

Throwable exception = new RuntimeException("No error: A GRPC status of OK should have been sent\nRst Stream");
target.onError(exception);

verify(logger).log(Level.WARNING, exception, "Encountered gRPC exception");
}

@Test
public void testConnectionTimeoutExceptionWrongMessage() {
DisconnectionHandler disconnectionHandler = mock(DisconnectionHandler.class);
MetricAggregator metricAggregator = mock(MetricAggregator.class);
Logger logger = mock(Logger.class);

ResponseObserver target = new ResponseObserver(
metricAggregator,
logger,
disconnectionHandler, shouldRecreateCall);

Throwable exception = new StatusRuntimeException(Status.fromCode(Status.Code.INTERNAL).withDescription("A REALLY BAD ERROR: PRINT ME"));
target.onError(exception);

verify(logger).log(Level.WARNING, exception, "Encountered gRPC exception");
}

}