Search in sources :

Example 1 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.

the class SegmentTest method testMetricMigrationAsync.

@Test
public void testMetricMigrationAsync() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
    segment.getTracedMethod().addRollupMetricName("rollupMetric");
    Thread finishThread = new Thread(new Runnable() {

        @Override
        public void run() {
            segment.getTracedMethod().addRollupMetricName("rollupMetric2");
            segment.end();
        }
    });
    finishThread.start();
    finishThread.join();
    root.finish(Opcodes.ARETURN, null);
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    ResponseTimeStats rollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric");
    assertEquals(1, rollupMetric.getCallCount());
    ResponseTimeStats exclusiveRollupMetric = root.getTransactionActivity().getTransactionStats().getUnscopedStats().getOrCreateResponseTimeStats("rollupMetric2");
    assertEquals(1, exclusiveRollupMetric.getCallCount());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 2 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.

the class DefaultTracerTest method checkInstanceMetric.

/**
 * @param host Host to report.
 * @param port Port to report.
 * @param expectedHost expected host in instance metric.
 * @param expectedInstanceID expected identifier in instance metric.
 */
public void checkInstanceMetric(String product, String host, Integer port, String expectedHost, String expectedInstanceID) {
    DefaultTracer tracer = prepareTracer();
    final TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
    tracer.reportAsExternal(DatastoreParameters.product(product).collection("MyCollection").operation("operation").instance(host, port).build());
    tracer.finish(0, null);
    ResponseTimeStats responseTimeStats = stats.getUnscopedStats().getOrCreateResponseTimeStats(String.format("Datastore/instance/DB/%s/%s", expectedHost, expectedInstanceID));
    assertEquals(responseTimeStats.getCallCount(), 1);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats)

Example 3 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.

the class AsyncTracerTestEdgeCaseThree method testAsyncEqualsTrue.

@Test
public void testAsyncEqualsTrue() throws InterruptedException {
    Thread secondThread = Txn();
    System.out.println("Awaiting termination");
    secondThread.join();
    // Wait for Transaction to finish (due to Token expiration on separate thread)
    Thread.sleep(5000);
    verifyScopedMetricsPresent("OtherTransaction/Custom/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree/Txn", "Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree/Txn", "Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree$1/tracerOne");
    ResponseTimeStats tracerOneStats = getStats().getScopedStats().getOrCreateResponseTimeStats("Java/com.newrelic.agent.async.AsyncTracerTestEdgeCaseThree$1/tracerOne");
    Assert.assertNotNull("No stats for tracerOne", tracerOneStats);
    // first invocation of tracerOne (3) is outside tracked transaction.
    Assert.assertEquals("tracerOne was called a different number of times", 1, tracerOneStats.getCallCount());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Test(org.junit.Test)

Example 4 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.

the class TransactionTimeTest method testTransactionTimesOtherTransaction.

@Test
public void testTransactionTimesOtherTransaction() throws InterruptedException {
    doWork();
    // verify count on stats
    Assert.assertNotNull(stats);
    ResponseTimeStats stat = stats.getScopedStats().getOrCreateResponseTimeStats("Custom/test.newrelic.test.agent.TransactionTimeTest/hello1");
    Assert.assertNotNull(stat);
    Assert.assertEquals(1, stat.getCallCount());
    stat = stats.getScopedStats().getOrCreateResponseTimeStats("Custom/test.newrelic.test.agent.TransactionTimeTest/hello2");
    Assert.assertNotNull(stat);
    Assert.assertEquals(1, stat.getCallCount());
    // verify total time
    double expected = data.getRootTracer().getDuration() / 1000000000.0;
    Assert.assertEquals(expected, stats.getUnscopedStats().getOrCreateResponseTimeStats("OtherTransaction/Custom/test.newrelic.test.agent.TransactionTimeTest/doWork").getTotal(), .001);
    Assert.assertEquals(expected, stats.getUnscopedStats().getOrCreateResponseTimeStats("OtherTransactionTotalTime/Custom/test.newrelic.test.agent.TransactionTimeTest/doWork").getTotal(), .001);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Test(org.junit.Test)

Example 5 with ResponseTimeStats

use of com.newrelic.agent.stats.ResponseTimeStats in project newrelic-java-agent by newrelic.

the class AgentTest method ttSizeLimitExceeded.

/**
 * If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
 * transaction trace.
 */
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
    TransactionDataList txs = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txs);
    TestSizeLimitServlet servlet = new TestSizeLimitServlet();
    String path = "/my/word";
    AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
    StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
    MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
    ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
    Assert.assertEquals(2, stats.getCallCount());
    Assert.assertEquals(2, txs.size());
    TransactionData transactionData = txs.get(1);
    Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
    Assert.assertEquals(3, tracers.size());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) MetricName(com.newrelic.agent.metric.MetricName) TransactionDataList(com.newrelic.agent.TransactionDataList) Tracer(com.newrelic.agent.tracers.Tracer) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)28 Test (org.junit.Test)20 Transaction (com.newrelic.agent.Transaction)9 StatsBase (com.newrelic.agent.stats.StatsBase)9 Tracer (com.newrelic.agent.tracers.Tracer)9 TokenImpl (com.newrelic.agent.TokenImpl)6 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)6 TransactionStats (com.newrelic.agent.stats.TransactionStats)6 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)4 StatsEngine (com.newrelic.agent.stats.StatsEngine)3 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 TransactionDataList (com.newrelic.agent.TransactionDataList)2 ExitTracer (com.newrelic.agent.bridge.ExitTracer)2 MetricName (com.newrelic.agent.metric.MetricName)2 Stats (com.newrelic.agent.stats.Stats)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)2 Trace (com.newrelic.api.agent.Trace)2 MockServiceManager (com.newrelic.agent.MockServiceManager)1