Search in sources :

Example 6 with SimpleStatsEngine

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

the class HibernateStatsTest method insertsAndLoads.

@Trace(dispatcher = true)
@Test
public void insertsAndLoads() {
    runSamplers();
    getTransactionStats().clear();
    Transaction transaction = session.beginTransaction();
    Player dude = new Player();
    dude.setId(nextId++);
    session.save(null, dude);
    Game game = new Game();
    game.setId(nextId++);
    session.save(null, game);
    session.load(Player.class, dude.getId());
    transaction.commit();
    Session session2 = sessionFactory.openSession();
    Criteria criteria = session2.createCriteria(Player.class);
    assertEquals(1, criteria.list().size());
    // getTransactionStats().clear();
    runSamplers();
    SimpleStatsEngine statsEngine = getTransactionStats();
    Stats stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/loads");
    assertEquals(1f, stats.getTotal(), 0);
    statsEngine.getStats("HibernateStatistics/entityLoads");
    assertEquals(1f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/inserts");
    assertEquals(1f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/entityInserts");
    assertEquals(2f, stats.getTotal(), 0);
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/deletes");
    assertEquals(1, stats.getCallCount());
    assertEquals(0f, stats.getTotal(), 0);
    statsEngine = getTransactionStats();
    statsEngine.clear();
    runSamplers();
    stats = statsEngine.getStats("HibernateStatistics/Entity/test.newrelic.test.agent.hibernate.Player/inserts");
    assertEquals(1, stats.getCallCount());
    assertEquals(0f, stats.getTotal(), 0);
}
Also used : Transaction(org.hibernate.Transaction) Stats(com.newrelic.agent.stats.Stats) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) Criteria(org.hibernate.Criteria) Session(org.hibernate.classic.Session) Trace(com.newrelic.api.agent.Trace) Test(org.junit.Test)

Example 7 with SimpleStatsEngine

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

the class OneTestForCriticalPath method verifyMetrics.

private void verifyMetrics() {
    for (int i = 0; i < expectedTxCount; i++) {
        String scope = dataList.get(i).getBlameOrRootMetricName();
        SimpleStatsEngine scopedStats = statsList.get(i).getScopedStats();
        Map<String, StatsBase> actualMetrics = scopedStats.getStatsMap();
        Collection<JsonMetric> expectedM = expectedScopedMetrics.get(scope);
        Assert.assertNotNull(expectedM);
        Assert.assertEquals("Expected metric count did not match actual for scope " + scope, expectedM.size(), actualMetrics.size());
        for (JsonMetric expCurr : expectedM) {
            StatsBase actCurr = actualMetrics.get(expCurr.getMetricName());
            Assert.assertNotNull("The following metric should be present but is not: " + expCurr.getMetricName(), actCurr);
            expCurr.validateMetricExists(actCurr);
        }
        // verify unscoped metrics
        if (expectedUnscopedMetrics.size() > 0) {
            SimpleStatsEngine unscopedStats = statsList.get(i).getUnscopedStats();
            actualMetrics = unscopedStats.getStatsMap();
            for (JsonMetric expCurr : expectedUnscopedMetrics) {
                StatsBase actCurr = actualMetrics.get(expCurr.getMetricName());
                Assert.assertNotNull("The following metric should be present but is not: " + expCurr.getMetricName(), actCurr);
                expCurr.validateMetricExists(actCurr);
            }
        }
    }
}
Also used : SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) StatsBase(com.newrelic.agent.stats.StatsBase)

Example 8 with SimpleStatsEngine

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

the class CrossProcessStateCatApiTest method setUpTransaction.

private void setUpTransaction(Transaction tx, TransactionActivity txa, Object lock, Dispatcher dispatcher, CrossProcessConfig config, String guid) {
    when(txa.getTransaction()).thenReturn(tx);
    when(tx.getLock()).thenReturn(lock);
    when(tx.getDispatcher()).thenReturn(dispatcher);
    when(tx.getCrossProcessConfig()).thenReturn(config);
    DistributedTracePayloadImpl distributedTracePayload = DistributedTracePayloadImpl.createDistributedTracePayload("", "", "", 0f);
    when(tx.createDistributedTracePayload(guid)).thenReturn(distributedTracePayload);
    TransactionStats transactionStats = Mockito.mock(TransactionStats.class);
    SimpleStatsEngine stats = Mockito.mock(SimpleStatsEngine.class);
    when(stats.getOrCreateResponseTimeStats(anyString())).thenReturn(Mockito.mock(ResponseTimeStats.class));
    when(transactionStats.getUnscopedStats()).thenReturn(stats);
    when(txa.getTransactionStats()).thenReturn(transactionStats);
    when(tx.getTransactionActivity()).thenReturn(txa);
    InboundHeaders headers = Mockito.mock(InboundHeaders.class);
    InboundHeaderState inboundHeaderState = new InboundHeaderState(tx, headers);
    when(tx.getInboundHeaderState()).thenReturn(inboundHeaderState);
    PriorityTransactionName priorityTransactionName = PriorityTransactionName.create("Something/Or/other", "category", TransactionNamePriority.FRAMEWORK);
    when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
    TransactionCounts txnCounts = Mockito.mock(TransactionCounts.class);
    when(txnCounts.isOverTracerSegmentLimit()).thenReturn(false);
    when(tx.getTransactionCounts()).thenReturn(txnCounts);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) InboundHeaders(com.newrelic.api.agent.InboundHeaders) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) TransactionCounts(com.newrelic.agent.transaction.TransactionCounts) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl)

Example 9 with SimpleStatsEngine

use of com.newrelic.agent.stats.SimpleStatsEngine 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 10 with SimpleStatsEngine

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

the class TransactionTimesTest method testTransactionTimes.

@Test
public void testTransactionTimes() throws InterruptedException {
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer root = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(root);
    DefaultTracer tracer1 = createDefaultTraer("hello1");
    tx.getTransactionActivity().tracerStarted(tracer1);
    DefaultTracer tracer2 = createDefaultTraer("hello2");
    tx.getTransactionActivity().tracerStarted(tracer2);
    Thread.sleep(10);
    tracer2.finish(0, null);
    tracer1.finish(0, null);
    root.finish(0, null);
    Assert.assertNotNull(stats);
    SimpleStatsEngine unscoped = stats.getUnscopedStats();
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransaction/all"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/all"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransaction/myMetricName"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/myMetricName"));
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransaction/all").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransaction/myMetricName").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/myMetricName").getCallCount());
    SimpleStatsEngine scoped = stats.getScopedStats();
    Assert.assertNotNull(scoped.getOrCreateResponseTimeStats("Java/com.newrelic.agent.transaction.TransactionTimesTest/dude"));
    Assert.assertEquals(1, scoped.getOrCreateResponseTimeStats("Java/com.newrelic.agent.transaction.TransactionTimesTest/dude").getCallCount());
    Assert.assertEquals(root.getDuration(), tx.getTransactionTimer().getTotalSumTimeInNanos());
    Assert.assertEquals(root.getDuration(), tx.getTransactionTimer().getResponseTimeInNanos());
    Assert.assertEquals(1, tx.getFinishedChildren().size());
}
Also used : Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Aggregations

SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)12 TransactionStats (com.newrelic.agent.stats.TransactionStats)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Transaction (com.newrelic.agent.Transaction)2 TransactionData (com.newrelic.agent.TransactionData)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)2 DistributedTracePayloadBuilder (com.newrelic.agent.DistributedTracePayloadBuilder)1 MetricData (com.newrelic.agent.MetricData)1 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 CountStats (com.newrelic.agent.stats.CountStats)1 Stats (com.newrelic.agent.stats.Stats)1 StatsBase (com.newrelic.agent.stats.StatsBase)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 TransactionCounts (com.newrelic.agent.transaction.TransactionCounts)1