Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
chore: make ApiTracer internal API (#1408)
Browse files Browse the repository at this point in the history
* chore: make ApiTracer internal API

* remove annotation

* make constructor protected

* renmase NoopApiTracer to BaseApiTracer
  • Loading branch information
mutianf committed Jun 21, 2021
1 parent 4d4d2a1 commit 5224356
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 43 deletions.
Expand Up @@ -36,7 +36,7 @@
import com.google.api.gax.rpc.TransportChannel;
import com.google.api.gax.rpc.internal.Headers;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import com.google.auth.Credentials;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -479,7 +479,7 @@ public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams
public ApiTracer getTracer() {
ApiTracer tracer = callOptions.getOption(TRACER_KEY);
if (tracer == null) {
tracer = NoopApiTracer.getInstance();
tracer = BaseApiTracer.getInstance();
}
return tracer;
}
Expand Down
Expand Up @@ -36,7 +36,7 @@
import com.google.api.gax.rpc.TransportChannel;
import com.google.api.gax.rpc.internal.Headers;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import com.google.auth.Credentials;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -352,7 +352,7 @@ public HttpJsonCallContext withDeadline(Instant newDeadline) {
@Override
public ApiTracer getTracer() {
if (tracer == null) {
return NoopApiTracer.getInstance();
return BaseApiTracer.getInstance();
}
return tracer;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@

import com.google.api.gax.rpc.StatusCode.Code;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import java.util.Set;
import javax.annotation.Nonnull;

Expand All @@ -51,7 +51,7 @@ public static RetryingContext create() {
@Nonnull
@Override
public ApiTracer getTracer() {
return NoopApiTracer.getInstance();
return BaseApiTracer.getInstance();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions gax/src/main/java/com/google/api/gax/rpc/ClientContext.java
Expand Up @@ -38,7 +38,7 @@
import com.google.api.gax.rpc.internal.QuotaProjectIdHidingCredentials;
import com.google.api.gax.rpc.mtls.MtlsProvider;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.NoopApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.auth.Credentials;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -119,7 +119,7 @@ public static Builder newBuilder() {
.setClock(NanoClock.getDefaultClock())
.setStreamWatchdog(null)
.setStreamWatchdogCheckInterval(Duration.ZERO)
.setTracerFactory(NoopApiTracerFactory.getInstance())
.setTracerFactory(BaseApiTracerFactory.getInstance())
.setQuotaProjectId(null);
}

Expand Down
4 changes: 2 additions & 2 deletions gax/src/main/java/com/google/api/gax/rpc/StubSettings.java
Expand Up @@ -40,7 +40,7 @@
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.NoopApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.auth.oauth2.QuotaProjectIdProvider;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -257,7 +257,7 @@ protected Builder(ClientContext clientContext) {
this.quotaProjectId = null;
this.streamWatchdogProvider = InstantiatingWatchdogProvider.create();
this.streamWatchdogCheckInterval = Duration.ofSeconds(10);
this.tracerFactory = NoopApiTracerFactory.getInstance();
this.tracerFactory = BaseApiTracerFactory.getInstance();
} else {
this.executorProvider = FixedExecutorProvider.create(clientContext.getExecutor());
this.transportChannelProvider =
Expand Down
4 changes: 2 additions & 2 deletions gax/src/main/java/com/google/api/gax/tracing/ApiTracer.java
Expand Up @@ -39,9 +39,9 @@
* its lifecycle. Constructing an instance of a subclass will implicitly signal the start of a new
* operation.
*
* <p>For internal use only.
* <p>For internal use only. google-cloud-java libraries should extend {@link BaseApiTracer}.
*/
@InternalApi("For internal use by google-cloud-java clients only")
@InternalApi
public interface ApiTracer {

/**
Expand Down
Expand Up @@ -38,9 +38,9 @@
* <p>In general a single instance of an {@link ApiTracer} will correspond to a single logical
* operation.
*
* <p>For internal use only.
* <p>For internal use only. google-cloud-java libraries should extend {@link BaseApiTracerFactory}.
*/
@InternalApi("For internal use by google-cloud-java clients only")
@InternalApi
@InternalExtensionOnly
public interface ApiTracerFactory {
/** The type of operation the {@link ApiTracer} is tracing. */
Expand Down
Expand Up @@ -33,13 +33,13 @@
import org.threeten.bp.Duration;

/**
* An implementation of {@link ApiTracer} that does nothing.
* A base implementation of {@link ApiTracer} that does nothing.
*
* <p>For internal use only.
*/
@InternalApi
public final class NoopApiTracer implements ApiTracer {
private static final ApiTracer INSTANCE = new NoopApiTracer();
@InternalApi("For internal use by google-cloud-java clients only")
public class BaseApiTracer implements ApiTracer {
private static final ApiTracer INSTANCE = new BaseApiTracer();

private static final Scope NOOP_SCOPE =
new Scope() {
Expand All @@ -49,7 +49,7 @@ public void close() {
}
};

private NoopApiTracer() {}
protected BaseApiTracer() {}

public static ApiTracer getInstance() {
return INSTANCE;
Expand Down
Expand Up @@ -32,23 +32,23 @@
import com.google.api.core.InternalApi;

/**
* Factory that will build {@link ApiTracer}s that do nothing.
* Base factory that will build {@link ApiTracer}s that do nothing.
*
* <p>For internal use only.
*/
@InternalApi
public final class NoopApiTracerFactory implements ApiTracerFactory {
private static final NoopApiTracerFactory INSTANCE = new NoopApiTracerFactory();
@InternalApi("For internal use by google-cloud-java clients only")
public class BaseApiTracerFactory implements ApiTracerFactory {
private static final BaseApiTracerFactory INSTANCE = new BaseApiTracerFactory();

public static NoopApiTracerFactory getInstance() {
public static BaseApiTracerFactory getInstance() {
return INSTANCE;
}

private NoopApiTracerFactory() {}
protected BaseApiTracerFactory() {}

/** {@inheritDoc} */
@Override
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
return NoopApiTracer.getInstance();
return BaseApiTracer.getInstance();
}
}
Expand Up @@ -207,7 +207,7 @@
* com.google.api.gax.rpc.ApiStreamObserver} for more information.
*/
@BetaApi("Surface for tracing is not yet stable")
public class OpencensusTracer implements ApiTracer {
public class OpencensusTracer extends BaseApiTracer {
private final Tracer tracer;
private final Span span;
private final OperationType operationType;
Expand Down
Expand Up @@ -49,7 +49,7 @@
* <p>This class is thread safe.
*/
@InternalApi("For google-cloud-java client use only")
public final class OpencensusTracerFactory implements ApiTracerFactory {
public final class OpencensusTracerFactory extends BaseApiTracerFactory {
@Nonnull private final Tracer internalTracer;
@Nonnull private final Map<String, AttributeValue> spanAttributes;

Expand Down
Expand Up @@ -32,7 +32,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -43,7 +43,7 @@ public class NoopRetryingContextTest {
@Test
public void testGetTracer() {
RetryingContext context = NoopRetryingContext.create();
assertSame(NoopApiTracer.getInstance(), context.getTracer());
assertSame(BaseApiTracer.getInstance(), context.getTracer());
}

@Test
Expand Down
Expand Up @@ -41,7 +41,7 @@
import com.google.api.gax.rpc.testing.FakeCallContext;
import com.google.api.gax.rpc.testing.MockStreamingApi.MockServerStreamingCall;
import com.google.api.gax.rpc.testing.MockStreamingApi.MockServerStreamingCallable;
import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import com.google.common.collect.Queues;
import com.google.common.truth.Truth;
import java.util.concurrent.BlockingDeque;
Expand Down Expand Up @@ -90,7 +90,7 @@ private ServerStreamingAttemptCallable<String, String> createCallable(ApiCallCon
@Test
public void testUserProvidedContextTimeout() {
// Mock up the ApiCallContext as if the user provided a timeout and streamWaitTimeout.
Mockito.doReturn(NoopApiTracer.getInstance()).when(mockedCallContext).getTracer();
Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer();
Mockito.doReturn(Duration.ofHours(5)).when(mockedCallContext).getTimeout();
Mockito.doReturn(Duration.ofHours(5)).when(mockedCallContext).getStreamWaitTimeout();

Expand Down Expand Up @@ -125,7 +125,7 @@ public void testUserProvidedContextTimeout() {
@Test
public void testNoUserProvidedContextTimeout() {
// Mock up the ApiCallContext as if the user did not provide custom timeouts.
Mockito.doReturn(NoopApiTracer.getInstance()).when(mockedCallContext).getTracer();
Mockito.doReturn(BaseApiTracer.getInstance()).when(mockedCallContext).getTracer();
Mockito.doReturn(null).when(mockedCallContext).getTimeout();
Mockito.doReturn(null).when(mockedCallContext).getStreamWaitTimeout();
Mockito.doReturn(mockedCallContext).when(mockedCallContext).withTimeout(totalTimeout);
Expand Down
Expand Up @@ -37,7 +37,7 @@
import com.google.api.gax.rpc.TransportChannel;
import com.google.api.gax.rpc.internal.Headers;
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.NoopApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import com.google.auth.Credentials;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -346,7 +346,7 @@ public Map<String, List<String>> getExtraHeaders() {
@Nonnull
public ApiTracer getTracer() {
if (tracer == null) {
return NoopApiTracer.getInstance();
return BaseApiTracer.getInstance();
}
return tracer;
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ public void testSpanNamePassthrough() {
new OpencensusTracerFactory(internalTracer, ImmutableMap.<String, String>of());

factory.newTracer(
NoopApiTracer.getInstance(), SpanName.of("FakeClient", "FakeMethod"), OperationType.Unary);
BaseApiTracer.getInstance(), SpanName.of("FakeClient", "FakeMethod"), OperationType.Unary);

verify(internalTracer)
.spanBuilderWithExplicitParent(eq("FakeClient.FakeMethod"), nullable(Span.class));
Expand All @@ -96,7 +96,7 @@ public void testImplicitParentSpan() {

try {
factory.newTracer(
NoopApiTracer.getInstance(),
BaseApiTracer.getInstance(),
SpanName.of("FakeClient", "FakeMethod"),
OperationType.Unary);
} finally {
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testSpanAttributes() {
new OpencensusTracerFactory(internalTracer, ImmutableMap.of("gax.version", "1.2.3"));

factory.newTracer(
NoopApiTracer.getInstance(), SpanName.of("FakeClient", "FakeMethod"), OperationType.Unary);
BaseApiTracer.getInstance(), SpanName.of("FakeClient", "FakeMethod"), OperationType.Unary);

verify(span, times(1))
.putAttributes(
Expand Down
Expand Up @@ -65,7 +65,7 @@ public class TracedBidiCallableTest {
private FakeCallContext outerCallContext;

@Mock private ApiTracerFactory tracerFactory;
private ApiTracer parentTracer = NoopApiTracer.getInstance();
private ApiTracer parentTracer = BaseApiTracer.getInstance();
@Mock private ApiTracer tracer;

private TracedBidiCallable<String, String> tracedCallable;
Expand Down
Expand Up @@ -76,7 +76,7 @@ public class TracedCallableTest {

@Before
public void setUp() {
parentTracer = NoopApiTracer.getInstance();
parentTracer = BaseApiTracer.getInstance();

// Wire the mock tracer factory
when(tracerFactory.newTracer(
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class TracedClientStreamingCallableTest {
public @Rule MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);

@Mock private ApiTracerFactory tracerFactory;
private ApiTracer parentTracer = NoopApiTracer.getInstance();
private ApiTracer parentTracer = BaseApiTracer.getInstance();
@Mock private ApiTracer tracer;

private FakeClientCallable innerCallable;
Expand Down
Expand Up @@ -76,7 +76,7 @@ public class TracedOperationCallableTest {

@Before
public void setUp() {
parentTracer = NoopApiTracer.getInstance();
parentTracer = BaseApiTracer.getInstance();

// Wire the mock tracer factory
when(tracerFactory.newTracer(
Expand Down
Expand Up @@ -70,7 +70,7 @@ public class TracedUnaryCallableTest {

@Before
public void setUp() {
parentTracer = NoopApiTracer.getInstance();
parentTracer = BaseApiTracer.getInstance();

// Wire the mock tracer factory
when(tracerFactory.newTracer(
Expand Down

0 comments on commit 5224356

Please sign in to comment.