io.grpc.ServerStreamTracer Java Examples

The following examples show how to use io.grpc.ServerStreamTracer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalInProcess.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new InProcessTransport.
 *
 * <p>When started, the transport will be registered with the given
 * {@link ServerListener}.
 */
@Internal
public static ConnectionClientTransport createInProcessTransport(
    String name,
    int maxInboundMetadataSize,
    String authority,
    String userAgent,
    Attributes eagAttrs,
    ObjectPool<ScheduledExecutorService> serverSchedulerPool,
    List<ServerStreamTracer.Factory> serverStreamTracerFactories,
    ServerListener serverListener) {
  return new InProcessTransport(
      name,
      maxInboundMetadataSize,
      authority,
      userAgent,
      eagAttrs,
      serverSchedulerPool,
      serverStreamTracerFactories,
      serverListener);
}
 
Example #2
Source File: AbstractServerImplBuilder.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
final List<ServerStreamTracer.Factory> getTracerFactories() {
  ArrayList<ServerStreamTracer.Factory> tracerFactories =
      new ArrayList<ServerStreamTracer.Factory>();
  if (statsEnabled) {
    CensusStatsModule censusStats = this.censusStatsOverride;
    if (censusStats == null) {
      censusStats = new CensusStatsModule(GrpcUtil.STOPWATCH_SUPPLIER, true);
    }
    tracerFactories.add(
        censusStats.getServerTracerFactory(recordStartedRpcs, recordFinishedRpcs));
  }
  if (tracingEnabled) {
    CensusTracingModule censusTracing =
        new CensusTracingModule(Tracing.getTracer(),
            Tracing.getPropagationComponent().getBinaryFormat());
    tracerFactories.add(censusTracing.getServerTracerFactory());
  }
  tracerFactories.addAll(streamTracerFactories);
  return tracerFactories;
}
 
Example #3
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void serverTracingSampledToLocalSpanStore() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata());

  serverStreamTracer.filterContext(Context.ROOT);

  serverStreamTracer.serverCallStarted(
      new CallInfo<>(sampledMethod, Attributes.EMPTY, null));

  serverStreamTracer.streamClosed(Status.CANCELLED);

  verify(spyServerSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.CANCELLED)
          .setSampleToLocalSpanStore(true)
          .build());
}
 
Example #4
Source File: NettyServerBuilder.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Override
@CheckReturnValue
protected NettyServer buildTransportServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  ProtocolNegotiator negotiator = protocolNegotiator;
  if (negotiator == null) {
    negotiator = sslContext != null ? ProtocolNegotiators.serverTls(sslContext) :
            ProtocolNegotiators.serverPlaintext();
  }

  return new NettyServer(
      address, channelType, channelOptions, bossEventLoopGroup, workerEventLoopGroup,
      negotiator, streamTracerFactories, transportTracerFactory,
      maxConcurrentCallsPerConnection, flowControlWindow,
      maxMessageSize, maxHeaderListSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos,
      maxConnectionIdleInNanos,
      maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos,
      permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, channelz);
}
 
Example #5
Source File: NettyServerTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void getPort_notStarted() throws Exception {
  InetSocketAddress addr = new InetSocketAddress(0);
  NettyServer ns = new NettyServer(
      addr,
      NioServerSocketChannel.class,
      new HashMap<ChannelOption<?>, Object>(),
      null, // no boss group
      null, // no event group
      new ProtocolNegotiators.PlaintextNegotiator(),
      Collections.<ServerStreamTracer.Factory>emptyList(),
      TransportTracer.getDefaultFactory(),
      1, // ignore
      1, // ignore
      1, // ignore
      1, // ignore
      1, // ignore
      1, 1, // ignore
      1, 1, // ignore
      true, 0, // ignore
      channelz);

  assertThat(ns.getPort()).isEqualTo(-1);
}
 
Example #6
Source File: CensusModulesTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void serverTracingSampledToLocalSpanStore() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata());

  serverStreamTracer.filterContext(Context.ROOT);

  serverStreamTracer.serverCallStarted(
      new ServerCallInfoImpl<String, String>(sampledMethod, Attributes.EMPTY, null));

  serverStreamTracer.streamClosed(Status.CANCELLED);

  verify(spyServerSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.CANCELLED)
          .setSampleToLocalSpanStore(true)
          .build());
}
 
Example #7
Source File: CensusModulesTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void traceHeadersPropagateSpanContext() throws Exception {
  CensusTracingModule.ClientCallTracer callTracer =
      censusTracing.newClientCallTracer(fakeClientParentSpan, method);
  Metadata headers = new Metadata();
  callTracer.newClientStreamTracer(CallOptions.DEFAULT, headers);

  verify(mockTracingPropagationHandler).toByteArray(same(fakeClientSpanContext));
  verifyNoMoreInteractions(mockTracingPropagationHandler);
  verify(tracer).spanBuilderWithExplicitParent(
      eq("Sent.package1.service2.method3"), same(fakeClientParentSpan));
  verify(spyClientSpanBuilder).setRecordEvents(eq(true));
  verifyNoMoreInteractions(tracer);
  assertTrue(headers.containsKey(censusTracing.tracingHeader));

  ServerStreamTracer serverTracer =
      censusTracing.getServerTracerFactory().newServerStreamTracer(
          method.getFullMethodName(), headers);
  verify(mockTracingPropagationHandler).fromByteArray(same(binarySpanContext));
  verify(tracer).spanBuilderWithRemoteParent(
      eq("Recv.package1.service2.method3"), same(spyClientSpan.getContext()));
  verify(spyServerSpanBuilder).setRecordEvents(eq(true));

  Context filteredContext = serverTracer.filterContext(Context.ROOT);
  assertSame(spyServerSpan, ContextUtils.CONTEXT_SPAN_KEY.get(filteredContext));
}
 
Example #8
Source File: InProcessTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
InProcessTransport(
    String name, int maxInboundMetadataSize, String authority, String userAgent,
    Attributes eagAttrs, ObjectPool<ScheduledExecutorService> serverSchedulerPool,
    List<ServerStreamTracer.Factory> serverStreamTracerFactories,
    ServerListener serverListener) {
  this(name, maxInboundMetadataSize, authority, userAgent, eagAttrs,
      Optional.of(serverListener), false);
  this.serverMaxInboundMetadataSize = maxInboundMetadataSize;
  this.serverSchedulerPool = serverSchedulerPool;
  this.serverStreamTracerFactories = serverStreamTracerFactories;
}
 
Example #9
Source File: NettyServerTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
NettyServerTransport(
    Channel channel,
    ChannelPromise channelUnused,
    ProtocolNegotiator protocolNegotiator,
    List<? extends ServerStreamTracer.Factory> streamTracerFactories,
    TransportTracer transportTracer,
    int maxStreams,
    boolean autoFlowControl,
    int flowControlWindow,
    int maxMessageSize,
    int maxHeaderListSize,
    long keepAliveTimeInNanos,
    long keepAliveTimeoutInNanos,
    long maxConnectionIdleInNanos,
    long maxConnectionAgeInNanos,
    long maxConnectionAgeGraceInNanos,
    boolean permitKeepAliveWithoutCalls,
    long permitKeepAliveTimeInNanos) {
  this.channel = Preconditions.checkNotNull(channel, "channel");
  this.channelUnused = channelUnused;
  this.protocolNegotiator = Preconditions.checkNotNull(protocolNegotiator, "protocolNegotiator");
  this.streamTracerFactories =
      Preconditions.checkNotNull(streamTracerFactories, "streamTracerFactories");
  this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer");
  this.maxStreams = maxStreams;
  this.autoFlowControl = autoFlowControl;
  this.flowControlWindow = flowControlWindow;
  this.maxMessageSize = maxMessageSize;
  this.maxHeaderListSize = maxHeaderListSize;
  this.keepAliveTimeInNanos = keepAliveTimeInNanos;
  this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos;
  this.maxConnectionIdleInNanos = maxConnectionIdleInNanos;
  this.maxConnectionAgeInNanos = maxConnectionAgeInNanos;
  this.maxConnectionAgeGraceInNanos = maxConnectionAgeGraceInNanos;
  this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls;
  this.permitKeepAliveTimeInNanos = permitKeepAliveTimeInNanos;
  SocketAddress remote = channel.remoteAddress();
  this.logId = InternalLogId.allocate(getClass(), remote != null ? remote.toString() : null);
}
 
Example #10
Source File: InProcessServer.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
InProcessServer(
    InProcessServerBuilder builder,
    List<? extends ServerStreamTracer.Factory> streamTracerFactories) {
  this.name = builder.name;
  this.schedulerPool = builder.schedulerPool;
  this.maxInboundMetadataSize = builder.maxInboundMetadataSize;
  this.streamTracerFactories =
      Collections.unmodifiableList(checkNotNull(streamTracerFactories, "streamTracerFactories"));
}
 
Example #11
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void serverTracingNotSampledToLocalSpanStore_whenServerCallNotCreated() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata());

  serverStreamTracer.streamClosed(Status.CANCELLED);

  verify(spyServerSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.CANCELLED)
          .setSampleToLocalSpanStore(false)
          .build());
}
 
Example #12
Source File: AbstractServerImplBuilderTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_disableBoth() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  builder.setTracingEnabled(false);
  builder.setStatsEnabled(false);
  List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();
  assertThat(factories).containsExactly(DUMMY_USER_TRACER);
}
 
Example #13
Source File: InProcessTransportTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  InProcessServerBuilder builder = InProcessServerBuilder
      .forName(TRANSPORT_NAME)
      .maxInboundMetadataSize(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE);
  return ImmutableList.of(new InProcessServer(builder, streamTracerFactories));
}
 
Example #14
Source File: CensusTracingModule.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
@Override
public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) {
  SpanContext remoteSpan = headers.get(tracingHeader);
  if (remoteSpan == SpanContext.INVALID) {
    remoteSpan = null;
  }
  return new ServerTracer(fullMethodName, remoteSpan);
}
 
Example #15
Source File: NettyTransportTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  return NettyServerBuilder
      .forAddress(new InetSocketAddress("localhost", 0))
      .flowControlWindow(65 * 1024)
      .setTransportTracerFactory(fakeClockTransportTracer)
      .buildTransportServers(streamTracerFactories);
}
 
Example #16
Source File: NettyServerBuilder.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
@CheckReturnValue
protected List<NettyServer> buildTransportServers(
    List<? extends ServerStreamTracer.Factory> streamTracerFactories) {
  assertEventLoopsAndChannelType();

  ProtocolNegotiator negotiator = protocolNegotiator;
  if (negotiator == null) {
    negotiator = sslContext != null
        ? ProtocolNegotiators.serverTls(sslContext, this.getExecutorPool())
        : ProtocolNegotiators.serverPlaintext();
  }

  List<NettyServer> transportServers = new ArrayList<>(listenAddresses.size());
  for (SocketAddress listenAddress : listenAddresses) {
    NettyServer transportServer = new NettyServer(
        listenAddress, channelFactory, channelOptions, childChannelOptions,
        bossEventLoopGroupPool, workerEventLoopGroupPool, forceHeapBuffer, negotiator,
        streamTracerFactories, getTransportTracerFactory(), maxConcurrentCallsPerConnection,
        autoFlowControl, flowControlWindow, maxMessageSize, maxHeaderListSize,
        keepAliveTimeInNanos, keepAliveTimeoutInNanos,
        maxConnectionIdleInNanos, maxConnectionAgeInNanos,
        maxConnectionAgeGraceInNanos, permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos,
        getChannelz());
    transportServers.add(transportServer);
  }
  return Collections.unmodifiableList(transportServers);
}
 
Example #17
Source File: InProcessServerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getPort_notStarted() throws Exception {
  InProcessServer s =
      new InProcessServer(builder, Collections.<ServerStreamTracer.Factory>emptyList());

  Truth.assertThat(s.getListenSocketAddress()).isEqualTo(new InProcessSocketAddress("name"));
}
 
Example #18
Source File: NettyServerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getPort_notStarted() {
  InetSocketAddress addr = new InetSocketAddress(0);
  NettyServer ns = new NettyServer(
      addr,
      new ReflectiveChannelFactory<>(NioServerSocketChannel.class),
      new HashMap<ChannelOption<?>, Object>(),
      new HashMap<ChannelOption<?>, Object>(),
      new FixedObjectPool<>(eventLoop),
      new FixedObjectPool<>(eventLoop),
      false,
      ProtocolNegotiators.plaintext(),
      Collections.<ServerStreamTracer.Factory>emptyList(),
      TransportTracer.getDefaultFactory(),
      1, // ignore
      false, // ignore
      1, // ignore
      1, // ignore
      1, // ignore
      1, // ignore
      1, 1, // ignore
      1, 1, // ignore
      true, 0, // ignore
      channelz);

  assertThat(ns.getListenSocketAddress()).isEqualTo(addr);
}
 
Example #19
Source File: InProcessServerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getPort_notStarted() throws Exception {
  InProcessServer s =
      new InProcessServer(builder, Collections.<ServerStreamTracer.Factory>emptyList());

  Truth.assertThat(s.getPort()).isEqualTo(-1);
}
 
Example #20
Source File: AbstractServerImplBuilderTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_default() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);

  List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();

  assertEquals(3, factories.size());
  assertThat(factories.get(0).getClass().getName())
      .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);
}
 
Example #21
Source File: AbstractInteropTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) {
  ServerStreamTracerInfo.InteropServerStreamTracer tracer
      = new ServerStreamTracerInfo.InteropServerStreamTracer();
  serverStreamTracers.add(new ServerStreamTracerInfo(fullMethodName, tracer));
  return tracer;
}
 
Example #22
Source File: AccessProtectedHack.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
public static List<? extends InternalServer> serverBuilderBuildTransportServer(
    AbstractServerImplBuilder<?> builder,
    List<ServerStreamTracer.Factory> streamTracerFactories,
    TransportTracer.Factory transportTracerFactory) {
  builder.transportTracerFactory = transportTracerFactory;
  return builder.buildTransportServers(streamTracerFactories);
}
 
Example #23
Source File: OkHttpTransportTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected List<? extends InternalServer> newServer(
    List<ServerStreamTracer.Factory> streamTracerFactories) {
  return AccessProtectedHack.serverBuilderBuildTransportServer(
      NettyServerBuilder
          .forPort(0)
          .flowControlWindow(65 * 1024),
      streamTracerFactories,
      fakeClockTransportTracer);
}
 
Example #24
Source File: StatsTraceContext.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * See {@link ServerStreamTracer#filterContext}.  For server-side only.
 *
 * <p>Called from {@link io.grpc.internal.ServerImpl}.
 */
public <ReqT, RespT> Context serverFilterContext(Context context) {
  Context ctx = checkNotNull(context, "context");
  for (StreamTracer tracer : tracers) {
    ctx = ((ServerStreamTracer) tracer).filterContext(ctx);
    checkNotNull(ctx, "%s returns null context", tracer);
  }
  return ctx;
}
 
Example #25
Source File: AbstractServerImplBuilderTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_disableStats() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  builder.setStatsEnabled(false);

  List<? extends ServerStreamTracer.Factory> factories = builder.getTracerFactories();

  assertEquals(2, factories.size());
  assertThat(factories.get(0).getClass().getName())
      .isEqualTo("io.grpc.census.CensusTracingModule$ServerTracerFactory");
  assertThat(factories.get(1)).isSameInstanceAs(DUMMY_USER_TRACER);
}
 
Example #26
Source File: AbstractServerImplBuilderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_disableTracing() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  builder.setTracingEnabled(false);
  List<ServerStreamTracer.Factory> factories = builder.getTracerFactories();
  assertEquals(2, factories.size());
  assertThat(factories.get(0)).isInstanceOf(CensusStatsModule.ServerTracerFactory.class);
  assertThat(factories.get(1)).isSameAs(DUMMY_USER_TRACER);
}
 
Example #27
Source File: AbstractServerImplBuilderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_disableStats() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  builder.setStatsEnabled(false);
  List<ServerStreamTracer.Factory> factories = builder.getTracerFactories();
  assertEquals(2, factories.size());
  assertThat(factories.get(0)).isInstanceOf(CensusTracingModule.ServerTracerFactory.class);
  assertThat(factories.get(1)).isSameAs(DUMMY_USER_TRACER);
}
 
Example #28
Source File: AbstractServerImplBuilderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTracerFactories_default() {
  builder.addStreamTracerFactory(DUMMY_USER_TRACER);
  List<ServerStreamTracer.Factory> factories = builder.getTracerFactories();
  assertEquals(3, factories.size());
  assertThat(factories.get(0)).isInstanceOf(CensusStatsModule.ServerTracerFactory.class);
  assertThat(factories.get(1)).isInstanceOf(CensusTracingModule.ServerTracerFactory.class);
  assertThat(factories.get(2)).isSameAs(DUMMY_USER_TRACER);
}
 
Example #29
Source File: StatsTraceContext.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Factory method for the server-side.
 */
public static StatsTraceContext newServerContext(
    List<? extends ServerStreamTracer.Factory> factories,
    String fullMethodName,
    Metadata headers) {
  if (factories.isEmpty()) {
    return NOOP;
  }
  StreamTracer[] tracers = new StreamTracer[factories.size()];
  for (int i = 0; i < tracers.length; i++) {
    tracers[i] = factories.get(i).newServerStreamTracer(fullMethodName, headers);
  }
  return new StatsTraceContext(tracers);
}
 
Example #30
Source File: OkHttpTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected InternalServer newServer(
    InternalServer server, List<ServerStreamTracer.Factory> streamTracerFactories) {
  int port = server.getPort();
  return AccessProtectedHack.serverBuilderBuildTransportServer(
      NettyServerBuilder
          .forPort(port)
          .flowControlWindow(65 * 1024),
      streamTracerFactories,
      fakeClockTransportTracer);
}