Search in sources :

Example 66 with StatsEngine

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 67 with StatsEngine

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 68 with StatsEngine

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);
}
Also used : MetricName(com.newrelic.agent.metric.MetricName) StatsWork(com.newrelic.agent.stats.StatsWork) StatsEngine(com.newrelic.agent.stats.StatsEngine) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 69 with StatsEngine

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) StatsEngine(com.newrelic.agent.stats.StatsEngine) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Test(org.junit.Test)

Example 70 with StatsEngine

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();
    }
}
Also used : TransactionListener(com.newrelic.agent.TransactionListener) EnvironmentHolderSettingsGenerator(test.newrelic.EnvironmentHolderSettingsGenerator) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) CountDownLatch(java.util.concurrent.CountDownLatch) StatsEngine(com.newrelic.agent.stats.StatsEngine) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) Stats(com.newrelic.agent.stats.Stats) TransactionData(com.newrelic.agent.TransactionData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

StatsEngine (com.newrelic.agent.stats.StatsEngine)96 Test (org.junit.Test)78 TransactionDataList (com.newrelic.agent.TransactionDataList)36 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)31 TransactionData (com.newrelic.agent.TransactionData)29 HashMap (java.util.HashMap)25 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 StatsWork (com.newrelic.agent.stats.StatsWork)8 MockRPMService (com.newrelic.agent.MockRPMService)7 ArrayList (java.util.ArrayList)6 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)5 Environment (com.newrelic.agent.environment.Environment)5 MetricName (com.newrelic.agent.metric.MetricName)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Attribute (javax.management.Attribute)5 MBeanServer (javax.management.MBeanServer)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)4 Stats (com.newrelic.agent.stats.Stats)4 HttpError (com.newrelic.agent.transport.HttpError)4 CountStatistic (javax.management.j2ee.statistics.CountStatistic)4