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();
}
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);
}
}
}
}
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);
}
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);
}
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);
}
Aggregations