use of com.newrelic.agent.stats.SimpleStatsEngine in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method txnFinishedInboundPayload.
@Test
public void txnFinishedInboundPayload() {
Map<String, Object> connectInfo = new HashMap<>();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
TransactionStats transactionStats = new TransactionStats();
Map<String, Object> intrinsicAttributes = new HashMap<>();
long payloadSendTimestamp = 1002000;
long startTimeInMillis = 1005000;
long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
String json = new DistributedTracePayloadBuilder().setTimestamp(payloadSendTimestamp).setHost("datanerd.us.com").setParentType("Browser").setAccountId("123456").setTrustKey("67890").setApplicationId("6789").setTransactionId("badcafe3").setTripId("cattrip").setPriority(0.0f).setDepth(0).setSyntheticsJob(null).setSyntheticsMonitor(null).setSyntheticsResource(null).createJsonPayload();
DistributedTracePayloadImpl payload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), distributedTraceService, Agent.LOG).parse(null, json);
TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, payload);
distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
assertEquals(1.35f, unscopedStats.getOrCreateResponseTimeStats("DurationByCaller/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
assertEquals(3.0f, unscopedStats.getOrCreateResponseTimeStats("TransportDuration/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
}
use of com.newrelic.agent.stats.SimpleStatsEngine 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.SimpleStatsEngine in project newrelic-java-agent by newrelic.
the class AsyncTest method verifyCustomUnscopedMetric.
public void verifyCustomUnscopedMetric(String name, int count) {
verifyUnscopedMetricsPresentIgnoringValues(stats, name);
SimpleStatsEngine engine = stats.getUnscopedStats();
Assert.assertNotNull(engine);
Assert.assertEquals(count, engine.getStats(name).getCallCount());
}
use of com.newrelic.agent.stats.SimpleStatsEngine in project newrelic-java-agent by newrelic.
the class IntrospectorStatsService method getUnscopedMetrics.
public Map<String, TracedMetricData> getUnscopedMetrics() {
SimpleStatsEngine unscoped = engine.getUnscopedStatsForTesting();
Map<String, TracedMetricData> unscopedMetricMap = convertToTracedMetric(unscoped);
// copies of scoped metrics -> unscoped
List<MetricData> allScopedMetricData = new ArrayList<>();
for (Entry<String, SimpleStatsEngine> entry : engine.getScopedStatsForTesting().entrySet()) {
allScopedMetricData.addAll(entry.getValue().getMetricData(metricNormalizer, entry.getKey()));
}
List<MetricData> unscopedCopies = StatsEngineImpl.createUnscopedCopies(metricNormalizer, allScopedMetricData);
for (MetricData unscopedCopy : unscopedCopies) {
if (unscopedCopy.getStats() instanceof CountStats) {
String metricName = unscopedCopy.getMetricName().getName();
TracedMetricData data = TracedMetricImpl.getTracedMetricFromStatsBase(metricName, (CountStats) unscopedCopy.getStats());
unscopedMetricMap.put(metricName, data);
}
}
return unscopedMetricMap;
}
use of com.newrelic.agent.stats.SimpleStatsEngine in project newrelic-java-agent by newrelic.
the class IntrospectorStatsService method getScopedMetrics.
public Map<String, TracedMetricData> getScopedMetrics(String transactionName) {
Map<String, SimpleStatsEngine> data = engine.getScopedStatsForTesting();
SimpleStatsEngine txEngine = data.get(transactionName);
if (txEngine == null) {
throw new IllegalArgumentException("no such transaction: " + transactionName);
}
return convertToTracedMetric(txEngine);
}
Aggregations