use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method overSqlLimit.
@Test
public void overSqlLimit() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
int sqlLimit = SlowQueryAggregatorImpl.SLOW_QUERY_LIMIT_PER_REPORTING_PERIOD;
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
for (int i = 0; i < sqlLimit * 2; i++) {
String sql = "select * from dude where column" + i + " = 'cool'";
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1 + i, TimeUnit.MILLISECONDS);
startSqlTracer(sql, 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(sqlLimit, sqlTraces.size());
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
for (int i = sqlLimit; i < sqlLimit * 2; i++) {
String expectedSql = "select * from dude where column" + i + " = ?";
long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
long expectedDuration = getExplainThresholdInMillis() + 1 + i;
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(1, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration, sqlTrace.getMax());
}
}
use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method transactionTracerNotEnabled.
@Test
public void transactionTracerNotEnabled() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put("enabled", false);
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(0, sqlTraces.size());
}
use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method notOverExplainThreshold.
@Test
public void notOverExplainThreshold() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis(), 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(0, sqlTraces.size());
}
use of com.newrelic.agent.stats.StatsEngineImpl 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());
}
use of com.newrelic.agent.stats.StatsEngineImpl in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method testExponentialBackoff.
@Test
public void testExponentialBackoff() {
rpmServiceManager.getOrCreateRPMService("Test");
// Create reservoir
ServiceFactory.getTransactionEventsService().harvestEvents("Test");
DistributedSamplingPriorityQueue<TransactionEvent> reservoir = ServiceFactory.getTransactionEventsService().getOrCreateDistributedSamplingReservoir("Test");
// First 10 traces
for (int i = 0; i < 10; i++) {
assertTrue(DistributedTraceUtil.isSampledPriority(distributedTraceService.calculatePriority(null, reservoir)));
TransactionEvent transactionEvent = Mockito.mock(TransactionEvent.class);
when(transactionEvent.getPriority()).thenReturn(1.0f);
when(transactionEvent.decider()).thenReturn(true);
reservoir.add(transactionEvent);
}
distributedTraceService.beforeHarvest("Test", new StatsEngineImpl());
ServiceFactory.getTransactionEventsService().harvestEvents("Test");
reservoir = ServiceFactory.getTransactionEventsService().getOrCreateDistributedSamplingReservoir("Test");
assertEquals(0, reservoir.getSampled());
// Test that we hit target
for (int i = 0; i < reservoir.getTarget(); i++) {
if (DistributedTraceUtil.isSampledPriority(distributedTraceService.calculatePriority(null, reservoir))) {
TransactionEvent transactionEvent = Mockito.mock(TransactionEvent.class);
when(transactionEvent.getPriority()).thenReturn(1.0f);
when(transactionEvent.decider()).thenReturn(true);
reservoir.add(transactionEvent);
}
}
assertTrue("Sampled fewer than target transactions", reservoir.getSampled() >= reservoir.getTarget());
ServiceFactory.getTransactionEventsService().harvestEvents("Test");
distributedTraceService.beforeHarvest("Test", new StatsEngineImpl());
reservoir = ServiceFactory.getTransactionEventsService().getOrCreateDistributedSamplingReservoir("Test");
// Test that we do not go above 2x target
for (int i = 0; i < 1000 * reservoir.getTarget(); i++) {
if (DistributedTraceUtil.isSampledPriority(distributedTraceService.calculatePriority(null, reservoir))) {
TransactionEvent transactionEvent = Mockito.mock(TransactionEvent.class);
when(transactionEvent.getPriority()).thenReturn(1.0f);
when(transactionEvent.decider()).thenReturn(true);
reservoir.add(transactionEvent);
}
}
assertTrue("Sampled fewer than target transactions", reservoir.getSampled() >= reservoir.getTarget());
assertTrue("Sampled more than 2x target ", reservoir.getSampled() <= (2 * reservoir.getTarget()));
}
Aggregations