Search in sources :

Example 1 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads.

@Test
public void agentInfoShouldBeRefreshedOnServerMetaDataChangeFromMultipleThreads() {
    // Given
    final long agentInfoSendRetryIntervalMs = 1000L;
    final int threadCount = 50;
    final CountDownLatch initLatch = new CountDownLatch(threadCount);
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    final Queue<Throwable> exceptions = new ConcurrentLinkedQueue<>();
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, bindPort);
    final AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    serverMetaDataRegistryService.addListener(new ServerMetaDataRegistryService.OnChangeListener() {

        @Override
        public void onServerMetaDataChange() {
            agentInfoSender.refresh();
        }
    });
    // When
    for (int i = 0; i < threadCount; i++) {
        final String serviceName = "/name" + i;
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                initLatch.countDown();
                try {
                    startLatch.await();
                    ServiceInfo serviceInfo = new DefaultServiceInfo(serviceName, Collections.<String>emptyList());
                    serverMetaDataRegistryService.addServiceInfo(serviceInfo);
                    serverMetaDataRegistryService.notifyListeners();
                } catch (final Throwable t) {
                    exceptions.add(t);
                } finally {
                    endLatch.countDown();
                }
            }
        });
    }
    await(initLatch, 3000);
    startLatch.countDown();
    await(endLatch, 3000);
    executorService.shutdown();
    try {
        waitExpectedRequestCount(threadCount, messageListener);
        waitExpectedSuccessCount(threadCount, messageListener);
    } finally {
        closeAll(agentInfoSender, clientFactory);
        testPinpointServerAcceptor.close();
    }
    // Then
    assertTrue("Failed with exceptions : " + exceptions, exceptions.isEmpty());
    assertEquals(threadCount, messageListener.getRequestCount());
    assertEquals(threadCount, messageListener.getSuccessCount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ServiceInfo(com.navercorp.pinpoint.bootstrap.context.ServiceInfo) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) ExecutorService(java.util.concurrent.ExecutorService) ServerMetaDataRegistryService(com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DefaultServiceInfo(com.navercorp.pinpoint.profiler.context.DefaultServiceInfo) Test(org.junit.Test)

Example 2 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldKeepRefreshing.

@Test
public void agentInfoShouldKeepRefreshing() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final long agentInfoSendRefreshIntervalMs = 100L;
    final int expectedRefreshCount = 5;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory();
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).refreshInterval(agentInfoSendRefreshIntervalMs).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    try {
        agentInfoSender.start();
        while (messageListener.getRequestCount() < expectedRefreshCount) {
            sleep(1000L);
        }
    } finally {
        closeAll(agentInfoSender, socketFactory);
        testPinpointServerAcceptor.close();
    }
    assertTrue(messageListener.getRequestCount() >= expectedRefreshCount);
    assertTrue(messageListener.getSuccessCount() >= expectedRefreshCount);
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) Test(org.junit.Test)

Example 3 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method reconnectionStressTest.

public void reconnectionStressTest() {
    final long stressTestTime = 60 * 1000L;
    final int randomMaxTime = 3000;
    final long agentInfoSendRetryIntervalMs = 1000L;
    final int maxTryPerAttempt = Integer.MAX_VALUE;
    final int expectedTriesUntilSuccess = (int) stressTestTime / (randomMaxTime * 2) - 1;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess);
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    int availableTcpPort = SocketUtils.findAvailableTcpPort(47000);
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(clientFactory, availableTcpPort);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).sendInterval(agentInfoSendRetryIntervalMs).maxTryPerAttempt(maxTryPerAttempt).setMessageConverter(resultResponseMessageConverter).build();
    long startTime = System.currentTimeMillis();
    try {
        agentInfoSender.start();
        while (System.currentTimeMillis() < startTime + stressTestTime) {
            createAndDeleteServer(messageListenerFactory, Math.abs(RandomUtils.nextInt(randomMaxTime)));
            sleep(Math.abs(RandomUtils.nextInt(1000)));
        }
    } finally {
        closeAll(agentInfoSender, clientFactory);
    }
    assertEquals(1, messageListener.getSuccessCount());
    assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount());
}
Also used : PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType)

Example 4 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class AgentInfoSenderTest method agentInfoShouldInitiallyRetryIndefinitely.

@Test
public void agentInfoShouldInitiallyRetryIndefinitely() {
    final long agentInfoSendRetryIntervalMs = 100L;
    final int maxTryPerAttempt = 3;
    final int expectedTriesUntilSuccess = maxTryPerAttempt * 5;
    final ResponseServerMessageListenerFactory messageListenerFactory = new ResponseServerMessageListenerFactory(expectedTriesUntilSuccess);
    ResponseServerMessageListener messageListener = messageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(messageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory socketFactory = createPinpointClientFactory();
    EnhancedDataSender<MetaDataType> dataSender = newTcpDataSender(socketFactory, bindPort);
    AgentInfoSender agentInfoSender = new AgentInfoSender.Builder(dataSender, agentInfoFactory).maxTryPerAttempt(maxTryPerAttempt).sendInterval(agentInfoSendRetryIntervalMs).setMessageConverter(resultResponseMessageConverter).build();
    try {
        agentInfoSender.start();
        waitExpectedRequestCount(expectedTriesUntilSuccess, messageListener);
    } finally {
        closeAll(agentInfoSender, socketFactory);
        testPinpointServerAcceptor.close();
    }
    assertEquals(expectedTriesUntilSuccess, messageListener.getRequestCount());
    assertEquals(1, messageListener.getSuccessCount());
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) Test(org.junit.Test)

Example 5 with MetaDataType

use of com.navercorp.pinpoint.profiler.metadata.MetaDataType in project pinpoint by naver.

the class ThriftModule method configure.

@Override
protected void configure() {
    logger.info("configure {}", this.getClass().getSimpleName());
    ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig();
    bind(ThriftTransportConfig.class).toInstance(thriftTransportConfig);
    bind(TransactionIdEncoder.class).to(DefaultTransactionIdEncoder.class).in(Scopes.SINGLETON);
    Key<CommandDispatcher> commandDispatcher = Key.get(CommandDispatcher.class);
    bind(commandDispatcher).toProvider(CommandDispatcherProvider.class).in(Scopes.SINGLETON);
    // expose(commandDispatcher);
    TypeLiteral<SpanProcessor<TSpan, TSpanChunk>> spanPostProcessorType = new TypeLiteral<SpanProcessor<TSpan, TSpanChunk>>() {
    };
    bind(spanPostProcessorType).toProvider(SpanProcessorProvider.class).in(Scopes.SINGLETON);
    bind(ConnectionFactoryProvider.class).toProvider(ConnectionFactoryProviderProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> pinpointClientFactory = Key.get(PinpointClientFactory.class, DefaultClientFactory.class);
    bind(pinpointClientFactory).toProvider(PinpointClientFactoryProvider.class).in(Scopes.SINGLETON);
    // expose(pinpointClientFactory);
    bind(HeaderTBaseSerializer.class).toProvider(HeaderTBaseSerializerProvider.class).in(Scopes.SINGLETON);
    // EnhancedDataSender
    TypeLiteral<EnhancedDataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
    };
    bind(dataSenderTypeLiteral).toProvider(TcpDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(dataSenderTypeLiteral);
    // Bind AgentDataSender to EnhancedDataSender
    Key<EnhancedDataSender<MetaDataType>> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class);
    bind(agentDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON);
    expose(agentDataSender);
    // Bind MetadataDataSender to EnhancedDataSender
    Key<EnhancedDataSender<MetaDataType>> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class);
    bind(metadataDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON);
    expose(metadataDataSender);
    Key<Timer> spanStatConnectTimer = Key.get(Timer.class, SpanStatChannelFactory.class);
    bind(spanStatConnectTimer).toProvider(SpanStatConnectTimerProvider.class).in(Scopes.SINGLETON);
    Key<ChannelFactory> spanStatChannelFactory = Key.get(ChannelFactory.class, SpanStatChannelFactory.class);
    bind(spanStatChannelFactory).toProvider(SpanStatChannelFactoryProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> spanClientFactory = Key.get(PinpointClientFactory.class, SpanDataSender.class);
    bind(spanClientFactory).toProvider(SpanClientFactoryProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> statClientFactory = Key.get(PinpointClientFactory.class, StatDataSender.class);
    bind(statClientFactory).toProvider(StatClientFactoryProvider.class).in(Scopes.SINGLETON);
    TypeLiteral<MessageConverter<SpanType, TBase<?, ?>>> thriftMessageConverter = new TypeLiteral<MessageConverter<SpanType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<SpanType, TBase<?, ?>>> spanMessageConverterKey = Key.get(thriftMessageConverter, SpanDataSender.class);
    bind(spanMessageConverterKey).toProvider(SpanThriftMessageConverterProvider.class).in(Scopes.SINGLETON);
    // expose(spanMessageConverterKey);
    TypeLiteral<MessageConverter<MetaDataType, TBase<?, ?>>> metadataMessageConverter = new TypeLiteral<MessageConverter<MetaDataType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<MetaDataType, TBase<?, ?>>> metadataMessageConverterKey = Key.get(metadataMessageConverter, MetadataDataSender.class);
    bind(metadataMessageConverterKey).toProvider(MetadataMessageConverterProvider.class).in(Scopes.SINGLETON);
    // expose(metadataMessageConverterKey);
    // Stat Thrift Converter
    TypeLiteral<MessageConverter<MetricType, TBase<?, ?>>> statMessageConverter = new TypeLiteral<MessageConverter<MetricType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<MetricType, TBase<?, ?>>> statMessageConverterKey = Key.get(statMessageConverter, StatDataSender.class);
    bind(statMessageConverterKey).toProvider(StatThriftMessageConverterProvider.class).in(Scopes.SINGLETON);
    TypeLiteral<DataSender<SpanType>> spanDataSenderType = new TypeLiteral<DataSender<SpanType>>() {
    };
    Key<DataSender<SpanType>> spanDataSender = Key.get(spanDataSenderType, SpanDataSender.class);
    bind(spanDataSender).toProvider(SpanDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(spanDataSender);
    TypeLiteral<DataSender<MetricType>> statDataSenderType = new TypeLiteral<DataSender<MetricType>>() {
    };
    Key<DataSender<MetricType>> statDataSender = Key.get(statDataSenderType, StatDataSender.class);
    bind(statDataSender).toProvider(StatDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(statDataSender);
    // For AgentInfoSender
    // TypeLiteral<AgentInfoFactory> agentInfoFactoryTypeLiteral = new TypeLiteral<AgentInfoFactory>() {};
    // bind(agentInfoFactoryTypeLiteral).toProvider(AgentInfoFactoryProvider.class).in(Scopes.SINGLETON);
    // expose(agentInfoFactoryTypeLiteral);
    TypeLiteral<MessageConverter<Object, ResultResponse>> resultMessageConverter = new TypeLiteral<MessageConverter<Object, ResultResponse>>() {
    };
    Key<MessageConverter<Object, ResultResponse>> resultMessageConverterKey = Key.get(resultMessageConverter, ResultConverter.class);
    bind(resultMessageConverterKey).toProvider(ThriftMessageToResultConverterProvider.class).in(Scopes.SINGLETON);
    expose(resultMessageConverterKey);
    Key<ModuleLifeCycle> rpcModuleLifeCycleKey = Key.get(ModuleLifeCycle.class, Names.named("RPC-MODULE"));
    bind(rpcModuleLifeCycleKey).to(ThriftModuleLifeCycle.class).in(Scopes.SINGLETON);
    expose(rpcModuleLifeCycleKey);
}
Also used : MetadataMessageConverterProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.MetadataMessageConverterProvider) ResultResponse(com.navercorp.pinpoint.profiler.sender.ResultResponse) DefaultTransactionIdEncoder(com.navercorp.pinpoint.profiler.context.thrift.DefaultTransactionIdEncoder) PinpointClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.PinpointClientFactoryProvider) EnhancedDataSender(com.navercorp.pinpoint.profiler.sender.EnhancedDataSender) DataSender(com.navercorp.pinpoint.profiler.sender.DataSender) EnhancedDataSender(com.navercorp.pinpoint.profiler.sender.EnhancedDataSender) ConnectionFactoryProviderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.ConnectionFactoryProviderProvider) SpanThriftMessageConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.SpanThriftMessageConverterProvider) CommandDispatcherProvider(com.navercorp.pinpoint.profiler.context.provider.CommandDispatcherProvider) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) SpanStatChannelFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatChannelFactoryProvider) ChannelFactory(org.jboss.netty.channel.ChannelFactory) MessageConverter(com.navercorp.pinpoint.profiler.context.thrift.MessageConverter) SpanType(com.navercorp.pinpoint.profiler.context.SpanType) HeaderTBaseSerializerProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.HeaderTBaseSerializerProvider) StatClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.StatClientFactoryProvider) ThriftMessageToResultConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.ThriftMessageToResultConverterProvider) DefaultThriftTransportConfig(com.navercorp.pinpoint.profiler.context.thrift.config.DefaultThriftTransportConfig) ThriftTransportConfig(com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig) StatThriftMessageConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.StatThriftMessageConverterProvider) SpanDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanDataSenderProvider) MetricType(com.navercorp.pinpoint.profiler.monitor.metric.MetricType) SpanStatConnectTimerProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatConnectTimerProvider) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) TcpDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.TcpDataSenderProvider) SpanProcessor(com.navercorp.pinpoint.profiler.context.compress.SpanProcessor) SpanClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanClientFactoryProvider) TypeLiteral(com.google.inject.TypeLiteral) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) CommandDispatcher(com.navercorp.pinpoint.profiler.receiver.CommandDispatcher) StatDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.StatDataSenderProvider) Timer(org.jboss.netty.util.Timer) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) SpanProcessorProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanProcessorProvider) TBase(org.apache.thrift.TBase)

Aggregations

MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)19 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)12 Test (org.junit.Test)10 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)9 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)8 ServerMetaDataRegistryService (com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 TypeLiteral (com.google.inject.TypeLiteral)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 ChannelFactory (com.navercorp.pinpoint.grpc.client.ChannelFactory)2 ChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder)2 DefaultChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)2 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)2 DefaultTransactionIdEncoder (com.navercorp.pinpoint.profiler.context.thrift.DefaultTransactionIdEncoder)2 StringMetaData (com.navercorp.pinpoint.profiler.metadata.StringMetaData)2 MetricType (com.navercorp.pinpoint.profiler.monitor.metric.MetricType)2 DataSender (com.navercorp.pinpoint.profiler.sender.DataSender)2 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)2 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2