use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreErrorWrongMessage.
@Test
public void ignoreErrorWrongMessage() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("ignore_error_bad_message_test");
try {
try {
throwException("pleasen be right");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreStatusSoClose.
@Test
public void ignoreStatusSoClose() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("non_ignore_status_code_test");
try {
reportStatusCode();
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("WebTransaction/NormalizedUri/420/*", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
assertEquals(1, statsEngine.getApdexStats(MetricName.create(MetricNames.APDEX)).getApdexFrustrating());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreErrorWrongMessageNoTransaction.
@Test
public void ignoreErrorWrongMessageNoTransaction() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("ignore_error_bad_message_test");
try {
try {
throwExceptionNoTransaction("pleasen be right");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(0, transactionList.size());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class IgnoreErrorsTest method ignoreClassMessagesFallbackNotIgnored.
@Test
public void ignoreClassMessagesFallbackNotIgnored() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("ignore_class_messages_fallback_test");
try {
try {
// This should be allowed through
throwException(new ExpectedError("blah"));
fail("The ignored exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.IgnoreErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class LogSenderServiceImpl method harvestEvents.
/**
* Harvest and send the LogEvents
*
* @param appName the application to harvest for
*/
public void harvestEvents(final String appName) {
if (!getIsEnabledForApp(ServiceFactory.getConfigService().getAgentConfig(appName), appName)) {
reservoirForApp.remove(appName);
return;
}
if (maxSamplesStored <= 0) {
clearReservoir(appName);
return;
}
long startTimeInNanos = System.nanoTime();
final DistributedSamplingPriorityQueue<LogEvent> reservoir = this.reservoirForApp.put(appName, new DistributedSamplingPriorityQueue<>(appName, LOG_SENDER_SERVICE, maxSamplesStored));
if (reservoir != null && reservoir.size() > 0) {
try {
// Send LogEvents
ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName).sendLogEvents(Collections.unmodifiableList(reservoir.asList()));
final long durationInNanos = System.nanoTime() - startTimeInNanos;
ServiceFactory.getStatsService().doStatsWork(new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
recordSupportabilityMetrics(statsEngine, durationInNanos, reservoir);
}
@Override
public String getAppName() {
return appName;
}
}, LogSenderServiceImpl.class.getName());
if (reservoir.size() < reservoir.getNumberOfTries()) {
int dropped = reservoir.getNumberOfTries() - reservoir.size();
Agent.LOG.log(Level.FINE, "Dropped {0} log events out of {1}.", dropped, reservoir.getNumberOfTries());
}
} catch (HttpError e) {
if (!e.discardHarvestData()) {
Agent.LOG.log(Level.FINE, "Unable to send log events. Unsent events will be included in the next harvest.", e);
// Save unsent data by merging it with current data using reservoir algorithm
DistributedSamplingPriorityQueue<LogEvent> currentReservoir = reservoirForApp.get(appName);
currentReservoir.retryAll(reservoir);
} else {
// discard harvest data
reservoir.clear();
Agent.LOG.log(Level.FINE, "Unable to send log events. Unsent events will be dropped.", e);
}
} catch (Exception e) {
// discard harvest data
reservoir.clear();
Agent.LOG.log(Level.FINE, "Unable to send log events. Unsent events will be dropped.", e);
}
}
}
Aggregations