core, census, testing, interop-testing, android-interop-testing: move census dependency out of grpc-core (#6577)

Decouples grpc-core with census, while still preserve the default integration of census in grpc-core. Users wishing to enable census needs to add grpc-census to their runtime classpath.

- Created a grpc-census module:
    - Moved CensusStatsModule.java and CensusTracingModule.java into grpc-census from grpc-core. CensusModuleTests.java is also moved. They now belong to io.grpc.census package.
Moved DeprecatedCensusConstants.java into io.grpc.census.internal (is this necessary?) in grpc-census.
    - Created CensusStatsAccessor.java and CensusTracingAccessor.java, which are used to create census ClientInterceptor and ServerStreamTracer.Factory.
    - Everything in grpc-census are package private, except the accessor classes. They only publicly expose ClientInterceptor and ServerStreamTracer.Factory, no Census specific types are exposed.

- Use runtime reflection to load and apply census stats/tracing to channel/server builders, if grpc-census is found in runtime classpath.

- Removed special APIs on AbstractManagedChannelImplBuilder and AbstractServerImplBuilder for overriding census module. They are only used for testing. Now we changed tests to apply Census ClientInterceptor and ServerStreamTracer.Factory just as normal interceptor/stream tracer factory. Test writer is responsible for taking care of the ordering concerns of interceptors and stream tracer factories.
This commit is contained in:
Chengyuan Zhang 2020-01-13 14:35:29 -08:00 committed by GitHub
parent 1cefe851e1
commit b7ccc0d142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 447 additions and 155 deletions

View File

@ -73,6 +73,7 @@ dependencies {
// You need to build grpc-java to obtain the grpc libraries below. // You need to build grpc-java to obtain the grpc libraries below.
implementation 'io.grpc:grpc-auth:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-auth:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-census:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-okhttp:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-okhttp:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-protobuf-lite:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-protobuf-lite:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION
implementation 'io.grpc:grpc-stub:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-stub:1.27.0-SNAPSHOT' // CURRENT_GRPC_VERSION

15
census/BUILD.bazel Normal file
View File

@ -0,0 +1,15 @@
java_library(
name = "census",
srcs = glob([
"src/main/java/**/*.java",
]),
visibility = ["//visibility:public"],
deps = [
"//api",
"//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@io_opencensus_opencensus_api//jar",
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
],
)

43
census/build.gradle Normal file
View File

@ -0,0 +1,43 @@
plugins {
id "java"
id "maven-publish"
}
description = 'gRPC: Census'
evaluationDependsOn(project(':grpc-api').path)
dependencies {
compile project(':grpc-api')
compile (libraries.opencensus_api) {
// prefer 3.0.2 from libraries instead of 3.0.1
exclude group: 'com.google.code.findbugs', module: 'jsr305'
// prefer 20.0 from libraries instead of 19.0
exclude group: 'com.google.guava', module: 'guava'
// we'll always be more up-to-date
exclude group: 'io.grpc', module: 'grpc-context'
}
compile (libraries.opencensus_contrib_grpc_metrics) {
// prefer 3.0.2 from libraries instead of 3.0.1
exclude group: 'com.google.code.findbugs', module: 'jsr305'
// we'll always be more up-to-date
exclude group: 'io.grpc', module: 'grpc-context'
// prefer 20.0 from libraries instead of 19.0
exclude group: 'com.google.guava', module: 'guava'
}
testCompile project(':grpc-api').sourceSets.test.output,
project(':grpc-context').sourceSets.test.output,
project(':grpc-core').sourceSets.test.output,
project(':grpc-testing'),
libraries.guava_testlib,
libraries.opencensus_impl
}
javadoc {
failOnError false // no public or protected classes found to document
exclude 'io/grpc/census/internal/**'
exclude 'io/grpc/census/Internal*'
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.internal; package io.grpc.census;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
@ -35,6 +35,7 @@ import io.grpc.MethodDescriptor;
import io.grpc.ServerStreamTracer; import io.grpc.ServerStreamTracer;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.StreamTracer; import io.grpc.StreamTracer;
import io.grpc.census.internal.DeprecatedCensusConstants;
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants; import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;
import io.opencensus.stats.Measure.MeasureDouble; import io.opencensus.stats.Measure.MeasureDouble;
import io.opencensus.stats.Measure.MeasureLong; import io.opencensus.stats.Measure.MeasureLong;
@ -67,7 +68,7 @@ import javax.annotation.Nullable;
* starts earlier than the ServerCall. Therefore, only one tracer is created per stream/call and * starts earlier than the ServerCall. Therefore, only one tracer is created per stream/call and
* it's the tracer that reports the summary to Census. * it's the tracer that reports the summary to Census.
*/ */
public final class CensusStatsModule { final class CensusStatsModule {
private static final Logger logger = Logger.getLogger(CensusStatsModule.class.getName()); private static final Logger logger = Logger.getLogger(CensusStatsModule.class.getName());
private static final double NANOS_PER_MILLI = TimeUnit.MILLISECONDS.toNanos(1); private static final double NANOS_PER_MILLI = TimeUnit.MILLISECONDS.toNanos(1);
@ -98,7 +99,7 @@ public final class CensusStatsModule {
/** /**
* Creates a {@link CensusStatsModule} with the given OpenCensus implementation. * Creates a {@link CensusStatsModule} with the given OpenCensus implementation.
*/ */
public CensusStatsModule( CensusStatsModule(
final Tagger tagger, final Tagger tagger,
final TagContextBinarySerializer tagCtxSerializer, final TagContextBinarySerializer tagCtxSerializer,
StatsRecorder statsRecorder, Supplier<Stopwatch> stopwatchSupplier, StatsRecorder statsRecorder, Supplier<Stopwatch> stopwatchSupplier,

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.internal; package io.grpc.census;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -0,0 +1,117 @@
/*
* Copyright 2019 The gRPC 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 io.grpc.census;
import com.google.common.base.Stopwatch;
import com.google.common.base.Supplier;
import io.grpc.ClientInterceptor;
import io.grpc.Internal;
import io.grpc.ServerStreamTracer;
import io.opencensus.stats.StatsRecorder;
import io.opencensus.tags.Tagger;
import io.opencensus.tags.propagation.TagContextBinarySerializer;
/**
* Accessor for getting {@link ClientInterceptor} or {@link ServerStreamTracer.Factory} with
* default Census stats implementation.
*/
@Internal
public final class InternalCensusStatsAccessor {
private static final Supplier<Stopwatch> STOPWATCH_SUPPLIER = new Supplier<Stopwatch>() {
@Override
public Stopwatch get() {
return Stopwatch.createUnstarted();
}
};
// Prevent instantiation.
private InternalCensusStatsAccessor() {
}
/**
* Returns a {@link ClientInterceptor} with default stats implementation.
*/
public static ClientInterceptor getClientInterceptor(
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
STOPWATCH_SUPPLIER,
true, /* propagateTags */
recordStartedRpcs,
recordFinishedRpcs,
recordRealTimeMetrics);
return censusStats.getClientInterceptor();
}
/**
* Returns a {@link ClientInterceptor} with custom stats implementation.
*/
public static ClientInterceptor getClientInterceptor(
Tagger tagger,
TagContextBinarySerializer tagCtxSerializer,
StatsRecorder statsRecorder,
Supplier<Stopwatch> stopwatchSupplier,
boolean propagateTags,
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
return censusStats.getClientInterceptor();
}
/**
* Returns a {@link ServerStreamTracer.Factory} with default stats implementation.
*/
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
STOPWATCH_SUPPLIER,
true, /* propagateTags */
recordStartedRpcs,
recordFinishedRpcs,
recordRealTimeMetrics);
return censusStats.getServerTracerFactory();
}
/**
* Returns a {@link ServerStreamTracer.Factory} with custom stats implementation.
*/
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
Tagger tagger,
TagContextBinarySerializer tagCtxSerializer,
StatsRecorder statsRecorder,
Supplier<Stopwatch> stopwatchSupplier,
boolean propagateTags,
boolean recordStartedRpcs,
boolean recordFinishedRpcs,
boolean recordRealTimeMetrics) {
CensusStatsModule censusStats =
new CensusStatsModule(
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics);
return censusStats.getServerTracerFactory();
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2019 The gRPC 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 io.grpc.census;
import io.grpc.ClientInterceptor;
import io.grpc.Internal;
import io.grpc.ServerStreamTracer;
import io.opencensus.trace.Tracing;
/**
* Accessor for getting {@link ClientInterceptor} or {@link ServerStreamTracer.Factory} with
* default Census tracing implementation.
*/
@Internal
public final class InternalCensusTracingAccessor {
// Prevent instantiation.
private InternalCensusTracingAccessor() {
}
/**
* Returns a {@link ClientInterceptor} with default tracing implementation.
*/
public static ClientInterceptor getClientInterceptor() {
CensusTracingModule censusTracing =
new CensusTracingModule(
Tracing.getTracer(),
Tracing.getPropagationComponent().getBinaryFormat());
return censusTracing.getClientInterceptor();
}
/**
* Returns a {@link ServerStreamTracer.Factory} with default stats implementation.
*/
public static ServerStreamTracer.Factory getServerStreamTracerFactory() {
CensusTracingModule censusTracing =
new CensusTracingModule(
Tracing.getTracer(),
Tracing.getPropagationComponent().getBinaryFormat());
return censusTracing.getServerTracerFactory();
}
}

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.internal; package io.grpc.census.internal;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants; import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.internal; package io.grpc.census;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
@ -56,7 +56,10 @@ import io.grpc.ServerCall;
import io.grpc.ServerCallHandler; import io.grpc.ServerCallHandler;
import io.grpc.ServerServiceDefinition; import io.grpc.ServerServiceDefinition;
import io.grpc.ServerStreamTracer; import io.grpc.ServerStreamTracer;
import io.grpc.ServerStreamTracer.ServerCallInfo;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.census.internal.DeprecatedCensusConstants;
import io.grpc.internal.FakeClock;
import io.grpc.internal.testing.StatsTestUtils; import io.grpc.internal.testing.StatsTestUtils;
import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder; import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder;
import io.grpc.internal.testing.StatsTestUtils.FakeTagContextBinarySerializer; import io.grpc.internal.testing.StatsTestUtils.FakeTagContextBinarySerializer;
@ -95,6 +98,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -1044,7 +1048,7 @@ public class CensusModulesTest {
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext)); assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
serverStreamTracer.serverCallStarted( serverStreamTracer.serverCallStarted(
new ServerCallInfoImpl<>(method, Attributes.EMPTY, null)); new CallInfo<>(method, Attributes.EMPTY, null));
verify(spyServerSpan, never()).end(any(EndSpanOptions.class)); verify(spyServerSpan, never()).end(any(EndSpanOptions.class));
@ -1087,7 +1091,7 @@ public class CensusModulesTest {
serverStreamTracer.filterContext(Context.ROOT); serverStreamTracer.filterContext(Context.ROOT);
serverStreamTracer.serverCallStarted( serverStreamTracer.serverCallStarted(
new ServerCallInfoImpl<>(sampledMethod, Attributes.EMPTY, null)); new CallInfo<>(sampledMethod, Attributes.EMPTY, null));
serverStreamTracer.streamClosed(Status.CANCELLED); serverStreamTracer.streamClosed(Status.CANCELLED);
@ -1250,8 +1254,39 @@ public class CensusModulesTest {
new Function<AggregationData, Long>() { new Function<AggregationData, Long>() {
@Override @Override
public Long apply(AggregationData arg) { public Long apply(AggregationData arg) {
return ((io.opencensus.stats.AggregationData.MeanData) arg).getCount(); return ((AggregationData.MeanData) arg).getCount();
} }
}); });
} }
private static class CallInfo<ReqT, RespT> extends ServerCallInfo<ReqT, RespT> {
private final MethodDescriptor<ReqT, RespT> methodDescriptor;
private final Attributes attributes;
private final String authority;
CallInfo(
MethodDescriptor<ReqT, RespT> methodDescriptor,
Attributes attributes,
@Nullable String authority) {
this.methodDescriptor = methodDescriptor;
this.attributes = attributes;
this.authority = authority;
}
@Override
public MethodDescriptor<ReqT, RespT> getMethodDescriptor() {
return methodDescriptor;
}
@Override
public Attributes getAttributes() {
return attributes;
}
@Nullable
@Override
public String getAuthority() {
return authority;
}
}
} }

View File

@ -38,8 +38,6 @@ java_library(
"@com_google_errorprone_error_prone_annotations//jar", "@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar", "@com_google_guava_guava//jar",
"@com_google_j2objc_j2objc_annotations//jar", "@com_google_j2objc_j2objc_annotations//jar",
"@io_opencensus_opencensus_api//jar",
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
"@io_perfmark_perfmark_api//jar", "@io_perfmark_perfmark_api//jar",
"@org_codehaus_mojo_animal_sniffer_annotations//jar", "@org_codehaus_mojo_animal_sniffer_annotations//jar",
], ],

View File

@ -20,25 +20,14 @@ dependencies {
compile (libraries.perfmark) { compile (libraries.perfmark) {
exclude group: 'com.google.errorprone', module: 'error_prone_annotations' exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
} }
compile (libraries.opencensus_api) {
// prefer our own versions instead of opencensus-api's dependency
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'io.grpc', module: 'grpc-context'
}
compile (libraries.opencensus_contrib_grpc_metrics) {
// prefer our own versions instead of opencensus-contrib's dependency
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'com.google.guava', module: 'guava'
}
testCompile project(':grpc-context').sourceSets.test.output, testCompile project(':grpc-context').sourceSets.test.output,
project(':grpc-api').sourceSets.test.output, project(':grpc-api').sourceSets.test.output,
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-grpclb'), project(':grpc-grpclb'),
libraries.guava_testlib, libraries.guava_testlib
libraries.opencensus_impl
testRuntimeOnly project(':grpc-census')
jmh project(':grpc-testing') jmh project(':grpc-testing')

View File

@ -33,7 +33,8 @@ import io.grpc.ManagedChannelBuilder;
import io.grpc.NameResolver; import io.grpc.NameResolver;
import io.grpc.NameResolverRegistry; import io.grpc.NameResolverRegistry;
import io.grpc.ProxyDetector; import io.grpc.ProxyDetector;
import io.opencensus.trace.Tracing; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -45,6 +46,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -56,6 +59,9 @@ public abstract class AbstractManagedChannelImplBuilder
<T extends AbstractManagedChannelImplBuilder<T>> extends ManagedChannelBuilder<T> { <T extends AbstractManagedChannelImplBuilder<T>> extends ManagedChannelBuilder<T> {
private static final String DIRECT_ADDRESS_SCHEME = "directaddress"; private static final String DIRECT_ADDRESS_SCHEME = "directaddress";
private static final Logger log =
Logger.getLogger(AbstractManagedChannelImplBuilder.class.getName());
public static ManagedChannelBuilder<?> forAddress(String name, int port) { public static ManagedChannelBuilder<?> forAddress(String name, int port) {
throw new UnsupportedOperationException("Subclass failed to hide static factory"); throw new UnsupportedOperationException("Subclass failed to hide static factory");
} }
@ -184,9 +190,6 @@ public abstract class AbstractManagedChannelImplBuilder
private boolean recordRealTimeMetrics = false; private boolean recordRealTimeMetrics = false;
private boolean tracingEnabled = true; private boolean tracingEnabled = true;
@Nullable
private CensusStatsModule censusStatsOverride;
protected AbstractManagedChannelImplBuilder(String target) { protected AbstractManagedChannelImplBuilder(String target) {
this.target = Preconditions.checkNotNull(target, "target"); this.target = Preconditions.checkNotNull(target, "target");
this.directServerAddress = null; this.directServerAddress = null;
@ -376,15 +379,6 @@ public abstract class AbstractManagedChannelImplBuilder
return thisT(); return thisT();
} }
/**
* Override the default stats implementation.
*/
@VisibleForTesting
protected final T overrideCensusStatsModule(CensusStatsModule censusStats) {
this.censusStatsOverride = censusStats;
return thisT();
}
@Override @Override
public T proxyDetector(@Nullable ProxyDetector proxyDetector) { public T proxyDetector(@Nullable ProxyDetector proxyDetector) {
this.proxyDetector = proxyDetector; this.proxyDetector = proxyDetector;
@ -565,22 +559,49 @@ public abstract class AbstractManagedChannelImplBuilder
temporarilyDisableRetry = false; temporarilyDisableRetry = false;
if (statsEnabled) { if (statsEnabled) {
temporarilyDisableRetry = true; temporarilyDisableRetry = true;
CensusStatsModule censusStats = this.censusStatsOverride; ClientInterceptor statsInterceptor = null;
if (censusStats == null) { try {
censusStats = new CensusStatsModule( Class<?> censusStatsAccessor =
GrpcUtil.STOPWATCH_SUPPLIER, true, recordStartedRpcs, recordFinishedRpcs, Class.forName("io.grpc.census.InternalCensusStatsAccessor");
Method getClientInterceptorMethod =
censusStatsAccessor.getDeclaredMethod(
"getClientInterceptor",
boolean.class,
boolean.class,
boolean.class);
statsInterceptor =
(ClientInterceptor) getClientInterceptorMethod
.invoke(
null,
recordStartedRpcs,
recordFinishedRpcs,
recordRealTimeMetrics); recordRealTimeMetrics);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
log.log(Level.FINE, "Unable to apply census stats", e);
} }
if (statsInterceptor != null) {
// First interceptor runs last (see ClientInterceptors.intercept()), so that no // First interceptor runs last (see ClientInterceptors.intercept()), so that no
// other interceptor can override the tracer factory we set in CallOptions. // other interceptor can override the tracer factory we set in CallOptions.
effectiveInterceptors.add(0, censusStats.getClientInterceptor()); effectiveInterceptors.add(0, statsInterceptor);
}
} }
if (tracingEnabled) { if (tracingEnabled) {
temporarilyDisableRetry = true; temporarilyDisableRetry = true;
CensusTracingModule censusTracing = ClientInterceptor tracingInterceptor = null;
new CensusTracingModule(Tracing.getTracer(), try {
Tracing.getPropagationComponent().getBinaryFormat()); Class<?> censusTracingAccessor =
effectiveInterceptors.add(0, censusTracing.getClientInterceptor()); Class.forName("io.grpc.census.InternalCensusTracingAccessor");
Method getClientInterceptroMethod =
censusTracingAccessor.getDeclaredMethod("getClientInterceptor");
tracingInterceptor = (ClientInterceptor) getClientInterceptroMethod.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
log.log(Level.FINE, "Unable to apply census tracing", e);
}
if (tracingInterceptor != null) {
effectiveInterceptors.add(0, tracingInterceptor);
}
} }
return effectiveInterceptors; return effectiveInterceptors;
} }

View File

@ -37,12 +37,15 @@ import io.grpc.ServerMethodDefinition;
import io.grpc.ServerServiceDefinition; import io.grpc.ServerServiceDefinition;
import io.grpc.ServerStreamTracer; import io.grpc.ServerStreamTracer;
import io.grpc.ServerTransportFilter; import io.grpc.ServerTransportFilter;
import io.opencensus.trace.Tracing; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -53,6 +56,8 @@ import javax.annotation.Nullable;
public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuilder<T>> public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuilder<T>>
extends ServerBuilder<T> { extends ServerBuilder<T> {
private static final Logger log = Logger.getLogger(AbstractServerImplBuilder.class.getName());
public static ServerBuilder<?> forPort(int port) { public static ServerBuilder<?> forPort(int port) {
throw new UnsupportedOperationException("Subclass failed to hide static factory"); throw new UnsupportedOperationException("Subclass failed to hide static factory");
} }
@ -80,7 +85,6 @@ public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuil
CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY; CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY;
long handshakeTimeoutMillis = DEFAULT_HANDSHAKE_TIMEOUT_MILLIS; long handshakeTimeoutMillis = DEFAULT_HANDSHAKE_TIMEOUT_MILLIS;
Deadline.Ticker ticker = Deadline.getSystemTicker(); Deadline.Ticker ticker = Deadline.getSystemTicker();
@Nullable private CensusStatsModule censusStatsOverride;
private boolean statsEnabled = true; private boolean statsEnabled = true;
private boolean recordStartedRpcs = true; private boolean recordStartedRpcs = true;
private boolean recordFinishedRpcs = true; private boolean recordFinishedRpcs = true;
@ -165,15 +169,6 @@ public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuil
return thisT(); return thisT();
} }
/**
* Override the default stats implementation.
*/
@VisibleForTesting
protected final T overrideCensusStatsModule(@Nullable CensusStatsModule censusStats) {
this.censusStatsOverride = censusStats;
return thisT();
}
@VisibleForTesting @VisibleForTesting
public final T setTransportTracerFactory(TransportTracer.Factory transportTracerFactory) { public final T setTransportTracerFactory(TransportTracer.Factory transportTracerFactory) {
this.transportTracerFactory = transportTracerFactory; this.transportTracerFactory = transportTracerFactory;
@ -241,19 +236,47 @@ public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuil
final List<? extends ServerStreamTracer.Factory> getTracerFactories() { final List<? extends ServerStreamTracer.Factory> getTracerFactories() {
ArrayList<ServerStreamTracer.Factory> tracerFactories = new ArrayList<>(); ArrayList<ServerStreamTracer.Factory> tracerFactories = new ArrayList<>();
if (statsEnabled) { if (statsEnabled) {
CensusStatsModule censusStats = censusStatsOverride; ServerStreamTracer.Factory censusStatsTracerFactory = null;
if (censusStats == null) { try {
censusStats = new CensusStatsModule( Class<?> censusStatsAccessor =
GrpcUtil.STOPWATCH_SUPPLIER, true, recordStartedRpcs, recordFinishedRpcs, Class.forName("io.grpc.census.InternalCensusStatsAccessor");
Method getServerStreamTracerFactoryMethod =
censusStatsAccessor.getDeclaredMethod(
"getServerStreamTracerFactory",
boolean.class,
boolean.class,
boolean.class);
censusStatsTracerFactory =
(ServerStreamTracer.Factory) getServerStreamTracerFactoryMethod
.invoke(
null,
recordStartedRpcs,
recordFinishedRpcs,
recordRealTimeMetrics); recordRealTimeMetrics);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
log.log(Level.FINE, "Unable to apply census stats", e);
}
if (censusStatsTracerFactory != null) {
tracerFactories.add(censusStatsTracerFactory);
} }
tracerFactories.add(censusStats.getServerTracerFactory());
} }
if (tracingEnabled) { if (tracingEnabled) {
CensusTracingModule censusTracing = ServerStreamTracer.Factory tracingStreamTracerFactory = null;
new CensusTracingModule(Tracing.getTracer(), try {
Tracing.getPropagationComponent().getBinaryFormat()); Class<?> censusTracingAccessor =
tracerFactories.add(censusTracing.getServerTracerFactory()); Class.forName("io.grpc.census.InternalCensusTracingAccessor");
Method getServerStreamTracerFactoryMethod =
censusTracingAccessor.getDeclaredMethod("getServerStreamTracerFactory");
tracingStreamTracerFactory =
(ServerStreamTracer.Factory) getServerStreamTracerFactoryMethod.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException e) {
log.log(Level.FINE, "Unable to apply census tracing", e);
}
if (tracingStreamTracerFactory != null) {
tracerFactories.add(tracingStreamTracerFactory);
}
} }
tracerFactories.addAll(streamTracerFactories); tracerFactories.addAll(streamTracerFactories);
tracerFactories.trimToSize(); tracerFactories.trimToSize();

View File

@ -36,9 +36,6 @@ import io.grpc.CompressorRegistry;
import io.grpc.DecompressorRegistry; import io.grpc.DecompressorRegistry;
import io.grpc.MethodDescriptor; import io.grpc.MethodDescriptor;
import io.grpc.NameResolver; import io.grpc.NameResolver;
import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder;
import io.grpc.internal.testing.StatsTestUtils.FakeTagContextBinarySerializer;
import io.grpc.internal.testing.StatsTestUtils.FakeTagger;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URI; import java.net.URI;
@ -284,10 +281,10 @@ public class AbstractManagedChannelImplBuilderTest {
builder.intercept(DUMMY_USER_INTERCEPTOR); builder.intercept(DUMMY_USER_INTERCEPTOR);
List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors(); List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors();
assertEquals(3, effectiveInterceptors.size()); assertEquals(3, effectiveInterceptors.size());
assertThat(effectiveInterceptors.get(0)) assertThat(effectiveInterceptors.get(0).getClass().getName())
.isInstanceOf(CensusTracingModule.TracingClientInterceptor.class); .isEqualTo("io.grpc.census.CensusTracingModule$TracingClientInterceptor");
assertThat(effectiveInterceptors.get(1)) assertThat(effectiveInterceptors.get(1).getClass().getName())
.isInstanceOf(CensusStatsModule.StatsClientInterceptor.class); .isEqualTo("io.grpc.census.CensusStatsModule$StatsClientInterceptor");
assertThat(effectiveInterceptors.get(2)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR); assertThat(effectiveInterceptors.get(2)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR);
} }
@ -297,8 +294,8 @@ public class AbstractManagedChannelImplBuilderTest {
builder.setStatsEnabled(false); builder.setStatsEnabled(false);
List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors(); List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors();
assertEquals(2, effectiveInterceptors.size()); assertEquals(2, effectiveInterceptors.size());
assertThat(effectiveInterceptors.get(0)) assertThat(effectiveInterceptors.get(0).getClass().getName())
.isInstanceOf(CensusTracingModule.TracingClientInterceptor.class); .isEqualTo("io.grpc.census.CensusTracingModule$TracingClientInterceptor");
assertThat(effectiveInterceptors.get(1)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR); assertThat(effectiveInterceptors.get(1)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR);
} }
@ -308,8 +305,8 @@ public class AbstractManagedChannelImplBuilderTest {
builder.setTracingEnabled(false); builder.setTracingEnabled(false);
List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors(); List<ClientInterceptor> effectiveInterceptors = builder.getEffectiveInterceptors();
assertEquals(2, effectiveInterceptors.size()); assertEquals(2, effectiveInterceptors.size());
assertThat(effectiveInterceptors.get(0)) assertThat(effectiveInterceptors.get(0).getClass().getName())
.isInstanceOf(CensusStatsModule.StatsClientInterceptor.class); .isEqualTo("io.grpc.census.CensusStatsModule$StatsClientInterceptor");
assertThat(effectiveInterceptors.get(1)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR); assertThat(effectiveInterceptors.get(1)).isSameInstanceAs(DUMMY_USER_INTERCEPTOR);
} }
@ -500,24 +497,10 @@ public class AbstractManagedChannelImplBuilderTest {
static class Builder extends AbstractManagedChannelImplBuilder<Builder> { static class Builder extends AbstractManagedChannelImplBuilder<Builder> {
Builder(String target) { Builder(String target) {
super(target); super(target);
overrideCensusStatsModule(
new CensusStatsModule(
new FakeTagger(),
new FakeTagContextBinarySerializer(),
new FakeStatsRecorder(),
GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, true));
} }
Builder(SocketAddress directServerAddress, String authority) { Builder(SocketAddress directServerAddress, String authority) {
super(directServerAddress, authority); super(directServerAddress, authority);
overrideCensusStatsModule(
new CensusStatsModule(
new FakeTagger(),
new FakeTagContextBinarySerializer(),
new FakeStatsRecorder(),
GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, true));
} }
@Override @Override

View File

@ -21,9 +21,6 @@ import static org.junit.Assert.assertEquals;
import io.grpc.Metadata; import io.grpc.Metadata;
import io.grpc.ServerStreamTracer; import io.grpc.ServerStreamTracer;
import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder;
import io.grpc.internal.testing.StatsTestUtils.FakeTagContextBinarySerializer;
import io.grpc.internal.testing.StatsTestUtils.FakeTagger;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -51,8 +48,10 @@ public class AbstractServerImplBuilderTest {
List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories(); List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();
assertEquals(3, factories.size()); assertEquals(3, factories.size());
assertThat(factories.get(0)).isInstanceOf(CensusStatsModule.ServerTracerFactory.class); assertThat(factories.get(0).getClass().getName())
assertThat(factories.get(1)).isInstanceOf(CensusTracingModule.ServerTracerFactory.class); .isEqualTo("io.grpc.census.CensusStatsModule$ServerTracerFactory");
assertThat(factories.get(1).getClass().getName())
.isEqualTo("io.grpc.census.CensusTracingModule$ServerTracerFactory");
assertThat(factories.get(2)).isSameInstanceAs(DUMMY_USER_TRACER); assertThat(factories.get(2)).isSameInstanceAs(DUMMY_USER_TRACER);
} }
@ -64,7 +63,8 @@ public class AbstractServerImplBuilderTest {
List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories(); List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();
assertEquals(2, factories.size()); assertEquals(2, factories.size());
assertThat(factories.get(0)).isInstanceOf(CensusTracingModule.ServerTracerFactory.class); assertThat(factories.get(0).getClass().getName())
.isEqualTo("io.grpc.census.CensusTracingModule$ServerTracerFactory");
assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER); assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER);
} }
@ -76,7 +76,8 @@ public class AbstractServerImplBuilderTest {
List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories(); List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();
assertEquals(2, factories.size()); assertEquals(2, factories.size());
assertThat(factories.get(0)).isInstanceOf(CensusStatsModule.ServerTracerFactory.class); assertThat(factories.get(0).getClass().getName())
.isEqualTo("io.grpc.census.CensusStatsModule$ServerTracerFactory");
assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER); assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER);
} }
@ -90,15 +91,6 @@ public class AbstractServerImplBuilderTest {
} }
static class Builder extends AbstractServerImplBuilder<Builder> { static class Builder extends AbstractServerImplBuilder<Builder> {
Builder() {
overrideCensusStatsModule(
new CensusStatsModule(
new FakeTagger(),
new FakeTagContextBinarySerializer(),
new FakeStatsRecorder(),
GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, true));
}
@Override @Override
protected List<io.grpc.internal.InternalServer> buildTransportServers( protected List<io.grpc.internal.InternalServer> buildTransportServers(

View File

@ -18,6 +18,7 @@ evaluationDependsOn(project(':grpc-context').path)
dependencies { dependencies {
compile project(':grpc-alts'), compile project(':grpc-alts'),
project(':grpc-auth'), project(':grpc-auth'),
project(':grpc-census'),
project(':grpc-core'), project(':grpc-core'),
project(':grpc-netty'), project(':grpc-netty'),
project(':grpc-okhttp'), project(':grpc-okhttp'),

View File

@ -61,9 +61,9 @@ import io.grpc.ServerStreamTracer;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.StatusRuntimeException; import io.grpc.StatusRuntimeException;
import io.grpc.auth.MoreCallCredentials; import io.grpc.auth.MoreCallCredentials;
import io.grpc.census.InternalCensusStatsAccessor;
import io.grpc.census.internal.DeprecatedCensusConstants;
import io.grpc.internal.AbstractServerImplBuilder; import io.grpc.internal.AbstractServerImplBuilder;
import io.grpc.internal.CensusStatsModule;
import io.grpc.internal.DeprecatedCensusConstants;
import io.grpc.internal.GrpcUtil; import io.grpc.internal.GrpcUtil;
import io.grpc.internal.testing.StatsTestUtils; import io.grpc.internal.testing.StatsTestUtils;
import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder; import io.grpc.internal.testing.StatsTestUtils.FakeStatsRecorder;
@ -240,15 +240,15 @@ public abstract class AbstractInteropTest {
.addStreamTracerFactory(serverStreamTracerFactory); .addStreamTracerFactory(serverStreamTracerFactory);
if (builder instanceof AbstractServerImplBuilder) { if (builder instanceof AbstractServerImplBuilder) {
customCensusModulePresent = true; customCensusModulePresent = true;
AbstractServerImplBuilder<?> sb = (AbstractServerImplBuilder<?>) builder; ServerStreamTracer.Factory censusTracerFactory =
io.grpc.internal.TestingAccessor.setStatsImplementation( InternalCensusStatsAccessor
sb, .getServerStreamTracerFactory(
new CensusStatsModule( tagger, tagContextBinarySerializer, serverStatsRecorder,
tagger,
tagContextBinarySerializer,
serverStatsRecorder,
GrpcUtil.STOPWATCH_SUPPLIER, GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, false /* real-time metrics */)); true, true, true, false /* real-time metrics */);
AbstractServerImplBuilder<?> sb = (AbstractServerImplBuilder<?>) builder;
io.grpc.internal.TestingAccessor.setStatsEnabled(sb, false);
sb.addStreamTracerFactory(censusTracerFactory);
} }
if (metricsExpected()) { if (metricsExpected()) {
assertThat(builder).isInstanceOf(AbstractServerImplBuilder.class); assertThat(builder).isInstanceOf(AbstractServerImplBuilder.class);
@ -353,9 +353,12 @@ public abstract class AbstractInteropTest {
return null; return null;
} }
protected final CensusStatsModule createClientCensusStatsModule() { protected final ClientInterceptor createCensusStatsClientInterceptor() {
return new CensusStatsModule( return
tagger, tagContextBinarySerializer, clientStatsRecorder, GrpcUtil.STOPWATCH_SUPPLIER, InternalCensusStatsAccessor
.getClientInterceptor(
tagger, tagContextBinarySerializer, clientStatsRecorder,
GrpcUtil.STOPWATCH_SUPPLIER,
true, true, true, false /* real-time metrics */); true, true, true, false /* real-time metrics */);
} }

View File

@ -450,9 +450,9 @@ public class TestServiceClient {
} }
builder = okBuilder; builder = okBuilder;
} }
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} }
@Override @Override

View File

@ -46,8 +46,8 @@ public class AutoWindowSizingOnTest extends AbstractInteropTest {
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress()) NettyChannelBuilder builder = NettyChannelBuilder.forAddress(getListenAddress())
.negotiationType(NegotiationType.PLAINTEXT) .negotiationType(NegotiationType.PLAINTEXT)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} }
} }

View File

@ -57,9 +57,9 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
.eventLoopGroup(eventLoopGroup) .eventLoopGroup(eventLoopGroup)
.flowControlWindow(65 * 1024) .flowControlWindow(65 * 1024)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} }
@Override @Override

View File

@ -71,9 +71,9 @@ public class Http2NettyTest extends AbstractInteropTest {
.trustManager(TestUtils.loadX509Cert("ca.pem")) .trustManager(TestUtils.loadX509Cert("ca.pem"))
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
.build()); .build());
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }

View File

@ -100,15 +100,15 @@ public class Http2OkHttpTest extends AbstractInteropTest {
.build()) .build())
.overrideAuthority(GrpcUtil.authorityFromHostAndPort( .overrideAuthority(GrpcUtil.authorityFromHostAndPort(
TestUtils.TEST_SERVER_HOST, port)); TestUtils.TEST_SERVER_HOST, port));
io.grpc.internal.TestingAccessor.setStatsImplementation(
builder, createClientCensusStatsModule());
try { try {
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(),
TestUtils.loadCert("ca.pem"))); TestUtils.loadCert("ca.pem")));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return builder; // Disable the default census stats interceptor, use testing interceptor instead.
io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.intercept(createCensusStatsClientInterceptor());
} }
@Test @Test

View File

@ -38,9 +38,9 @@ public class InProcessTest extends AbstractInteropTest {
@Override @Override
protected ManagedChannel createChannel() { protected ManagedChannel createChannel() {
InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME); InProcessChannelBuilder builder = InProcessChannelBuilder.forName(SERVER_NAME);
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} }
@Override @Override

View File

@ -165,9 +165,9 @@ public class TransportCompressionTest extends AbstractInteropTest {
} }
}) })
.usePlaintext(); .usePlaintext();
io.grpc.internal.TestingAccessor.setStatsImplementation( // Disable the default census stats interceptor, use testing interceptor instead.
builder, createClientCensusStatsModule()); io.grpc.internal.TestingAccessor.setStatsEnabled(builder, false);
return builder.build(); return builder.intercept(createCensusStatsClientInterceptor()).build();
} }
/** /**

View File

@ -70,6 +70,7 @@ IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS = {
"io.grpc:grpc-alts": "@io_grpc_grpc_java//alts", "io.grpc:grpc-alts": "@io_grpc_grpc_java//alts",
"io.grpc:grpc-api": "@io_grpc_grpc_java//api", "io.grpc:grpc-api": "@io_grpc_grpc_java//api",
"io.grpc:grpc-auth": "@io_grpc_grpc_java//auth", "io.grpc:grpc-auth": "@io_grpc_grpc_java//auth",
"io.grpc:grpc-census": "@io_grpc_grpc_java//census",
"io.grpc:grpc-context": "@io_grpc_grpc_java//context", "io.grpc:grpc-context": "@io_grpc_grpc_java//context",
"io.grpc:grpc-core": "@io_grpc_grpc_java//core:core_maven", "io.grpc:grpc-core": "@io_grpc_grpc_java//core:core_maven",
"io.grpc:grpc-grpclb": "@io_grpc_grpc_java//grpclb", "io.grpc:grpc-grpclb": "@io_grpc_grpc_java//grpclb",

View File

@ -29,6 +29,7 @@ include ":grpc-api"
include ":grpc-core" include ":grpc-core"
include ":grpc-context" include ":grpc-context"
include ":grpc-stub" include ":grpc-stub"
include ":grpc-census"
include ":grpc-auth" include ":grpc-auth"
include ":grpc-okhttp" include ":grpc-okhttp"
include ":grpc-protobuf" include ":grpc-protobuf"
@ -51,6 +52,7 @@ project(':grpc-api').projectDir = "$rootDir/api" as File
project(':grpc-core').projectDir = "$rootDir/core" as File project(':grpc-core').projectDir = "$rootDir/core" as File
project(':grpc-context').projectDir = "$rootDir/context" as File project(':grpc-context').projectDir = "$rootDir/context" as File
project(':grpc-stub').projectDir = "$rootDir/stub" as File project(':grpc-stub').projectDir = "$rootDir/stub" as File
project(':grpc-census').projectDir = "$rootDir/census" as File
project(':grpc-auth').projectDir = "$rootDir/auth" as File project(':grpc-auth').projectDir = "$rootDir/auth" as File
project(':grpc-okhttp').projectDir = "$rootDir/okhttp" as File project(':grpc-okhttp').projectDir = "$rootDir/okhttp" as File
project(':grpc-protobuf').projectDir = "$rootDir/protobuf" as File project(':grpc-protobuf').projectDir = "$rootDir/protobuf" as File

View File

@ -31,5 +31,6 @@ java_library(
deps = [ deps = [
"//api", "//api",
"//core:internal", "//core:internal",
"@io_opencensus_opencensus_api//jar",
], ],
) )

View File

@ -14,6 +14,15 @@ dependencies {
project(':grpc-stub'), project(':grpc-stub'),
libraries.junit libraries.junit
compile (libraries.opencensus_api) {
// prefer 3.0.2 from libraries instead of 3.0.1
exclude group: 'com.google.code.findbugs', module: 'jsr305'
// prefer 20.0 from libraries instead of 19.0
exclude group: 'com.google.guava', module: 'guava'
// we'll always be more up-to-date
exclude group: 'io.grpc', module: 'grpc-context'
}
testCompile (libraries.mockito) { testCompile (libraries.mockito) {
// prefer our own versions instead of mockito's dependency // prefer our own versions instead of mockito's dependency
exclude group: 'org.hamcrest', module: 'hamcrest-core' exclude group: 'org.hamcrest', module: 'hamcrest-core'

View File

@ -21,19 +21,20 @@ package io.grpc.internal;
*/ */
public final class TestingAccessor { public final class TestingAccessor {
/** /**
* Sets a custom stats implementation for tests. * Disable or enable client side census stats features.
*/ */
public static void setStatsImplementation( public static void setStatsEnabled(
AbstractManagedChannelImplBuilder<?> builder, CensusStatsModule censusStats) { AbstractManagedChannelImplBuilder<?> builder, boolean statsEnabled) {
builder.overrideCensusStatsModule(censusStats); builder.setStatsEnabled(statsEnabled);
} }
/** /**
* Sets a custom stats implementation for tests. * Disable or enable server side census stats features.
*/ */
public static void setStatsImplementation( public static void setStatsEnabled(
AbstractServerImplBuilder<?> builder, CensusStatsModule censusStats) { AbstractServerImplBuilder<?> builder,
builder.overrideCensusStatsModule(censusStats); boolean statsEnabled) {
builder.setStatsEnabled(statsEnabled);
} }
private TestingAccessor() { private TestingAccessor() {