Search in sources :

Example 26 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class Transaction method requestInitialized.

public void requestInitialized(Request request, Response response) {
    Agent.LOG.log(Level.FINEST, "Request initialized: {0}", request.getRequestURI());
    synchronized (requestStateChangeLock) {
        ServiceFactory.getStatsService().doStatsWork(StatsWorks.getIncrementCounterWork(MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_INITIALIZED, 1), MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_INITIALIZED);
        if (this.isFinished()) {
            return;
        }
        if (dispatcher == null) {
            ExitTracer tracer = AgentBridge.instrumentation.createTracer(null, REQUEST_INITIALIZED_CLASS_SIGNATURE_ID, null, REQUEST_TRACER_FLAGS);
            if (tracer != null) {
                if (response == null) {
                    response = DUMMY_RESPONSE;
                }
                setDispatcher(new WebRequestDispatcher(request, response, this));
            }
        } else {
            // JAVA-825. Ignore multiple requestInitialized() callbacks.
            ServiceFactory.getStatsService().doStatsWork(StatsWorks.getIncrementCounterWork(MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_INITIALIZED_STARTED, 1), MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_INITIALIZED_STARTED);
            Agent.LOG.finer("requestInitialized(): transaction already started.");
        }
    }
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher)

Example 27 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.

the class BasicRequestDispatcherTracerTest method testReferrerRequestParameters.

@Test
public void testReferrerRequestParameters() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader("Referer", "HelloThere;JSESSIONID=98279286928?passwd=passwd");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    Assert.assertNull(Transaction.getTransaction().getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME));
    dispatcher.transactionActivityWithResponseFinished();
    Assert.assertEquals("HelloThere", Transaction.getTransaction().getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME));
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 28 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher 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 29 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher 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 30 with WebRequestDispatcher

use of com.newrelic.agent.dispatchers.WebRequestDispatcher 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

WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)55 Test (org.junit.Test)49 TransactionStats (com.newrelic.agent.stats.TransactionStats)11 Transaction (com.newrelic.agent.Transaction)10 ApdexStats (com.newrelic.agent.stats.ApdexStats)4 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)3 Response (com.newrelic.api.agent.Response)3 HashMap (java.util.HashMap)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)2 MockRPMService (com.newrelic.agent.MockRPMService)2 WebResponse (com.newrelic.agent.bridge.WebResponse)2 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 Request (com.newrelic.api.agent.Request)2 Trace (com.newrelic.api.agent.Trace)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 GenericServlet (javax.servlet.GenericServlet)2