use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreClassesFallback.
@Test
public void ignoreClassesFallback() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("ignore_classes_fallback_test");
try {
try {
throwException(new IgnoredError("blah"));
fail("The ignored exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreSuperclassMessages.
@Test
public void ignoreSuperclassMessages() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("ignore_superclass_messages_test");
try {
try {
throwException(new IgnoredError("blah"));
fail("The ignored exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
// yml is configured to ignore the superclass Exception, shouldn't apply to subclass IgnoredError
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class ApiTest method testNoExceptionRecordMetricNoTransaction.
@Test
public void testNoExceptionRecordMetricNoTransaction() throws Exception {
final MetricName name = MetricName.create("roger");
StatsWork statsWork = new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
statsEngine.getApdexStats(name);
try {
statsEngine.getStats(name);
Assert.fail("expected java.lang.RuntimeException");
} catch (RuntimeException e) {
// expected
}
}
@Override
public String getAppName() {
return null;
}
};
ServiceFactory.getStatsService().doStatsWork(statsWork, "statsWorkName");
NewRelic.recordMetric(name.getName(), 1.0f);
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class TransactionDispatcherTest method testSetResponseOnly.
@Test
public void testSetResponseOnly() {
Transaction tx = Transaction.getTransaction(true);
/* Start a tracer and end it so that the transaction runs the dispatcher
transactionActivityWithResponseFinished code
*/
OtherRootTracer rootTracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), null, new SimpleMetricNameFormat(""));
tx.getTransactionActivity().tracerStarted(rootTracer);
MockHttpResponse response = new MockHttpResponse();
response.setResponseStatus(418);
response.setResponseStatusMessage("tea");
tx.setWebResponse(response);
rootTracer.finish(null);
assertEquals(418, tx.getStatus());
assertEquals("tea", tx.getStatusMessage());
// Make sure the status code was set in time for the Apdex calculation.
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(tx.getApplicationName());
assertEquals(1, statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX)).getApdexFrustrating());
}
use of com.newrelic.agent.stats.StatsEngine 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();
}
}
Aggregations