Search in sources :

Example 91 with TransactionStats

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

the class DefaultTracerTest method testDatastoreParametersNoHost.

@Test
public void testDatastoreParametersNoHost() {
    DefaultTracer tracer = prepareTracer();
    TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
    tracer.reportAsExternal(DatastoreParameters.product("Product").collection("collection").operation("operation").instance(null, 91929).build());
    tracer.recordMetrics(stats);
    checkUnknownDatastoreSupportabilityMetrics("Product", 1, 0, 1);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Test(org.junit.Test)

Example 92 with TransactionStats

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsMultipleServersSomeMissingServerNames.

@Test
public void requestXStartHeaderRecordMetricsMultipleServersSomeMissingServerNames() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    long requestStartTimeInMicroseconds1 = nowInMicroseconds - 30000;
    long requestStartTimeInMicroseconds2 = nowInMicroseconds - 20000;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "t=" + requestStartTimeInMicroseconds1 + "server2 t=" + requestStartTimeInMicroseconds2);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    float expected1 = (float) (requestStartTimeInMicroseconds2 - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
    float expected2 = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds2) / TimeConversion.MICROSECONDS_PER_SECOND;
    float expectedTotal = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
    TransactionStats statsEngine = new TransactionStats();
    dispatcher.recordHeaderMetrics(statsEngine);
    String spec = MetricName.QUEUE_TIME.getName();
    Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
    assertDelta(expectedTotal, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
    Assert.assertEquals(1, statsEngine.getSize());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 93 with TransactionStats

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

the class BasicRequestDispatcherTracerTest method before.

@Before
public void before() throws Exception {
    Map<String, Object> configMap = createConfigMap(0);
    createServiceManager(AgentConfigImpl.createAgentConfig(configMap), configMap);
    Transaction.clearTransaction();
    stats = new TransactionStats();
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Before(org.junit.Before)

Example 94 with TransactionStats

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsNegativeValue.

@Test
public void requestXStartHeaderRecordMetricsNegativeValue() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long requestStartTimeInMillis = (Transaction.getTransaction().getWallClockStartTimeMs() - 100) * -1;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMillis);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    TransactionStats statsEngine = new TransactionStats();
    dispatcher.recordHeaderMetrics(statsEngine);
    Assert.assertEquals(0, statsEngine.getSize());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 95 with TransactionStats

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

the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetrics.

@Test
public void requestXStartHeaderRecordMetrics() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    long requestStartTimeInMicroseconds = nowInMicroseconds - 10000;
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMicroseconds);
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
    float expected = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds) / TimeConversion.MICROSECONDS_PER_SECOND;
    TransactionStats statsEngine = new TransactionStats();
    dispatcher.recordHeaderMetrics(statsEngine);
    String spec = MetricName.QUEUE_TIME.getName();
    Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
    assertDelta(expected, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
    Assert.assertEquals(1, statsEngine.getUnscopedStats().getStatsMap().size());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Aggregations

TransactionStats (com.newrelic.agent.stats.TransactionStats)104 Test (org.junit.Test)90 TransactionData (com.newrelic.agent.TransactionData)40 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 Tracer (com.newrelic.agent.tracers.Tracer)15 HashMap (java.util.HashMap)14 SpanEvent (com.newrelic.agent.model.SpanEvent)13 TransactionService (com.newrelic.agent.TransactionService)12 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)11 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)11 ArrayList (java.util.ArrayList)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Map (java.util.Map)9 Transaction (com.newrelic.agent.Transaction)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)7 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JSONArray (org.json.simple.JSONArray)5