use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsMultipleServers.
@Test
public void requestXStartHeaderRecordMetricsMultipleServers() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds1 = nowInMicroseconds - 30000;
long requestStartTimeInMicroseconds2 = nowInMicroseconds - 20000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMicroseconds1 + "server2 t=" + requestStartTimeInMicroseconds2);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
float expected1 = (float) (requestStartTimeInMicroseconds2 - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
float expected2 = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds2) / TimeConversion.MICROSECONDS_PER_SECOND;
float expectedTotal = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
String spec = MetricName.QUEUE_TIME.getName();
Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
assertDelta(expectedTotal, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
Assert.assertEquals(1, statsEngine.getSize());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartAndXQueueHeaderRecordMetrics.
@Test
public void requestXStartAndXQueueHeaderRecordMetrics() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds = nowInMicroseconds - 30000;
long queueStartTimeInMicroseconds = nowInMicroseconds - 10000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMicroseconds);
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMicroseconds);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
float expectedQueueTime = (float) (nowInMicroseconds - queueStartTimeInMicroseconds) / TimeConversion.MICROSECONDS_PER_SECOND;
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
String spec = MetricName.QUEUE_TIME.getName();
Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
assertDelta(expectedQueueTime, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .01);
Assert.assertEquals(1, statsEngine.getSize());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method txnFinished.
@Test
public void txnFinished() {
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
TransactionStats transactionStats = new TransactionStats();
Map<String, Object> intrinsicAttributes = new HashMap<>();
long startTimeInMillis = System.currentTimeMillis();
long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, null);
distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
String responseTime = MessageFormat.format(MetricNames.DURATION_BY_PARENT_UNKNOWN_ALL, "HTTPS");
String errors = MessageFormat.format(MetricNames.ERRORS_BY_PARENT_UNKNOWN, "HTTPS");
assertEquals(1.35, unscopedStats.getOrCreateResponseTimeStats(responseTime).getTotal(), 0.01f);
assertEquals(1, unscopedStats.getStats(errors).getCallCount());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class ApiCallingAsyncTest method testNaming1.
@Test(timeout = 10000)
public void testNaming1() throws Exception {
final Request req = new Request() {
@Override
public HeaderType getHeaderType() {
return null;
}
@Override
public String getHeader(String name) {
return null;
}
@Override
public String getRequestURI() {
return null;
}
@Override
public String getRemoteUser() {
return null;
}
@Override
public Enumeration<?> getParameterNames() {
return null;
}
@Override
public String[] getParameterValues(String name) {
return null;
}
@Override
public Object getAttribute(String name) {
return null;
}
@Override
public String getCookieValue(String name) {
return null;
}
};
final Response resp = new Response() {
@Override
public HeaderType getHeaderType() {
return null;
}
@Override
public void setHeader(String name, String value) {
}
@Override
public int getStatus() throws Exception {
return 0;
}
@Override
public String getStatusMessage() throws Exception {
return null;
}
@Override
public String getContentType() {
return null;
}
};
// The two threads call APIs in different orders. The purpose of the test is to ensure
// that the same metrics get reported either way.
Thread t1 = new Thread() {
@Override
@Trace(dispatcher = true)
public void run() {
NewRelic.setTransactionName(null, "MyOtherTransaction");
NewRelic.setRequestAndResponse(req, resp);
}
};
t1.start();
t1.join();
TransactionStats s1 = getStats();
Thread t2 = new Thread() {
@Override
@Trace(dispatcher = true)
public void run() {
NewRelic.setRequestAndResponse(req, resp);
NewRelic.setTransactionName(null, "MyOtherTransaction");
}
};
t2.start();
t2.join();
TransactionStats s2 = getStats();
assertSameKeys(s1, s2, new String[] { "Java/com.newrelic.agent.async.ApiCallingAsyncTest\\$\\d/run" });
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class AsyncTest method dispatcherTransactionStatsFinished.
@Override
public void dispatcherTransactionStatsFinished(TransactionData transactionData, TransactionStats transactionStats) {
TransactionStats statsCopy = new TransactionStats();
try {
// Create deep copy of transactionStats object
for (Map.Entry<String, StatsBase> entry : transactionStats.getUnscopedStats().getStatsMap().entrySet()) {
statsCopy.getUnscopedStats().getStatsMap().put(entry.getKey(), (StatsBase) entry.getValue().clone());
}
for (Map.Entry<String, StatsBase> entry : transactionStats.getScopedStats().getStatsMap().entrySet()) {
statsCopy.getScopedStats().getStatsMap().put(entry.getKey(), (StatsBase) entry.getValue().clone());
}
} catch (Exception e) {
statsCopy = transactionStats;
}
timesSet++;
data = transactionData;
stats = statsCopy;
dataList.add(transactionData);
statsList.add(statsCopy);
}
Aggregations