diff --git a/core/src/main/java/io/grpc/BinaryLog.java b/core/src/main/java/io/grpc/BinaryLog.java index ec1a2ade3c..5c2d4ab2f3 100644 --- a/core/src/main/java/io/grpc/BinaryLog.java +++ b/core/src/main/java/io/grpc/BinaryLog.java @@ -30,9 +30,6 @@ public abstract class BinaryLog implements Closeable { public abstract Channel wrapChannel(Channel channel); - public static final CallOptions.Key CLIENT_CALL_ID_CALLOPTION_KEY - = CallOptions.Key.create("binarylog-calloptions-key"); - /** * A CallId is two byte[] arrays both of size 8 that uniquely identifies the RPC. Users are * free to use the byte arrays however they see fit. diff --git a/core/src/main/java/io/grpc/internal/CensusTracingModule.java b/core/src/main/java/io/grpc/internal/CensusTracingModule.java index 3a0bb66bc6..1269f3fdf4 100644 --- a/core/src/main/java/io/grpc/internal/CensusTracingModule.java +++ b/core/src/main/java/io/grpc/internal/CensusTracingModule.java @@ -20,8 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static io.opencensus.trace.unsafe.ContextUtils.CONTEXT_SPAN_KEY; import com.google.common.annotations.VisibleForTesting; -import io.grpc.BinaryLog; -import io.grpc.BinaryLog.CallId; import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; @@ -43,7 +41,6 @@ import io.opencensus.trace.SpanContext; import io.opencensus.trace.Status; import io.opencensus.trace.Tracer; import io.opencensus.trace.propagation.BinaryFormat; -import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.logging.Level; import java.util.logging.Logger; @@ -388,13 +385,7 @@ final class CensusTracingModule { ClientCall call = next.newCall( method, - callOptions.withStreamTracerFactory(tracerFactory) - .withOption( - BinaryLog.CLIENT_CALL_ID_CALLOPTION_KEY, - new CallId( - 0, - ByteBuffer.wrap( - tracerFactory.span.getContext().getSpanId().getBytes()).getLong()))); + callOptions.withStreamTracerFactory(tracerFactory)); return new SimpleForwardingClientCall(call) { @Override public void start(Listener responseListener, Metadata headers) { diff --git a/core/src/test/java/io/grpc/internal/CensusModulesTest.java b/core/src/test/java/io/grpc/internal/CensusModulesTest.java index 5abc65a453..29c59a0d1c 100644 --- a/core/src/test/java/io/grpc/internal/CensusModulesTest.java +++ b/core/src/test/java/io/grpc/internal/CensusModulesTest.java @@ -33,7 +33,6 @@ import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isNull; import static org.mockito.Matchers.same; import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; @@ -43,10 +42,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -import com.google.common.util.concurrent.SettableFuture; import io.grpc.Attributes; -import io.grpc.BinaryLog; -import io.grpc.BinaryLog.CallId; import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; @@ -67,7 +63,6 @@ import io.grpc.internal.testing.StatsTestUtils.FakeTagContextBinarySerializer; import io.grpc.internal.testing.StatsTestUtils.FakeTagger; import io.grpc.internal.testing.StatsTestUtils.MockableSpan; import io.grpc.testing.GrpcServerRule; -import io.grpc.testing.TestMethodDescriptors; import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants; import io.opencensus.tags.TagContext; import io.opencensus.tags.TagValue; @@ -83,7 +78,6 @@ import io.opencensus.trace.propagation.BinaryFormat; import io.opencensus.trace.propagation.SpanContextParseException; import io.opencensus.trace.unsafe.ContextUtils; import java.io.InputStream; -import java.nio.ByteBuffer; import java.util.HashSet; import java.util.List; import java.util.Random; @@ -1000,57 +994,6 @@ public class CensusModulesTest { "Recv.io.grpc.Bar", CensusTracingModule.generateTraceSpanName(true, "io.grpc/Bar")); } - /** - * Tests integration with binary logging. - */ - @Test - public void callIdFromSpan() { - MockableSpan mockableSpan = MockableSpan.generateRandomSpan(new Random(0)); - CallId callId = new CallId( - 0, - ByteBuffer.wrap( - mockableSpan.getContext().getSpanId().getBytes()).getLong()); - assertThat(callId.hi).isEqualTo(0); - assertThat(callId.lo) - .isEqualTo(ByteBuffer.wrap(mockableSpan.getContext().getSpanId().getBytes()).getLong()); - } - - /** - * Tests integration with binary logging. - */ - @Test - public void censusTracerSetsCallId() throws Exception { - Tracer tracer = mock(Tracer.class); - SpanBuilder builder = mock(SpanBuilder.class); - when(tracer.spanBuilderWithExplicitParent(any(String.class), any(Span.class))) - .thenReturn(builder); - when(builder.setRecordEvents(any(Boolean.class))).thenReturn(builder); - MockableSpan mockableSpan = MockableSpan.generateRandomSpan(new Random(0)); - when(builder.startSpan()).thenReturn(mockableSpan); - - final SettableFuture options = SettableFuture.create(); - Channel c = new Channel() { - @Override - public ClientCall newCall( - MethodDescriptor methodDescriptor, CallOptions callOptions) { - options.set(callOptions); - return null; - } - - @Override - public String authority() { - return null; - } - }; - new CensusTracingModule(tracer, mock(BinaryFormat.class)) - .getClientInterceptor() - .interceptCall(TestMethodDescriptors.voidMethod(), CallOptions.DEFAULT, c); - CallId callId = options.get().getOption(BinaryLog.CLIENT_CALL_ID_CALLOPTION_KEY); - assertThat(callId.hi).isEqualTo(0); - assertThat(callId.lo) - .isEqualTo(ByteBuffer.wrap(mockableSpan.getContext().getSpanId().getBytes()).getLong()); - } - private static void assertNoServerContent(StatsTestUtils.MetricsRecord record) { assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_ERROR_COUNT)); assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT)); diff --git a/services/src/main/java/io/grpc/services/BinaryLogs.java b/services/src/main/java/io/grpc/services/BinaryLogs.java index afe3f24622..de7f79116f 100644 --- a/services/src/main/java/io/grpc/services/BinaryLogs.java +++ b/services/src/main/java/io/grpc/services/BinaryLogs.java @@ -38,19 +38,5 @@ public final class BinaryLogs { return new BinaryLogProviderImpl(sink); } - /** - * Same as {@link #createBinaryLog()} except the call IDs are derived from census. - */ - public static BinaryLog createCensusBinaryLog() throws IOException { - return new CensusBinaryLogProvider(); - } - - /** - * Same as {@link #createBinaryLog(BinaryLogSink)} except the call IDs are derived from census. - */ - public static BinaryLog createCensusBinaryLog(BinaryLogSink sink) throws IOException { - return new CensusBinaryLogProvider(sink); - } - private BinaryLogs() {} } diff --git a/services/src/main/java/io/grpc/services/CensusBinaryLogProvider.java b/services/src/main/java/io/grpc/services/CensusBinaryLogProvider.java deleted file mode 100644 index d6fb7fae8a..0000000000 --- a/services/src/main/java/io/grpc/services/CensusBinaryLogProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2018 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.services; - -import io.grpc.CallOptions; -import io.opencensus.trace.Span; -import io.opencensus.trace.Tracing; -import java.io.IOException; -import java.nio.ByteBuffer; - -final class CensusBinaryLogProvider extends BinaryLogProviderImpl { - - public CensusBinaryLogProvider() throws IOException { - super(); - } - - public CensusBinaryLogProvider(BinaryLogSink sink) throws IOException { - super(sink); - } - - CensusBinaryLogProvider(BinaryLogSink sink, String configStr) throws IOException { - super(sink, configStr); - } - - @Override - protected CallId getServerCallId() { - Span currentSpan = Tracing.getTracer().getCurrentSpan(); - return new CallId( - 0, - ByteBuffer.wrap( - currentSpan.getContext().getSpanId().getBytes()).getLong()); - } - - @Override - protected CallId getClientCallId(CallOptions options) { - return options.getOption(BinaryLogProvider.CLIENT_CALL_ID_CALLOPTION_KEY); - } -} diff --git a/services/src/test/java/io/grpc/services/BinlogHelperTest.java b/services/src/test/java/io/grpc/services/BinlogHelperTest.java index 148eb171c2..5237a0bb98 100644 --- a/services/src/test/java/io/grpc/services/BinlogHelperTest.java +++ b/services/src/test/java/io/grpc/services/BinlogHelperTest.java @@ -905,9 +905,7 @@ public final class BinlogHelperTest { .getClientInterceptor(CALL_ID) .interceptCall( method, - CallOptions.DEFAULT.withOption( - BinaryLogProvider.CLIENT_CALL_ID_CALLOPTION_KEY, CALL_ID) - .withDeadlineAfter(1, TimeUnit.SECONDS), + CallOptions.DEFAULT.withDeadlineAfter(1, TimeUnit.SECONDS), new Channel() { @Override public ClientCall newCall( diff --git a/services/src/test/java/io/grpc/services/CensusBinaryLogProviderTest.java b/services/src/test/java/io/grpc/services/CensusBinaryLogProviderTest.java deleted file mode 100644 index 8fabbd1f92..0000000000 --- a/services/src/test/java/io/grpc/services/CensusBinaryLogProviderTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2018 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.services; - -import static com.google.common.truth.Truth.assertThat; -import static io.opencensus.trace.unsafe.ContextUtils.CONTEXT_SPAN_KEY; - -import io.grpc.BinaryLog.CallId; -import io.grpc.CallOptions; -import io.grpc.Context; -import io.grpc.internal.testing.StatsTestUtils.MockableSpan; -import java.nio.ByteBuffer; -import java.util.Random; -import java.util.concurrent.Callable; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * Tests for {@link CensusBinaryLogProvider}. - */ -@RunWith(JUnit4.class) -public class CensusBinaryLogProviderTest { - @Mock - private BinaryLogSink sink; - - public CensusBinaryLogProviderTest() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void serverCallIdFromCensus() throws Exception { - final MockableSpan mockableSpan = MockableSpan.generateRandomSpan(new Random(0)); - Context context = Context.current().withValue(CONTEXT_SPAN_KEY, mockableSpan); - context.call(new Callable() { - @Override - public Void call() throws Exception { - CallId callId = new CensusBinaryLogProvider(sink, "*").getServerCallId(); - assertThat(callId.hi).isEqualTo(0); - assertThat(ByteBuffer.wrap(mockableSpan.getContext().getSpanId().getBytes()).getLong()) - .isEqualTo(callId.lo); - return null; - } - }); - } - - @Test - public void clientCallId() throws Exception { - CallId expected = new CallId(1234, 5677); - CallId actual = new CensusBinaryLogProvider(sink, "*") - .getClientCallId( - CallOptions.DEFAULT.withOption( - BinaryLogProvider.CLIENT_CALL_ID_CALLOPTION_KEY, - expected)); - assertThat(actual).isEqualTo(expected); - } -}