use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class ApiTest method testSetRequestAndResponse.
@Test
public void testSetRequestAndResponse() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
tracer.finish(0, null);
Assert.assertEquals(1, txList.size());
Assert.assertEquals("/mytest", txList.get(0).getRequestUri(AgentConfigImpl.ATTRIBUTES));
TransactionStats stats = apiTestHelper.tranStats;
ResponseTimeStats dispatcherStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("HttpDispatcher");
Assert.assertEquals(1, dispatcherStats.getCallCount());
Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats("WebTransaction/Uri/mytest").getCallCount());
Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex/Uri/mytest").getApdexSatisfying());
Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex").getApdexSatisfying());
Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.WEB_TRANSACTION).getCallCount());
Assert.assertEquals(0, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.OTHER_TRANSACTION_ALL).getCallCount());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class KafkaTest method produceConsumeTest.
@Test
public void produceConsumeTest() throws Exception {
EnvironmentHolderSettingsGenerator envHolderSettings = new EnvironmentHolderSettingsGenerator(CONFIG_FILE, "all_enabled_test", CLASS_LOADER);
EnvironmentHolder holder = new EnvironmentHolder(envHolderSettings);
holder.setupEnvironment();
kafkaUnitRule.getKafkaUnit().createTopic(testTopic, 1);
final KafkaConsumer<String, String> consumer = setupConsumer();
final CountDownLatch latch = new CountDownLatch(1);
final ConcurrentLinkedQueue<TransactionData> finishedTransactions = new ConcurrentLinkedQueue<>();
TransactionListener transactionListener = new TransactionListener() {
@Override
public void dispatcherTransactionFinished(TransactionData transactionData, TransactionStats transactionStats) {
finishedTransactions.add(transactionData);
latch.countDown();
}
};
ServiceFactory.getTransactionService().addTransactionListener(transactionListener);
try {
produceMessage();
final Future<?> submit = executorService.submit(new Runnable() {
@Override
public void run() {
consumeMessage(consumer);
}
});
submit.get(30, TimeUnit.SECONDS);
latch.await(30, TimeUnit.SECONDS);
Assert.assertEquals(2, finishedTransactions.size());
// Wait for the metrics reporter
Thread.sleep(1000);
// Assert on the kafka metrics that we're expecting
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName());
Stats messagesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-fetch-manager-metrics/records-consumed-rate");
Assert.assertNotNull(messagesConsumed);
Assert.assertTrue(messagesConsumed.getCallCount() > 1);
Assert.assertTrue(messagesConsumed.getTotal() > 0);
Stats bytesConsumed = statsEngine.getStats("MessageBroker/Kafka/Internal/consumer-metrics/incoming-byte-rate");
Assert.assertNotNull(bytesConsumed);
Assert.assertTrue(bytesConsumed.getCallCount() > 1);
Assert.assertTrue(bytesConsumed.getTotal() > 0);
Stats rebalanceAssignedPartition = statsEngine.getStats("MessageBroker/Kafka/Rebalance/Assigned/" + testTopic + "/0");
Assert.assertNotNull(rebalanceAssignedPartition);
Assert.assertEquals(1, rebalanceAssignedPartition.getCallCount());
Stats serializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Serialization/TestTopic");
Assert.assertNotNull(serializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, serializationByTopic.getCallCount());
Assert.assertTrue(serializationByTopic.getTotal() > 1);
Stats deserializationByTopic = statsEngine.getStats("MessageBroker/Kafka/Deserialization/TestTopic");
Assert.assertNotNull(deserializationByTopic);
// One for the key, one for the value
Assert.assertEquals(2, deserializationByTopic.getCallCount());
Assert.assertTrue(deserializationByTopic.getTotal() > 1);
// external reporting test
TransactionData prodTxn = finishedTransactions.poll();
Collection<Tracer> tracers = prodTxn.getTracers();
Iterator<Tracer> iterator = tracers.iterator();
Assert.assertTrue(iterator.hasNext());
Tracer tracer = iterator.next();
Assert.assertEquals("MessageBroker/Kafka/Topic/Produce/Named/TestTopic", tracer.getMetricName());
TransactionData conTxn = finishedTransactions.poll();
Tracer rootTracer = conTxn.getRootTracer();
Assert.assertEquals("MessageBroker/Kafka/Topic/Consume/Named/TestTopic", rootTracer.getMetricName());
Assert.assertNotNull(conTxn.getInboundDistributedTracePayload());
} finally {
ServiceFactory.getTransactionService().removeTransactionListener(transactionListener);
consumer.close();
}
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DatastoreForTransactionTest method testcheckDatastoresInvalid.
@Test
public void testcheckDatastoresInvalid() {
TransactionStats stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
Collection<DatastoreRequestImpl> actual = DatastoreForTransaction.checkDatastores(true, stats);
Assert.assertEquals(0, actual.size());
stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
actual = DatastoreForTransaction.checkDatastores(true, stats);
Assert.assertEquals(0, actual.size());
stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
actual = DatastoreForTransaction.checkDatastores(true, stats);
Assert.assertEquals(0, actual.size());
stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
actual = DatastoreForTransaction.checkDatastores(true, stats);
Assert.assertEquals(0, actual.size());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DatastoreForTransactionTest method testAddDatastoresTwoCallsSameMetrics.
@Test
public void testAddDatastoresTwoCallsSameMetrics() {
TransactionStats stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
DatastoreForTransaction exts = new DatastoreForTransaction();
exts.addDatastore(true, stats);
stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/mysql/allWeb").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getScopedStats().getOrCreateResponseTimeStats("Datastore/statement/mysql/table/select").recordResponseTime(10, TimeUnit.MILLISECONDS);
exts.addDatastore(true, stats);
Collection<DataStoreRequest> actual = exts.getDatastores();
Assert.assertEquals(1, actual.size());
Iterator<DataStoreRequest> it = actual.iterator();
DatastoreRequestImpl impl = (DatastoreRequestImpl) it.next();
Assert.assertEquals(2, impl.getCount());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DatastoreForTransactionTest method testHasDatastores.
@Test
public void testHasDatastores() {
TransactionStats stats = new TransactionStats();
stats.getUnscopedStats().getOrCreateResponseTimeStats("Unscoped/other").recordResponseTime(10, TimeUnit.MILLISECONDS);
stats.getUnscopedStats().getOrCreateResponseTimeStats("Another/another").recordResponseTime(10, TimeUnit.MILLISECONDS);
Assert.assertFalse(DatastoreForTransaction.hasDatastores(stats));
stats.getUnscopedStats().getOrCreateResponseTimeStats("Datastore/all").recordResponseTime(10, TimeUnit.MILLISECONDS);
Assert.assertTrue(DatastoreForTransaction.hasDatastores(stats));
}
Aggregations