Search in sources :

Example 6 with ChannelFactoryBuilder

use of com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder in project pinpoint by naver.

the class ChannelFactoryTest method build.

@Test
public void build() throws InterruptedException {
    HeaderFactory headerFactory = new AgentHeaderFactory("agentId", "agentName", "appName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis());
    CountRecordClientInterceptor countRecordClientInterceptor = new CountRecordClientInterceptor();
    ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder(this.getClass().getSimpleName());
    channelFactoryBuilder.setHeaderFactory(headerFactory);
    channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
    channelFactoryBuilder.addClientInterceptor(countRecordClientInterceptor);
    channelFactoryBuilder.setClientOption(new ClientOption());
    ChannelFactory channelFactory = channelFactoryBuilder.build();
    ManagedChannel managedChannel = channelFactory.build("127.0.0.1", PORT);
    managedChannel.getState(false);
    SpanGrpc.SpanStub spanStub = SpanGrpc.newStub(managedChannel);
    final QueueingStreamObserver<Empty> responseObserver = new QueueingStreamObserver<>();
    logger.debug("sendSpan");
    StreamObserver<PSpanMessage> sendSpan = spanStub.sendSpan(responseObserver);
    PSpan pSpan = newSpan();
    PSpanMessage message = PSpanMessage.newBuilder().setSpan(pSpan).build();
    logger.debug("client-onNext");
    sendSpan.onNext(message);
    logger.debug("wait for response");
    Empty value = responseObserver.getValue();
    logger.debug("response:{}", value);
    logger.debug("client-onCompleted");
    sendSpan.onCompleted();
    Assert.assertEquals(1, countRecordClientInterceptor.getExecutedInterceptCallCount());
    logger.debug("state:{}", managedChannel.getState(true));
    spanService.awaitOnCompleted();
    logger.debug("managedChannel shutdown");
    managedChannel.shutdown();
    managedChannel.awaitTermination(1000, TimeUnit.MILLISECONDS);
    channelFactory.close();
}
Also used : HeaderFactory(com.navercorp.pinpoint.grpc.client.HeaderFactory) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) Empty(com.google.protobuf.Empty) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) ManagedChannel(io.grpc.ManagedChannel) SpanGrpc(com.navercorp.pinpoint.grpc.trace.SpanGrpc) ClientOption(com.navercorp.pinpoint.grpc.client.config.ClientOption) Test(org.junit.Test)

Example 7 with ChannelFactoryBuilder

use of com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder in project pinpoint by naver.

the class AgentGrpcDataSenderTestMain method request.

public void request() throws Exception {
    MessageConverter<MetaDataType, GeneratedMessageV3> messageConverter = new GrpcMetadataMessageConverter();
    HeaderFactory headerFactory = new AgentHeaderFactory(AGENT_ID, AGENT_NAME, APPLICATION_NAME, SERVICE_TYPE, START_TIME);
    DnsExecutorServiceProvider dnsExecutorServiceProvider = new DnsExecutorServiceProvider();
    GrpcNameResolverProvider grpcNameResolverProvider = new GrpcNameResolverProvider(dnsExecutorServiceProvider);
    NameResolverProvider nameResolverProvider = grpcNameResolverProvider.get();
    ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("TestAgentGrpcDataSender");
    channelFactoryBuilder.setHeaderFactory(headerFactory);
    channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
    channelFactoryBuilder.setClientOption(new ClientOption());
    ChannelFactory channelFactory = channelFactoryBuilder.build();
    AgentGrpcDataSender<MetaDataType> sender = new AgentGrpcDataSender<>("localhost", 9997, 1, messageConverter, reconnectExecutor, scheduledExecutorService, channelFactory, null);
    AgentInfo agentInfo = newAgentInfo();
    sender.request(agentInfo);
    TimeUnit.SECONDS.sleep(60);
    sender.stop();
}
Also used : NameResolverProvider(io.grpc.NameResolverProvider) GrpcNameResolverProvider(com.navercorp.pinpoint.profiler.context.provider.grpc.GrpcNameResolverProvider) HeaderFactory(com.navercorp.pinpoint.grpc.client.HeaderFactory) AgentHeaderFactory(com.navercorp.pinpoint.grpc.AgentHeaderFactory) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) GrpcNameResolverProvider(com.navercorp.pinpoint.profiler.context.provider.grpc.GrpcNameResolverProvider) GrpcMetadataMessageConverter(com.navercorp.pinpoint.profiler.context.grpc.GrpcMetadataMessageConverter) AgentInfo(com.navercorp.pinpoint.profiler.metadata.AgentInfo) DnsExecutorServiceProvider(com.navercorp.pinpoint.profiler.context.provider.grpc.DnsExecutorServiceProvider) ClientOption(com.navercorp.pinpoint.grpc.client.config.ClientOption) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) AgentHeaderFactory(com.navercorp.pinpoint.grpc.AgentHeaderFactory)

Example 8 with ChannelFactoryBuilder

use of com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder in project pinpoint by naver.

the class AgentGrpcDataSenderProvider method get.

@Override
public EnhancedDataSender<MetaDataType> get() {
    final String collectorIp = grpcTransportConfig.getAgentCollectorIp();
    final int collectorPort = grpcTransportConfig.getAgentCollectorPort();
    final boolean sslEnable = grpcTransportConfig.isAgentSslEnable();
    final int senderExecutorQueueSize = grpcTransportConfig.getAgentSenderExecutorQueueSize();
    final ChannelFactoryBuilder channelFactoryBuilder = newChannelFactoryBuilder(sslEnable);
    ChannelFactory channelFactory = channelFactoryBuilder.build();
    final ReconnectExecutor reconnectExecutor = reconnectExecutorProvider.get();
    final ProfilerCommandServiceLocator profilerCommandServiceLocator = createProfilerCommandServiceLocator(activeTraceRepository);
    MessageConverter<MetaDataType, GeneratedMessageV3> messageConverter = this.messageConverter;
    return newAgentGrpcDataSender(collectorIp, collectorPort, senderExecutorQueueSize, messageConverter, channelFactory, reconnectExecutor, retransmissionExecutor, profilerCommandServiceLocator);
}
Also used : ReconnectExecutor(com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory) ProfilerCommandServiceLocator(com.navercorp.pinpoint.profiler.receiver.ProfilerCommandServiceLocator) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)

Example 9 with ChannelFactoryBuilder

use of com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder in project pinpoint by naver.

the class SpanGrpcDataSenderProvider method get.

@Override
public DataSender<SpanType> get() {
    final String collectorIp = grpcTransportConfig.getSpanCollectorIp();
    final int collectorPort = grpcTransportConfig.getSpanCollectorPort();
    final boolean sslEnable = grpcTransportConfig.isSpanSslEnable();
    final int senderExecutorQueueSize = grpcTransportConfig.getSpanSenderExecutorQueueSize();
    final ChannelFactoryBuilder channelFactoryBuilder = newChannelFactoryBuilder(sslEnable);
    final ChannelFactory channelFactory = channelFactoryBuilder.build();
    final ReconnectExecutor reconnectExecutor = this.reconnectExecutor.get();
    ClientOption spanClientOption = grpcTransportConfig.getSpanClientOption();
    final StreamState failState = new SimpleStreamState(spanClientOption.getLimitCount(), spanClientOption.getLimitTime());
    logger.info("failState:{}", failState);
    final SpanGrpcDataSender spanGrpcDataSender = new SpanGrpcDataSender(collectorIp, collectorPort, senderExecutorQueueSize, messageConverter, reconnectExecutor, channelFactory, failState);
    registerChannelzReporter(spanGrpcDataSender);
    return spanGrpcDataSender;
}
Also used : SimpleStreamState(com.navercorp.pinpoint.profiler.sender.grpc.SimpleStreamState) StreamState(com.navercorp.pinpoint.profiler.sender.grpc.StreamState) ReconnectExecutor(com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor) SimpleStreamState(com.navercorp.pinpoint.profiler.sender.grpc.SimpleStreamState) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory) ClientOption(com.navercorp.pinpoint.grpc.client.config.ClientOption) SpanGrpcDataSender(com.navercorp.pinpoint.profiler.sender.grpc.SpanGrpcDataSender) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)

Example 10 with ChannelFactoryBuilder

use of com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder in project pinpoint by naver.

the class SpanGrpcDataSenderProvider method newChannelFactoryBuilder.

private ChannelFactoryBuilder newChannelFactoryBuilder(boolean sslEnable) {
    final int channelExecutorQueueSize = grpcTransportConfig.getSpanChannelExecutorQueueSize();
    final ClientOption clientOption = grpcTransportConfig.getSpanClientOption();
    ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("SpanGrpcDataSender");
    channelFactoryBuilder.setHeaderFactory(headerFactory);
    channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
    final ClientInterceptor unaryCallDeadlineInterceptor = new UnaryCallDeadlineInterceptor(grpcTransportConfig.getSpanRequestTimeout());
    channelFactoryBuilder.addClientInterceptor(unaryCallDeadlineInterceptor);
    // channelFactoryBuilder.addClientInterceptor(discardClientInterceptor);
    if (clientInterceptorList != null) {
        for (ClientInterceptor clientInterceptor : clientInterceptorList) {
            logger.info("addClientInterceptor:{}", clientInterceptor);
            channelFactoryBuilder.addClientInterceptor(clientInterceptor);
        }
    }
    channelFactoryBuilder.setExecutorQueueSize(channelExecutorQueueSize);
    channelFactoryBuilder.setClientOption(clientOption);
    if (sslEnable) {
        SslOption sslOption = grpcTransportConfig.getSslOption();
        channelFactoryBuilder.setSslOption(sslOption);
    }
    return channelFactoryBuilder;
}
Also used : UnaryCallDeadlineInterceptor(com.navercorp.pinpoint.grpc.client.UnaryCallDeadlineInterceptor) SslOption(com.navercorp.pinpoint.grpc.client.config.SslOption) DiscardClientInterceptor(com.navercorp.pinpoint.grpc.client.interceptor.DiscardClientInterceptor) ClientInterceptor(io.grpc.ClientInterceptor) ClientOption(com.navercorp.pinpoint.grpc.client.config.ClientOption) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)

Aggregations

ChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder)12 DefaultChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)12 ClientOption (com.navercorp.pinpoint.grpc.client.config.ClientOption)9 ChannelFactory (com.navercorp.pinpoint.grpc.client.ChannelFactory)6 UnaryCallDeadlineInterceptor (com.navercorp.pinpoint.grpc.client.UnaryCallDeadlineInterceptor)5 ClientInterceptor (io.grpc.ClientInterceptor)5 HeaderFactory (com.navercorp.pinpoint.grpc.client.HeaderFactory)4 SslOption (com.navercorp.pinpoint.grpc.client.config.SslOption)4 AgentHeaderFactory (com.navercorp.pinpoint.grpc.AgentHeaderFactory)3 ReconnectExecutor (com.navercorp.pinpoint.profiler.sender.grpc.ReconnectExecutor)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 DiscardClientInterceptor (com.navercorp.pinpoint.grpc.client.interceptor.DiscardClientInterceptor)2 MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)2 Empty (com.google.protobuf.Empty)1 PSpan (com.navercorp.pinpoint.grpc.trace.PSpan)1 PSpanMessage (com.navercorp.pinpoint.grpc.trace.PSpanMessage)1 SpanGrpc (com.navercorp.pinpoint.grpc.trace.SpanGrpc)1 GrpcMetadataMessageConverter (com.navercorp.pinpoint.profiler.context.grpc.GrpcMetadataMessageConverter)1 DnsExecutorServiceProvider (com.navercorp.pinpoint.profiler.context.provider.grpc.DnsExecutorServiceProvider)1 GrpcNameResolverProvider (com.navercorp.pinpoint.profiler.context.provider.grpc.GrpcNameResolverProvider)1