Search in sources :

Example 1 with ConnectionConfigListener

use of com.newrelic.agent.ConnectionConfigListener in project newrelic-java-agent by newrelic.

the class ConfigServiceTest method connectionListenerAndErrorEvents.

@Test
public void connectionListenerAndErrorEvents() throws Exception {
    Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
    createServiceManager(configMap);
    ConfigService configService = ServiceFactory.getConfigService();
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    // test defaults
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    String appName = rpmService.getApplicationName();
    String appName2 = "bogus";
    Map<String, Object> data = new HashMap<>();
    Map<String, Object> agentData = new HashMap<>();
    data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
    assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
    assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
    assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
    assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
    // test collector shut off
    data.put(ErrorCollectorConfigImpl.COLLECT_EVENTS, false);
    connectionConfigListener.connected(rpmService, data);
    assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
    assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
    assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
    assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
    // test config shut off and max event count
    rpmService = new MockRPMService();
    rpmService.setApplicationName(appName2);
    agentData.put(AgentConfigFactory.CAPTURE_ERROR_EVENTS, false);
    agentData.put(AgentConfigFactory.MAX_ERROR_EVENT_SAMPLES_STORED, 20);
    connectionConfigListener.connected(rpmService, data);
    assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
    assertFalse(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
    assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
    assertEquals(20, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 2 with ConnectionConfigListener

use of com.newrelic.agent.ConnectionConfigListener in project newrelic-java-agent by newrelic.

the class ConfigServiceTest method connectionListener.

@Test
public void connectionListener() throws Exception {
    Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
    createServiceManager(configMap);
    ConfigService configService = ServiceFactory.getConfigService();
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    String appName = rpmService.getApplicationName();
    String appName2 = "bogus";
    Map<String, Object> data = new HashMap<>();
    Map<String, Object> agentData = new HashMap<>();
    data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
    data.put(AgentConfigImpl.APDEX_T, 0.500d);
    data.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
    data.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
    agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, true);
    agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, true);
    assertFalse(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
    assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
    assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
    assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
    connectionConfigListener.connected(rpmService, data);
    assertEquals(500L, configService.getAgentConfig(appName).getApdexTInMillis());
    assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
    assertTrue(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
    assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
    assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
    assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
    data.put(AgentConfigImpl.APDEX_T, 1.500d);
    connectionConfigListener.connected(rpmService, data);
    assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
    assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
    rpmService = new MockRPMService();
    rpmService.setApplicationName(appName2);
    data.put(AgentConfigImpl.APDEX_T, 2.000d);
    connectionConfigListener.connected(rpmService, data);
    assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
    assertEquals(2000L, configService.getAgentConfig(appName2).getApdexTInMillis());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 3 with ConnectionConfigListener

use of com.newrelic.agent.ConnectionConfigListener in project newrelic-java-agent by newrelic.

the class SqlTraceServiceTest method serverConfigChanges.

@Test
public void serverConfigChanges() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> sqlMap = createMap();
    sqlMap.put("enabled", true);
    configMap.put(AgentConfigImpl.SLOW_SQL, sqlMap);
    createServiceManager(configMap);
    // run a transaction
    Tracer requestDispatcherTracer = startDispatcherTracer();
    long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
    List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(2, sqlTraces.size());
    Map<String, Object> serverData = createMap();
    Map<String, Object> agentMap = createMap();
    serverData.put(AgentConfigFactory.AGENT_CONFIG, agentMap);
    agentMap.put(AgentConfigFactory.SLOW_SQL_PREFIX + "enabled", false);
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    connectionConfigListener.connected(mockRPMService, serverData);
    // run a transaction
    requestDispatcherTracer = startDispatcherTracer();
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(0, sqlTraces.size());
    serverData = createMap();
    agentMap = createMap();
    serverData.put(AgentConfigFactory.AGENT_CONFIG, agentMap);
    agentMap.put(AgentConfigFactory.SLOW_SQL_PREFIX + "enabled", true);
    connectionConfigListener.connected(mockRPMService, serverData);
    // run a transaction
    requestDispatcherTracer = startDispatcherTracer();
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
    requestDispatcherTracer.finish(Opcodes.RETURN, null);
    // run a harvest
    mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
    sqlTraces = mockRPMService.getSqlTraces();
    // verify results
    Assert.assertEquals(2, sqlTraces.size());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 4 with ConnectionConfigListener

use of com.newrelic.agent.ConnectionConfigListener in project newrelic-java-agent by newrelic.

the class BasicRequestDispatcherTracerTest method requestXQueueHeaderRecordApdexMetrics.

@Test
public void requestXQueueHeaderRecordApdexMetrics() throws Exception {
    MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
    MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
    rpmService.setEverConnected(true);
    Map<String, Object> data = new HashMap<>();
    data.put(AgentConfigImpl.APDEX_T, 6.0d);
    ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
    connectionConfigListener.connected(rpmService, data);
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 23500));
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
    ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
    apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
    Assert.assertEquals(0, apdexStats.getApdexFrustrating());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) ApdexStats(com.newrelic.agent.stats.ApdexStats) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 5 with ConnectionConfigListener

use of com.newrelic.agent.ConnectionConfigListener in project newrelic-java-agent by newrelic.

the class DatabaseTest method useDelegatingPreparedStatement.

@Test
public void useDelegatingPreparedStatement() throws Exception {
    final String applicationName = "App";
    ((ConnectionConfigListener) ServiceFactory.getConfigService()).connected(ServiceFactory.getRPMServiceManager().getRPMService(), new HashMap<String, Object>() {

        {
            put("transaction_tracer.record_sql", "raw");
        }
    });
    AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(null);
    Assert.assertEquals(SqlObfuscator.RAW_SETTING, agentConfig.getTransactionTracerConfig().getRecordSql());
    Assert.assertEquals(SqlObfuscator.RAW_SETTING, agentConfig.getRequestTransactionTracerConfig().getRecordSql());
    HttpServlet servlet = new PreparedStatementServlet(true, 1);
    AgentHelper.invokeServlet(servlet, "", applicationName, "/database/test");
    Set<String> metrics = AgentHelper.getMetrics(AgentHelper.getDefaultStatsEngine());
    Assert.assertTrue(metrics.toString(), metrics.size() > 0);
    AgentHelper.verifyDatastoreMetrics(metrics, DatastoreVendor.Derby, "test", "select");
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) HttpServlet(javax.servlet.http.HttpServlet) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) Test(org.junit.Test)

Aggregations

ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)8 Test (org.junit.Test)8 MockRPMService (com.newrelic.agent.MockRPMService)6 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)6 HashMap (java.util.HashMap)5 JSONObject (org.json.simple.JSONObject)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)2 ApdexStats (com.newrelic.agent.stats.ApdexStats)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 HttpServlet (javax.servlet.http.HttpServlet)2 MockHarvestService (com.newrelic.agent.MockHarvestService)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1