Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -143,6 +143,11 @@ public void attemptFailed(Throwable error, Duration delay) {
recordAttemptCompletion(error);
}

@Override
public void attemptPermanentFailure(Throwable throwable) {
recordAttemptCompletion(throwable);
}

@Override
public void onRequest(int requestCount) {
requestLeft.accumulateAndGet(requestCount, IntMath::saturatedAdd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.api.client.util.Lists;
import com.google.api.core.SettableApiFuture;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.NotFoundException;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.StreamController;
import com.google.api.gax.tracing.SpanName;
Expand Down Expand Up @@ -66,6 +67,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -85,6 +87,8 @@ public class BuiltinMetricsTracerTest {
private static final String INSTANCE_ID = "fake-instance";
private static final String APP_PROFILE_ID = "default";
private static final String TABLE_ID = "fake-table";

private static final String BAD_TABLE_ID = "non-exist-table";
private static final String ZONE = "us-west-1";
private static final String CLUSTER = "cluster-0";
private static final long FAKE_SERVER_TIMING = 50;
Expand Down Expand Up @@ -345,6 +349,35 @@ public void testMutateRowAttempts() {
assertThat(status.getAllValues()).containsExactly("UNAVAILABLE", "UNAVAILABLE", "OK");
}

@Test
public void testPermanentFailure() {
when(mockFactory.newTracer(any(), any(), any()))
.thenReturn(
new BuiltinMetricsTracer(
OperationType.ServerStreaming,
SpanName.of("Bigtable", "ReadRows"),
statsRecorderWrapper));

try {
Lists.newArrayList(stub.readRowsCallable().call(Query.create(BAD_TABLE_ID)).iterator());
Assert.fail("Request should throw not found error");
} catch (NotFoundException e) {
}

ArgumentCaptor<Long> attemptLatency = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Long> operationLatency = ArgumentCaptor.forClass(Long.class);

verify(statsRecorderWrapper, timeout(50)).putAttemptLatencies(attemptLatency.capture());
verify(statsRecorderWrapper, timeout(50)).putOperationLatencies(operationLatency.capture());
verify(statsRecorderWrapper, timeout(50))
.recordAttempt(status.capture(), tableId.capture(), zone.capture(), cluster.capture());

assertThat(status.getValue()).isEqualTo("NOT_FOUND");
assertThat(tableId.getValue()).isEqualTo(BAD_TABLE_ID);
assertThat(cluster.getValue()).isEqualTo("unspecified");
assertThat(zone.getValue()).isEqualTo("global");
}

private static class FakeService extends BigtableGrpc.BigtableImplBase {

static List<ReadRowsResponse> createFakeResponse() {
Expand Down Expand Up @@ -375,6 +408,10 @@ static List<ReadRowsResponse> createFakeResponse() {
@Override
public void readRows(
ReadRowsRequest request, StreamObserver<ReadRowsResponse> responseObserver) {
if (request.getTableName().contains(BAD_TABLE_ID)) {
responseObserver.onError(new StatusRuntimeException(Status.NOT_FOUND));
return;
}
final AtomicBoolean done = new AtomicBoolean();
final ServerCallStreamObserver<ReadRowsResponse> target =
(ServerCallStreamObserver<ReadRowsResponse>) responseObserver;
Expand Down