use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class SlowQueryInfoTest method testEmptyTxnUrlRequestUriDisabled.
@Test
public void testEmptyTxnUrlRequestUriDisabled() {
Map<String, Object> attributeMap = new HashMap<>();
attributeMap.put("exclude", "request.*");
Map<String, Object> settings = new HashMap<>();
settings.put("attributes", attributeMap);
setupServiceManager(settings);
SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
Transaction transaction = Transaction.getTransaction();
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setUri("http://jvm.agent.uri");
transaction.setDispatcher(dispatcher);
TransactionData data = new TransactionData(transaction, 100);
Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
assertEquals(null, sqlTrace.getUri());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class SlowQueryInfoTest method testTxnUrl.
@Test
public void testTxnUrl() {
setupServiceManager(new HashMap<String, Object>());
Transaction transaction = Transaction.getTransaction();
SqlTraceConfig sqlTraceConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getSqlTraceConfig();
MockDispatcher dispatcher = new MockDispatcher();
dispatcher.setUri("http://jvm.agent.uri");
transaction.setDispatcher(dispatcher);
TransactionData data = new TransactionData(transaction, 100);
Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", "select ? from ?", sqlTraceConfig);
SqlTrace sqlTrace = slowQueryInfo.asSqlTrace();
assertEquals("http://jvm.agent.uri", sqlTrace.getUri());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class KeyTransactionTraceSamplerTest method testSameScore.
@Test
public void testSameScore() throws Exception {
Map<String, Double> keyTransactions = new HashMap<>();
keyTransactions.put("keyTxnOne", 0.5);
keyTransactions.put("keyTxnTwo", 0.25);
setupAgent(keyTransactions);
KeyTransactionTraceSampler sampler = new KeyTransactionTraceSampler();
TransactionData keyTxnOne = createTransactionData("keyTxnOne", 1000);
TransactionData keyTxnTwo = createTransactionData("keyTxnTwo", 500);
sampler.noticeTransaction(keyTxnOne);
sampler.noticeTransaction(keyTxnTwo);
assertEquals(sampler.getScore(keyTxnOne), sampler.getScore(keyTxnTwo));
// First one noticed should win
List<TransactionTrace> traces = sampler.harvest(APP_NAME);
TransactionTrace transactionTrace = traces.get(0);
assertEquals("keyTxnOne", transactionTrace.getRequestUri());
sampler.noticeTransaction(keyTxnTwo);
sampler.noticeTransaction(keyTxnOne);
transactionTrace = sampler.harvest(APP_NAME).get(0);
assertEquals("keyTxnTwo", transactionTrace.getRequestUri());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class RandomTransactionSamplerTest method samplerChecksForMatchingAppName.
@Test
public void samplerChecksForMatchingAppName() throws Exception {
ITransactionSampler transactionSampler = new RandomTransactionSampler(5);
long durationInMillis = 5000L;
TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
td = createTransactionData("/en/betting/Football/*", durationInMillis + 100L);
Assert.assertFalse(transactionSampler.noticeTransaction(td));
List<TransactionTrace> traces = transactionSampler.harvest("Bogus");
Assert.assertEquals(0, traces.size());
traces = transactionSampler.harvest(APP_NAME);
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
}
use of com.newrelic.agent.TransactionData in project newrelic-java-agent by newrelic.
the class TransactionTraceBucketTest method topN2.
@Test
public void topN2() throws Exception {
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttMap = createConfigMap();
ttMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 0.5f);
ttMap.put(TransactionTracerConfigImpl.TOP_N, 2);
configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttMap);
createServiceManager(configMap);
ITransactionSampler transactionSampler = new TransactionTraceSampler();
long durationInMillis = 1000L;
TransactionData td = createTransactionData("/en/betting/Football/*", durationInMillis);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
List<TransactionTrace> traces = transactionSampler.harvest(APP_NAME);
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/en/betting/Football/*", traces.get(0).getRequestUri());
Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
td = createTransactionData("/en/betting/Football/*", durationInMillis);
Assert.assertFalse(transactionSampler.noticeTransaction(td));
td = createTransactionData("/de/betting/Chess/*", durationInMillis);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
traces = transactionSampler.harvest(APP_NAME);
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/de/betting/Chess/*", traces.get(0).getRequestUri());
Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
td = createTransactionData("/en/betting/Football/*", durationInMillis);
Assert.assertFalse(transactionSampler.noticeTransaction(td));
td = createTransactionData("/de/betting/Chess/*", durationInMillis);
Assert.assertFalse(transactionSampler.noticeTransaction(td));
td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
traces = transactionSampler.harvest(APP_NAME);
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/ru/betting/Motorsport/*", traces.get(0).getRequestUri());
Assert.assertEquals(durationInMillis, traces.get(0).getDuration());
td = createTransactionData("/en/betting/Football/*", durationInMillis - 200L);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
td = createTransactionData("/en/betting/Football/*", durationInMillis - 100L);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis);
Assert.assertFalse(transactionSampler.noticeTransaction(td));
td = createTransactionData("/ru/betting/Motorsport/*", durationInMillis + 100L);
Assert.assertTrue(transactionSampler.noticeTransaction(td));
traces = transactionSampler.harvest(APP_NAME);
Assert.assertEquals(1, traces.size());
Assert.assertEquals("/ru/betting/Motorsport/*", traces.get(0).getRequestUri());
Assert.assertEquals(durationInMillis + 100L, traces.get(0).getDuration());
}
Aggregations