Search in sources :

Example 6 with StatsBase

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

the class DatastoreForTransaction method checkDatastores.

protected static Collection<DatastoreRequestImpl> checkDatastores(boolean isWeb, TransactionStats stats) {
    int totalCount = 0;
    // Datastore/all
    // Datastore/allWeb or Datastore/allOther
    Multimap<String, DatastoreRequestImpl> currentbyDatastore = HashMultimap.create();
    for (Entry<String, StatsBase> current : stats.getScopedStats().getStatsMap().entrySet()) {
        if (current.getKey().startsWith("Datastore/")) {
            DatastoreRequestImpl impl = DatastoreRequestImpl.checkAndMakeDatastore(current.getKey());
            if (impl != null) {
                currentbyDatastore.put(impl.getDatastore(), impl);
                totalCount++;
            }
        }
    }
    // check that unscoped metrics are correct
    if (totalCount > 0) {
        Map<String, StatsBase> unscoped = stats.getUnscopedStats().getStatsMap();
        ResponseTimeStatsImpl all = (ResponseTimeStatsImpl) unscoped.get(ALL);
        ResponseTimeStatsImpl allWebOther = (ResponseTimeStatsImpl) (isWeb ? unscoped.get(ALL_WEB) : unscoped.get(ALL_OTHER));
        if ((all != null) && (all.getCallCount() == totalCount) && (allWebOther != null) && (allWebOther.getCallCount() == totalCount)) {
            // then check the host metrics
            Iterator<Entry<String, Collection<DatastoreRequestImpl>>> it = currentbyDatastore.asMap().entrySet().iterator();
            Entry<String, Collection<DatastoreRequestImpl>> current;
            while (it.hasNext()) {
                current = it.next();
                String prefix = MessageFormat.format(STORE_ALL, current.getKey());
                ResponseTimeStatsImpl hostAll = (ResponseTimeStatsImpl) unscoped.get(prefix);
                ResponseTimeStatsImpl hostWebOther = (ResponseTimeStatsImpl) (isWeb ? unscoped.get(prefix + "Web") : unscoped.get(prefix + "Other"));
                if (hostAll == null || hostWebOther == null || hostAll.getCallCount() != current.getValue().size() || hostWebOther.getCallCount() != current.getValue().size()) {
                    it.remove();
                }
            }
            return currentbyDatastore.values();
        }
    }
    return Collections.emptyList();
}
Also used : Entry(java.util.Map.Entry) Collection(java.util.Collection) StatsBase(com.newrelic.agent.stats.StatsBase) ResponseTimeStatsImpl(com.newrelic.agent.stats.ResponseTimeStatsImpl)

Example 7 with StatsBase

use of com.newrelic.agent.stats.StatsBase 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 StatsBase

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

use of com.newrelic.agent.stats.StatsBase 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)

Example 10 with StatsBase

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

the class TransactionAsyncRootLastTest 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();
    StartAndThenLink activity1 = new StartAndThenLink(token1, true, false);
    activity1.start();
    activity1.join();
    StartAndThenLink activity2 = new StartAndThenLink(token2, false, true);
    activity2.start();
    activity2.join();
    rootTracer.finish(Opcodes.RETURN, 0);
    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

StatsBase (com.newrelic.agent.stats.StatsBase)19 Tracer (com.newrelic.agent.tracers.Tracer)10 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)9 Test (org.junit.Test)9 TokenImpl (com.newrelic.agent.TokenImpl)6 Transaction (com.newrelic.agent.Transaction)6 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)6 ResponseTimeStatsImpl (com.newrelic.agent.stats.ResponseTimeStatsImpl)4 CountStats (com.newrelic.agent.stats.CountStats)3 MetricData (com.newrelic.agent.MetricData)2 MockNormalizer (com.newrelic.agent.MockNormalizer)1 TracedMetricData (com.newrelic.agent.introspec.TracedMetricData)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1