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