diff options
author | Kun Zhang <zhangkun83@users.noreply.github.com> | 2017-11-01 16:46:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-01 16:46:05 -0700 |
commit | d87ef74082220bdbdcb98b94cd9a3dac9482d813 (patch) | |
tree | c1e5998a130e3ceda67ff4a2aff4f70c474e8b43 /testing-proto | |
parent | 253a01461b4999b6aeb27e54d88ef0bba04239b1 (diff) | |
download | grpc-grpc-java-d87ef74082220bdbdcb98b94cd9a3dac9482d813.tar.gz |
core: set sampled for local span per MethodDescriptor. (#3627)
This moves away from the global String-based Span name registry which
is not as flexible as we desire.
Also renamed the option name to be more accurate. This is not
API-breaking because the origianl addition to MethodDescriptor and
code-gen didn't make it into the 1.7.0 release.
Diffstat (limited to 'testing-proto')
3 files changed, 8 insertions, 41 deletions
diff --git a/testing-proto/build.gradle b/testing-proto/build.gradle index bda787f93..84f651af4 100644 --- a/testing-proto/build.gradle +++ b/testing-proto/build.gradle @@ -13,9 +13,7 @@ buildscript { dependencies { compile project(':grpc-protobuf'), project(':grpc-stub') - testCompile libraries.opencensus_api, - libraries.truth - testRuntime libraries.opencensus_impl + testCompile libraries.truth } configureProtoCompilation() diff --git a/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java b/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java index 64a600e26..1bd2fe89c 100644 --- a/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java +++ b/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java @@ -50,7 +50,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "UnaryRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -82,7 +82,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "ClientStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -114,7 +114,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "ServerStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -146,7 +146,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "BidiStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java b/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java index a6381cccb..3dce5d975 100644 --- a/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java +++ b/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java @@ -16,19 +16,14 @@ package io.grpc.testing.protobuf; -import static com.google.common.truth.Truth.assertThat; import static io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING; import static io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING; import static io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING; import static io.grpc.MethodDescriptor.MethodType.UNARY; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import io.grpc.MethodDescriptor; -import io.opencensus.trace.Tracing; -import io.opencensus.trace.export.SampledSpanStore; -import java.util.ArrayList; -import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -59,33 +54,7 @@ public class SimpleServiceTest { } @Test - public void registerSampledMethodsForTracing() throws Exception { - // Make sure SimpleServiceGrpc and CensusTracingModule classes are loaded. - assertNotNull(Class.forName(SimpleServiceGrpc.class.getName())); - assertNotNull(Class.forName("io.grpc.internal.CensusTracingModule")); - - String[] methodNames = new String[] { - "grpc.testing.SimpleService/UnaryRpc", - "grpc.testing.SimpleService/ClientStreamingRpc", - "grpc.testing.SimpleService/ServerStreamingRpc", - "grpc.testing.SimpleService/BidiStreamingRpc"}; - - ArrayList<String> expectedSpans = new ArrayList<String>(); - for (String methodName : methodNames) { - expectedSpans.add(generateTraceSpanName(false, methodName)); - expectedSpans.add(generateTraceSpanName(true, methodName)); - } - - SampledSpanStore sampledStore = Tracing.getExportComponent().getSampledSpanStore(); - Set<String> registeredSpans = sampledStore.getRegisteredSpanNamesForCollection(); - assertThat(registeredSpans).containsAllIn(expectedSpans); - } - - /** - * Copy of {@link io.grpc.internal.CensusTracingModule#generateTraceSpanName} to break dependency. - */ - private static String generateTraceSpanName(boolean isServer, String fullMethodName) { - String prefix = isServer ? "Recv" : "Sent"; - return prefix + "." + fullMethodName.replace('/', '.'); + public void generatedMethodsAreSampledToLocalTracing() throws Exception { + assertTrue(SimpleServiceGrpc.getUnaryRpcMethod().isSampledToLocalTracing()); } } |