use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method transactionSamplersWithSynthetics.
@Test
public void transactionSamplersWithSynthetics() throws Exception {
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 1000f);
createServiceManager(configMap);
TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
// This sampler only saves traces with "baseball" in the tx name
ITransactionSampler transactionSampler = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
if (td.getPriorityTransactionName().getName().contains("baseball")) {
tds.add(td);
return true;
}
return false;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
// This sampler only saves traces with "football" in the tx name
ITransactionSampler transactionSampler2 = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
// football tx's only
if (td.getPriorityTransactionName().getName().contains("football")) {
tds.add(td);
return true;
}
return false;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
// This sampler saves the longest trace it sees
ITransactionSampler transactionSampler3 = new ITransactionSampler() {
private final List<TransactionData> tds = new ArrayList<>();
@Override
public boolean noticeTransaction(TransactionData td) {
if (tds.size() == 0) {
tds.add(td);
return true;
} else if (td.getLegacyDuration() > tds.get(0).getLegacyDuration()) {
tds.clear();
tds.add(td);
}
return false;
}
@Override
public List<TransactionTrace> harvest(String appName) {
List<TransactionTrace> traces = new ArrayList<>();
for (TransactionData td : tds) {
TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
traces.add(trace);
}
return traces;
}
@Override
public void stop() {
tds.clear();
}
};
ttService.addTransactionTraceSampler(transactionSampler);
ttService.addTransactionTraceSampler(transactionSampler2);
ttService.addTransactionTraceSampler(transactionSampler3);
addTx("haggis-eating", 100L, false);
addTx("baseball", 100L, false);
addTx("baseball", 101L, true);
addTx("football", 100L, false);
addTx("football", 101L, true);
addTx("cricket", 100L, false);
addTx("cricket", 101L, true);
addTx("curling", 1500L, false);
addTx("curling", 2501L, true);
ttService.afterHarvest(APP_NAME);
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
List<TransactionTrace> traces = rpmService.getTraces();
System.out.println(traces);
Assert.assertEquals(8, traces.size());
// The synthetics sampler should have picked up all the traces with lengths ending in a 1
int nSynthetic = 0;
for (TransactionTrace tt : traces) {
if (tt.getDuration() % 10 == 1) {
nSynthetic++;
}
}
Assert.assertEquals(4, nSynthetic);
// And other samplers should have captured everything but (cricket, 100)
for (TransactionTrace tt : traces) {
if (tt.getRequestUri().contains("cricket") && tt.getDuration() == 100L) {
Assert.fail("samplers not behaving as expected.");
}
}
traces.clear();
traces = rpmService.getTraces();
Assert.assertEquals(0, traces.size());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class TransactionTraceServiceTest method testKeyTransactionSampler.
@Test
public void testKeyTransactionSampler() throws Exception {
final String keyTransactionName = "/a/key/transaction";
final String normalTransactionName = "/a/normal/transaction";
Map<String, Object> configMap = createConfigMap();
Map<String, Object> ttConfigMap = new HashMap<>();
configMap.put(AgentConfigImpl.ENABLE_AUTO_APP_NAMING, false);
configMap.put("transaction_tracer", ttConfigMap);
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.TRANSACTION_THRESHOLD, 100L);
Map<String, Object> ktConfig = new HashMap<>();
ktConfig.put(keyTransactionName, 0.04);
configMap.put(AgentConfigImpl.KEY_TRANSACTIONS, ktConfig);
createServiceManager(configMap);
removeRandomTTSamplers();
TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
TransactionData td = createTransactionData(keyTransactionName, "App Name", 50);
rpmServiceManager.getOrCreateRPMService("App Name");
Assert.assertTrue(td.getAgentConfig().isApdexTSet(keyTransactionName));
Assert.assertEquals(40, td.getAgentConfig().getApdexTInMillis(keyTransactionName));
ttService.dispatcherTransactionFinished(td, null);
TransactionData td2 = createTransactionData(normalTransactionName, "App Name", 50);
Assert.assertFalse(td2.getAgentConfig().isApdexTSet(normalTransactionName));
ttService.dispatcherTransactionFinished(td2, null);
ttService.afterHarvest("App Name");
MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getRPMService("App Name");
Assert.assertEquals(1, rpmService.getTraces().size());
Assert.assertEquals(keyTransactionName, rpmService.getTraces().get(0).getRequestUri());
Assert.assertEquals(50L, rpmService.getTraces().get(0).getDuration());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordApdexMetrics.
@Test
public void requestXStartHeaderRecordApdexMetrics() throws Exception {
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
rpmService.setEverConnected(true);
Map<String, Object> data = new HashMap<>();
data.put(AgentConfigImpl.APDEX_T, 6.0d);
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
connectionConfigListener.connected(rpmService, data);
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + (Transaction.getTransaction().getWallClockStartTimeMs() - 24005));
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.getTransaction().getRootTracer().finish(0, null);
StatsEngine statsEngine = ServiceFactory.getStatsService().getStatsEngineForHarvest(APP_NAME);
ApdexStats apdexStats = statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX));
Assert.assertEquals(1, apdexStats.getApdexFrustrating());
apdexStats = statsEngine.getApdexStats(MetricName.create("Apdex/Uri/Unknown"));
Assert.assertEquals(1, apdexStats.getApdexFrustrating());
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class BoundedConcurrentCacheTest method createServiceManager.
private MockServiceManager createServiceManager(Map<String, Object> configMap) throws Exception {
AgentConfig config = AgentConfigFactory.createAgentConfig(configMap, null, null);
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
DatabaseService dbService = new DatabaseService();
serviceManager.setDatabaseService(dbService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceManager.setRPMService(rpmService);
configService.start();
serviceManager.start();
sqlTraceService.start();
return serviceManager;
}
use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.
the class SlowQueryAggregatorImplTest method createServiceManager.
private MockServiceManager createServiceManager(Map<String, Object> configMap) throws Exception {
AgentConfig config = AgentConfigFactory.createAgentConfig(configMap, null, null);
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
DatabaseService dbService = new DatabaseService();
serviceManager.setDatabaseService(dbService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
serviceManager.setDistributedTraceService(new DistributedTraceServiceImpl());
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceManager.setRPMService(rpmService);
configService.start();
serviceManager.start();
sqlTraceService.start();
sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
serviceManager.setAttributesService(new AttributesService());
return serviceManager;
}
Aggregations