mirror of https://github.com/grpc/grpc-java.git
core, services: remove census from binary logs (#4845)
The exact census span behavior wrt gRPC is not yet defined, so let's punt on tight integration. It may be fine to log grpc-trace-bin on server side because it is a key visible to the application.
This commit is contained in:
parent
e1c6cadb50
commit
95fd47d747
|
|
@ -30,9 +30,6 @@ public abstract class BinaryLog implements Closeable {
|
||||||
|
|
||||||
public abstract Channel wrapChannel(Channel channel);
|
public abstract Channel wrapChannel(Channel channel);
|
||||||
|
|
||||||
public static final CallOptions.Key<CallId> 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
|
* 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.
|
* free to use the byte arrays however they see fit.
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static io.opencensus.trace.unsafe.ContextUtils.CONTEXT_SPAN_KEY;
|
import static io.opencensus.trace.unsafe.ContextUtils.CONTEXT_SPAN_KEY;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.grpc.BinaryLog;
|
|
||||||
import io.grpc.BinaryLog.CallId;
|
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ClientCall;
|
import io.grpc.ClientCall;
|
||||||
|
|
@ -43,7 +41,6 @@ import io.opencensus.trace.SpanContext;
|
||||||
import io.opencensus.trace.Status;
|
import io.opencensus.trace.Status;
|
||||||
import io.opencensus.trace.Tracer;
|
import io.opencensus.trace.Tracer;
|
||||||
import io.opencensus.trace.propagation.BinaryFormat;
|
import io.opencensus.trace.propagation.BinaryFormat;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@ -388,13 +385,7 @@ final class CensusTracingModule {
|
||||||
ClientCall<ReqT, RespT> call =
|
ClientCall<ReqT, RespT> call =
|
||||||
next.newCall(
|
next.newCall(
|
||||||
method,
|
method,
|
||||||
callOptions.withStreamTracerFactory(tracerFactory)
|
callOptions.withStreamTracerFactory(tracerFactory));
|
||||||
.withOption(
|
|
||||||
BinaryLog.CLIENT_CALL_ID_CALLOPTION_KEY,
|
|
||||||
new CallId(
|
|
||||||
0,
|
|
||||||
ByteBuffer.wrap(
|
|
||||||
tracerFactory.span.getContext().getSpanId().getBytes()).getLong())));
|
|
||||||
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
|
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
|
||||||
@Override
|
@Override
|
||||||
public void start(Listener<RespT> responseListener, Metadata headers) {
|
public void start(Listener<RespT> responseListener, Metadata headers) {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isNull;
|
import static org.mockito.Matchers.isNull;
|
||||||
import static org.mockito.Matchers.same;
|
import static org.mockito.Matchers.same;
|
||||||
import static org.mockito.Mockito.inOrder;
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.spy;
|
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.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
|
||||||
import io.grpc.Attributes;
|
import io.grpc.Attributes;
|
||||||
import io.grpc.BinaryLog;
|
|
||||||
import io.grpc.BinaryLog.CallId;
|
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ClientCall;
|
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.FakeTagger;
|
||||||
import io.grpc.internal.testing.StatsTestUtils.MockableSpan;
|
import io.grpc.internal.testing.StatsTestUtils.MockableSpan;
|
||||||
import io.grpc.testing.GrpcServerRule;
|
import io.grpc.testing.GrpcServerRule;
|
||||||
import io.grpc.testing.TestMethodDescriptors;
|
|
||||||
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;
|
import io.opencensus.contrib.grpc.metrics.RpcMeasureConstants;
|
||||||
import io.opencensus.tags.TagContext;
|
import io.opencensus.tags.TagContext;
|
||||||
import io.opencensus.tags.TagValue;
|
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.propagation.SpanContextParseException;
|
||||||
import io.opencensus.trace.unsafe.ContextUtils;
|
import io.opencensus.trace.unsafe.ContextUtils;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
@ -1000,57 +994,6 @@ public class CensusModulesTest {
|
||||||
"Recv.io.grpc.Bar", CensusTracingModule.generateTraceSpanName(true, "io.grpc/Bar"));
|
"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<CallOptions> options = SettableFuture.create();
|
|
||||||
Channel c = new Channel() {
|
|
||||||
@Override
|
|
||||||
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
|
|
||||||
MethodDescriptor<RequestT, ResponseT> 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) {
|
private static void assertNoServerContent(StatsTestUtils.MetricsRecord record) {
|
||||||
assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_ERROR_COUNT));
|
assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_ERROR_COUNT));
|
||||||
assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT));
|
assertNull(record.getMetric(RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT));
|
||||||
|
|
|
||||||
|
|
@ -38,19 +38,5 @@ public final class BinaryLogs {
|
||||||
return new BinaryLogProviderImpl(sink);
|
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() {}
|
private BinaryLogs() {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -905,9 +905,7 @@ public final class BinlogHelperTest {
|
||||||
.getClientInterceptor(CALL_ID)
|
.getClientInterceptor(CALL_ID)
|
||||||
.interceptCall(
|
.interceptCall(
|
||||||
method,
|
method,
|
||||||
CallOptions.DEFAULT.withOption(
|
CallOptions.DEFAULT.withDeadlineAfter(1, TimeUnit.SECONDS),
|
||||||
BinaryLogProvider.CLIENT_CALL_ID_CALLOPTION_KEY, CALL_ID)
|
|
||||||
.withDeadlineAfter(1, TimeUnit.SECONDS),
|
|
||||||
new Channel() {
|
new Channel() {
|
||||||
@Override
|
@Override
|
||||||
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
|
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
|
||||||
|
|
|
||||||
|
|
@ -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<Void>() {
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue