Search in sources :

Example 1 with ConfigServiceImpl

use of com.newrelic.agent.config.ConfigServiceImpl in project newrelic-java-agent by newrelic.

the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabledMiddle.

@Test
public void testDifferentAppNamesOneDisabledMiddle() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    // default app name
    TransactionData transactionData = generateTransactionData(APP_NAME);
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // second app name
    TransactionData transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
    TransactionStats transactionStats2 = new TransactionStats();
    transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
    // third app name
    String appName3 = "thirdAppName";
    TransactionData transactionData3 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), appName3);
    TransactionStats transactionStats3 = new TransactionStats();
    transactionStats3.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(10, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    // populate the eventData map
    service.harvestEvents(APP_NAME_2);
    // populate the eventData map
    service.harvestEvents(appName3);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData2 = getEventData(APP_NAME_2);
    assertEquals(0, currentEventData2.size());
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData3 = getEventData(appName3);
    assertEquals(0, currentEventData3.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    service.dispatcherTransactionFinished(transactionData2, transactionStats2);
    service.dispatcherTransactionFinished(transactionData3, transactionStats3);
    assertEquals(1, currentEventData.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
    assertEquals(1, currentEventData2.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData2.peek().getDuration(), 0);
    assertEquals(1, currentEventData3.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
    // server side says app name 2 disabled
    Map<String, Object> data = new HashMap<>();
    data.put("collect_analytics_events", Boolean.FALSE);
    ((ConfigServiceImpl) configService).connected(rpmServiceAppName2, data);
    // second time with second name
    transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
    transactionStats2 = new TransactionStats();
    transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
    service.dispatcherTransactionFinished(transactionData2, transactionStats2);
    currentEventData2 = getEventData(APP_NAME_2);
    // since the second app has been disabled - this should be false
    assertNull(currentEventData2);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 2 with ConfigServiceImpl

use of com.newrelic.agent.config.ConfigServiceImpl in project newrelic-java-agent by newrelic.

the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabled.

@Test
public void testDifferentAppNamesOneDisabled() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    // server side says app name 2 disabled
    Map<String, Object> data = new HashMap<>();
    data.put("collect_analytics_events", Boolean.FALSE);
    ((ConfigServiceImpl) configService).connected(rpmServiceAppName2, data);
    // default app name
    TransactionData transactionData = generateTransactionData(APP_NAME);
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // second app name
    TransactionData transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
    TransactionStats transactionStats2 = new TransactionStats();
    transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
    // third app name
    String appName3 = "thirdAppName";
    rpmServiceManager.getOrCreateRPMService(appName3);
    TransactionData transactionData3 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), appName3);
    TransactionStats transactionStats3 = new TransactionStats();
    transactionStats3.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(10, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    // populate the eventData map
    service.harvestEvents(APP_NAME_2);
    // populate the eventData map
    service.harvestEvents(appName3);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData2 = getEventData(APP_NAME_2);
    assertEquals(0, currentEventData2.size());
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData3 = getEventData(appName3);
    assertEquals(0, currentEventData3.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    service.dispatcherTransactionFinished(transactionData2, transactionStats2);
    service.dispatcherTransactionFinished(transactionData3, transactionStats3);
    assertEquals(1, currentEventData.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
    currentEventData2 = getEventData(APP_NAME_2);
    assertNull(currentEventData2);
    assertEquals(1, currentEventData3.size());
    assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
    service.harvestEvents(APP_NAME);
    currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.harvestEvents(appName3);
    currentEventData3 = getEventData(appName3);
    assertEquals(0, currentEventData3.size());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) HashMap(java.util.HashMap) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 3 with ConfigServiceImpl

use of com.newrelic.agent.config.ConfigServiceImpl in project newrelic-java-agent by newrelic.

the class AgentLinkingMetadataTest method getLinkingMetadata.

@Test
public void getLinkingMetadata() {
    // Given
    final String expectedTraceId = "traceId1234";
    final String expectedSpanId = "spanId5678";
    final String expectedEntityGuid = "entityGuid91011";
    final String expectedEntityName = "entityName91011";
    final String expectedEntityType = AgentLinkingMetadata.ENTITY_TYPE_DEFAULT;
    TraceMetadataImpl traceMetadataMock = mock(TraceMetadataImpl.class);
    ServiceManagerImpl serviceManagerMock = mock(ServiceManagerImpl.class);
    RPMServiceManagerImpl rpmServiceManagerMock = mock(RPMServiceManagerImpl.class);
    RPMService rpmServiceMock = mock(RPMService.class);
    ConfigServiceImpl configServiceMock = mock(ConfigServiceImpl.class);
    AgentConfigImpl agentConfigMock = mock(AgentConfigImpl.class);
    ServiceFactory.setServiceManager(serviceManagerMock);
    // When
    when(traceMetadataMock.getTraceId()).thenReturn(expectedTraceId);
    when(traceMetadataMock.getSpanId()).thenReturn(expectedSpanId);
    when(serviceManagerMock.getRPMServiceManager()).thenReturn(rpmServiceManagerMock);
    when(serviceManagerMock.getConfigService()).thenReturn(configServiceMock);
    when(rpmServiceManagerMock.getRPMService()).thenReturn(rpmServiceMock);
    when(configServiceMock.getDefaultAgentConfig()).thenReturn(agentConfigMock);
    when(agentConfigMock.getApplicationName()).thenReturn(expectedEntityName);
    when(rpmServiceMock.getEntityGuid()).thenReturn(expectedEntityGuid);
    // Then
    Map<String, String> linkingMetadata = AgentLinkingMetadata.getLinkingMetadata(traceMetadataMock, ServiceFactory.getConfigService(), ServiceFactory.getRPMService());
    assertFalse("linkingMetadata map shouldn't be empty", linkingMetadata.isEmpty());
    // Can't assert on a specific hostname value as it will resolve to the actual hostname of the machine running the test
    assertFalse("hostname shouldn't be empty", linkingMetadata.get(AgentLinkingMetadata.HOSTNAME).isEmpty());
    assertEquals(expectedEntityGuid, linkingMetadata.get(AgentLinkingMetadata.ENTITY_GUID));
    assertEquals(expectedEntityName, linkingMetadata.get(AgentLinkingMetadata.ENTITY_NAME));
    assertEquals(expectedEntityType, linkingMetadata.get(AgentLinkingMetadata.ENTITY_TYPE));
    assertEquals(expectedTraceId, linkingMetadata.get(AgentLinkingMetadata.TRACE_ID));
    assertEquals(expectedSpanId, linkingMetadata.get(AgentLinkingMetadata.SPAN_ID));
}
Also used : AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Test(org.junit.Test)

Example 4 with ConfigServiceImpl

use of com.newrelic.agent.config.ConfigServiceImpl in project newrelic-java-agent by newrelic.

the class CrossProcessAndSyntheticsConfigTest method testConfig.

// The "expected value" arguments are all about the newrelic.yml. We're not varying the collector JSON here.
public void testConfig(String ymlFilePath, boolean expectedValueOfCatEnable, boolean expectedValueOfBrowserEnabled) throws Exception {
    System.setProperty("newrelic.config.file", ymlFilePath);
    ConfigService configService = ConfigServiceFactory.createConfigService(mock(Logger.class), false);
    AgentConfig agentConfig = configService.getAgentConfig(appName);
    assertEquals(appName, agentConfig.getApplicationName());
    assertTrue(agentConfig instanceof AgentConfigImpl);
    assertTrue(configService instanceof ConfigServiceImpl);
    IRPMService rpmService = mock(IRPMService.class);
    Mockito.when(rpmService.getApplicationName()).thenReturn(appName);
    org.json.simple.parser.JSONParser parser = new org.json.simple.parser.JSONParser();
    @SuppressWarnings("unchecked") Map<String, Object> serverData = (Map<String, Object>) parser.parse(collectorJson);
    ((ConfigServiceImpl) configService).connected(rpmService, serverData);
    assertEquals(configService.getAgentConfig(appName).getBrowserMonitoringConfig().isAutoInstrumentEnabled(), expectedValueOfBrowserEnabled);
    assertEquals(configService.getAgentConfig(appName).getCrossProcessConfig().isCrossApplicationTracing(), expectedValueOfCatEnable);
    String s = configService.getAgentConfig(appName).getValue("cross_application_tracer.encoding_key");
    assertEquals(s, encodingKey);
}
Also used : Logger(com.newrelic.api.agent.Logger) AgentConfig(com.newrelic.agent.config.AgentConfig) AgentConfigImpl(com.newrelic.agent.config.AgentConfigImpl) ConfigService(com.newrelic.agent.config.ConfigService) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) Map(java.util.Map)

Example 5 with ConfigServiceImpl

use of com.newrelic.agent.config.ConfigServiceImpl in project newrelic-java-agent by newrelic.

the class EnvironmentHolder method setupEnvironment.

public void setupEnvironment() throws Exception {
    rpmService.setIsConnected(true);
    IRPMService originalRpmService = originalServiceManager.getRPMServiceManager().getRPMService();
    rpmService.setApplicationName(originalRpmService.getApplicationName());
    AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(environmentHolderSettingsGenerator.generateSettings());
    Map<String, Object> properties = ImmutableMap.<String, Object>of("agent_config", ((BaseConfig) agentConfig).getProperties(), "collect_span_events", true);
    ((ConfigServiceImpl) ServiceFactory.getConfigService()).connected(rpmService, properties);
    if (agentConfig.getDistributedTracingConfig().isEnabled()) {
        ((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).connected(rpmService, agentConfig);
    }
    config = agentConfig;
    // Set up now that new environment is in place
    ServiceFactory.getTransactionService().addTransactionListener(transactionList);
    transactionList.clear();
    // We have to actually start the harvest service, even though typically tests call harvestNow(). This means
    // the test will conflict with a real harvest if it takes more than about 30 seconds, possibly leading to
    // flickers. We should probably change the design of the harvest service. Better yet, we should implement a
    // better way to have custom configurations in functional tests and get rid of this messy class completely.
    ServiceFactory.getHarvestService().startHarvest(rpmService);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) ConfigServiceImpl(com.newrelic.agent.config.ConfigServiceImpl) IRPMService(com.newrelic.agent.IRPMService)

Aggregations

ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)8 Test (org.junit.Test)6 AgentConfigImpl (com.newrelic.agent.config.AgentConfigImpl)5 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)4 TransactionData (com.newrelic.agent.TransactionData)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 HashMap (java.util.HashMap)2 IRPMService (com.newrelic.agent.IRPMService)1 ConfigService (com.newrelic.agent.config.ConfigService)1 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)1 Logger (com.newrelic.api.agent.Logger)1 Map (java.util.Map)1