Search in sources :

Example 26 with ResponseTimeStats

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

the class CrossProcessTransactionStateImplTest method testTransactionHeader.

// The following test used to cover the complex logic that tried to decide when to create and
// send GUIDs based on the old "Beacon" logic. Eventually the Browser product replaced this with
// a new and better implementation, so all the Agent support was ripped out sometime after the
// 3.13.0 release of the Agent. This test was modified to suit; so it compiles and executes now,
// and passes, but it's unclear what it's really testing.
@Test
public void testTransactionHeader() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String transactionHeader = "[\"8cd217491c0264d7\",false]";
    String txGuid = "56b0d429ee4730fe";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), Obfuscator.obfuscateNameUsingKey(transactionHeader, encodingKey), "12345");
    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());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 27 with ResponseTimeStats

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

the class DistributedTraceCrossAgentTest method assertExpectedMetrics.

private void assertExpectedMetrics(ArrayList metrics, TransactionStats transactionStats) {
    Assert.assertNotNull(transactionStats);
    for (Object metric : metrics) {
        ArrayList expectedStats = (ArrayList) metric;
        String expectedMetricName = (String) expectedStats.get(0);
        Long expectedMetricCount = (Long) ((JSONArray) metric).get(1);
        final String message = String.format("Expected call count %d for: %s", expectedMetricCount, expectedMetricName);
        if (expectedMetricName.startsWith("Supportability") || expectedMetricName.startsWith("ErrorsByCaller")) {
            Stats actualStat = transactionStats.getUnscopedStats().getStats(expectedMetricName);
            Assert.assertEquals(message, expectedMetricCount.intValue(), actualStat.getCallCount());
        } else {
            ResponseTimeStats actualStat = transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(expectedMetricName);
            Assert.assertEquals(message, expectedMetricCount.intValue(), actualStat.getCallCount());
        }
    }
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) ArrayList(java.util.ArrayList) TransactionStats(com.newrelic.agent.stats.TransactionStats) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) Stats(com.newrelic.agent.stats.Stats) JSONObject(org.json.simple.JSONObject)

Example 28 with ResponseTimeStats

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

the class ThreadStateSamplerTest method testCpuTimeMetrics.

@Test
public void testCpuTimeMetrics() {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.setStatsService(new StatsServiceImpl());
    StatsService statsService = ServiceFactory.getStatsService();
    ThreadStateSampler threadStateSampler = new ThreadStateSampler(ManagementFactory.getThreadMXBean(), ThreadNameNormalizerTest.getThreadNameNormalizer());
    CpuCalculationThread cpuCalculation = new CpuCalculationThread(threadStateSampler);
    cpuCalculation.start();
    try {
        cpuCalculation.join();
    } catch (InterruptedException e) {
    }
    StatsEngine engine = statsService.getStatsEngineForHarvest(null);
    ResponseTimeStats systemTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/SystemTime");
    ResponseTimeStats userTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/UserTime");
    ResponseTimeStats totalTimeStats = engine.getResponseTimeStats("Threads/TotalTime/CALCULATE_CPU/CpuTime");
    // these are approximate times
    float systemTimeSeconds = systemTimeStats.getTotal();
    float userTimeSeconds = userTimeStats.getTotal();
    float totalTimeSeconds = totalTimeStats.getTotal();
    float cpuCalculationTimeSeconds = (float) ((double) cpuCalculation.getCpuTime() / 1000000000) * 10;
    assertTrue("CpuTime: " + cpuCalculationTimeSeconds + ", TotalTime: " + totalTimeSeconds, cpuCalculationTimeSeconds >= totalTimeSeconds);
    assertTrue("UserTime: " + userTimeSeconds + ", SystemTime: " + systemTimeSeconds, userTimeSeconds > systemTimeSeconds);
    // This test is prone to flickering due to high load scenarios and rounding errors, hence the modifier added to totalTimeSeconds
    assertTrue("TotalTime: " + totalTimeSeconds + ", SystemTime: " + systemTimeSeconds + ", UserTime: " + userTimeSeconds, // account for rounding error
    totalTimeSeconds + 4.0 >= systemTimeSeconds + userTimeSeconds);
    // Since we can't guarantee the exact total time, it should be
    // between 1 and 5 (since we had a busywork loop for ~5000ms)
    assertTrue(totalTimeSeconds > 1.0f);
    assertTrue(totalTimeSeconds < 6.0f);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) StatsService(com.newrelic.agent.stats.StatsService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) 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