Search in sources :

Example 6 with ResponseTimeStats

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

the class CrossProcessStateTest method processOutboundResponseHeaders.

@Test
public void processOutboundResponseHeaders() {
    String incomingId = "6#66";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"TestTransaction\\/name\",0.0,0.0,12345,\"5001D\",false]", encodingKey);
    cps.processOutboundResponseHeaders(null, 0);
    TransactionStats txStats = mock(TransactionStats.class);
    TransactionActivity ta = mock(TransactionActivity.class);
    when(tx.getTransactionActivity()).thenReturn(ta);
    when(ta.getTransactionStats()).thenReturn(txStats);
    SimpleStatsEngine statsEngine = mock(SimpleStatsEngine.class);
    when(txStats.getUnscopedStats()).thenReturn(statsEngine);
    ResponseTimeStats stats = mock(ResponseTimeStats.class);
    when(statsEngine.getOrCreateResponseTimeStats(anyString())).thenReturn(stats);
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getClientCrossProcessId()).thenReturn(incomingId);
    when(ihs.isTrustedCatRequest()).thenReturn(true);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    AgentConfig agentConfig = mock(AgentConfig.class);
    DistributedTracingConfig distributedTracingConfig = mock(DistributedTracingConfig.class);
    when(distributedTracingConfig.isEnabled()).thenReturn(false);
    when(agentConfig.getDistributedTracingConfig()).thenReturn(distributedTracingConfig);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    PriorityTransactionName txName = mock(PriorityTransactionName.class);
    when(tx.getPriorityTransactionName()).thenReturn(txName);
    when(txName.getName()).thenReturn("TestTransaction/name");
    when(tx.getGuid()).thenReturn("5001D");
    when(config.getCrossProcessId()).thenReturn(incomingId);
    cps.processOutboundResponseHeaders(outboundHeaders, 12345);
    verify(outboundHeaders).setHeader(eq("X-NewRelic-App-Data"), eq(obfuscatedAppData));
    cps.processOutboundResponseHeaders(outboundHeaders, 12345);
    verify(outboundHeaders, Mockito.times(2)).getHeaderType();
    verifyNoMoreInteractions(outboundHeaders);
    verify(config, atLeastOnce()).isCrossApplicationTracing();
    verify(config, atLeastOnce()).getCrossProcessId();
    verify(config, atLeastOnce()).getEncodingKey();
    verify(tx, atLeastOnce()).getAgentConfig();
    verify(tx, atLeastOnce()).getCrossProcessConfig();
    verify(tx, atLeastOnce()).getInboundHeaderState();
    verify(tx, atLeastOnce()).isIgnore();
    verify(tx, atLeastOnce()).getLock();
    verify(tx, atLeastOnce()).getGuid();
    verify(tx, atLeastOnce()).freezeTransactionName();
    verify(tx, atLeastOnce()).getRunningDurationInNanos();
    verify(tx, atLeastOnce()).getExternalTime();
    verify(tx, atLeastOnce()).getPriorityTransactionName();
    verify(txName, atLeastOnce()).getName();
    verify(tx, atLeastOnce()).getTransactionActivity();
    verify(ta, atLeastOnce()).getTransactionStats();
    verify(txStats, atLeastOnce()).getUnscopedStats();
    verify(statsEngine, atLeastOnce()).getOrCreateResponseTimeStats(anyString());
    verify(stats, atLeastOnce()).recordResponseTime(anyLong(), any(TimeUnit.class));
    verifyNoMoreInteractions(txStats, statsEngine, stats, txName);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) TimeUnit(java.util.concurrent.TimeUnit) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with ResponseTimeStats

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

the class CrossProcessTransactionStateImplTest method testAppDataHeader.

@Test
public void testAppDataHeader() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String txGuid = "5001D";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, "12345");
    stats = new TransactionStats();
    configureTestMocks(encodingKey, txGuid, obfuscatedAppData, request);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    crossProcessTransactionState.writeResponseHeaders();
    verifyMocks(obfuscatedAppData);
    assertEquals(1, stats.getUnscopedStats().getSize());
    ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
    assertEquals(1, clientAppStats.getCallCount());
    assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
    assertNull(tx.getInboundHeaderState().getReferrerGuid());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with ResponseTimeStats

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

the class CrossProcessTransactionStateImplTest method testNoContentLengthNoQueueTime.

@Test
public void testNoContentLengthNoQueueTime() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String txGuid = "5001D";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",0.0,0.2,-1,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, null);
    doNothing().when(response).setHeader("X-NewRelic-App-Data", obfuscatedAppData);
    configureCatEnabled(encodingKey, true);
    mockDispatcher(request);
    mockConfigFromTransaction();
    mockBasicTransactionMethods();
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getRequestContentLength()).thenReturn(-1L);
    when(ihs.getReferrerGuid()).thenReturn(null);
    when(ihs.isTrustedCatRequest()).thenReturn(true);
    when(ihs.getClientCrossProcessId()).thenReturn(incomingId);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    doNothing().when(tx).freezeTransactionName();
    when(tx.getExternalTime()).thenReturn(0L);
    PriorityTransactionName txName = PriorityTransactionName.create("WebTransaction/test/test", null, TransactionNamePriority.JSP);
    when(tx.getPriorityTransactionName()).thenReturn(txName);
    when(tx.getTransactionActivity()).thenReturn(ta);
    doNothing().when(ta).markAsResponseSender();
    when(ta.getTransactionStats()).thenReturn(stats);
    long durationInNanos = TimeUnit.NANOSECONDS.convert(200L, TimeUnit.MILLISECONDS);
    when(tx.getRunningDurationInNanos()).thenReturn(durationInNanos);
    when(tx.getGuid()).thenReturn(txGuid);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    verifyMocks(obfuscatedAppData);
    assertEquals(1, stats.getUnscopedStats().getSize());
    ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
    assertEquals(1, clientAppStats.getCallCount());
    assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with ResponseTimeStats

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

the class TransactionAsyncRootFirstTest method testStartAndThenLinkMultipleDiffTokensExpireAll.

@Test
public void testStartAndThenLinkMultipleDiffTokensExpireAll() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token1 = (TokenImpl) tx.getToken();
    TokenImpl token2 = (TokenImpl) tx.getToken();
    rootTracer.finish(Opcodes.RETURN, 0);
    StartAndThenLink activity1 = new StartAndThenLink(token1, false, false);
    activity1.start();
    activity1.join();
    StartAndThenLink activity2 = new StartAndThenLink(token2, false, false);
    activity2.start();
    activity2.join();
    tx.expireAllTokensForCurrentTransaction();
    waitForTransaction();
    TransactionAsyncUtility.basicDataVerify(data, stats, activity1, 3);
    Map<String, StatsBase> scoped = stats.getScopedStats().getStatsMap();
    ResponseTimeStats data1 = (ResponseTimeStats) scoped.get("RequestDispatcher");
    ResponseTimeStats data2 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token1.toString());
    ResponseTimeStats data3 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token2.toString());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    Assert.assertNotNull(data3);
    Assert.assertEquals(1, data1.getCallCount());
    Assert.assertEquals(1, data2.getCallCount());
    Assert.assertEquals(1, data3.getCallCount());
    Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
    Assert.assertEquals(((ResponseTimeStats) unscoped.get("WebTransactionTotalTime")).getTotal(), data1.getTotal() + data2.getTotal() + data3.getTotal(), .001);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Transaction(com.newrelic.agent.Transaction) TokenImpl(com.newrelic.agent.TokenImpl) Tracer(com.newrelic.agent.tracers.Tracer) StartAndThenLink(com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink) StatsBase(com.newrelic.agent.stats.StatsBase) Test(org.junit.Test)

Example 10 with ResponseTimeStats

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

the class TransactionAsyncRootFirstTest method testStartAndThenLinkMultipleDiffTokens.

@Test
public void testStartAndThenLinkMultipleDiffTokens() throws InterruptedException {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction();
    Tracer rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "hi");
    tx.getTransactionActivity().tracerStarted(rootTracer);
    TokenImpl token1 = (TokenImpl) tx.getToken();
    TokenImpl token2 = (TokenImpl) tx.getToken();
    rootTracer.finish(Opcodes.RETURN, 0);
    StartAndThenLink activity1 = new StartAndThenLink(token1, true, false);
    activity1.start();
    activity1.join();
    StartAndThenLink activity2 = new StartAndThenLink(token2, false, true);
    activity2.start();
    activity2.join();
    waitForTransaction();
    TransactionAsyncUtility.basicDataVerify(data, stats, activity1, 3);
    Map<String, StatsBase> scoped = stats.getScopedStats().getStatsMap();
    ResponseTimeStats data1 = (ResponseTimeStats) scoped.get("RequestDispatcher");
    ResponseTimeStats data2 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token1.toString());
    ResponseTimeStats data3 = (ResponseTimeStats) scoped.get("Java/java.lang.Object/root" + token2.toString());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    Assert.assertNotNull(data3);
    Assert.assertEquals(1, data1.getCallCount());
    Assert.assertEquals(1, data2.getCallCount());
    Assert.assertEquals(1, data3.getCallCount());
    Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
    Assert.assertEquals(((ResponseTimeStats) unscoped.get("WebTransactionTotalTime")).getTotal(), data1.getTotal() + data2.getTotal() + data3.getTotal(), .001);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Transaction(com.newrelic.agent.Transaction) TokenImpl(com.newrelic.agent.TokenImpl) Tracer(com.newrelic.agent.tracers.Tracer) StartAndThenLink(com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink) StatsBase(com.newrelic.agent.stats.StatsBase) 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