use of com.newrelic.agent.stats.StatsWork in project newrelic-java-agent by newrelic.
the class TransactionEventsService method harvestEvents.
public void harvestEvents(final String appName) {
long startTimeInNanos = System.nanoTime();
beforeHarvestSynthetics(appName);
int targetStored = config.getTargetSamplesStored();
DistributedSamplingPriorityQueue<TransactionEvent> currentReservoir = reservoirForApp.get(appName);
int decidedLast = AdaptiveSampling.decidedLast(currentReservoir, targetStored);
// Now the reservoir for per-transaction analytic events from ordinary non-synthetic transactions
final DistributedSamplingPriorityQueue<TransactionEvent> reservoirToSend = reservoirForApp.put(appName, new DistributedSamplingPriorityQueue<TransactionEvent>(appName, "Transaction Event Service", maxSamplesStored, decidedLast, targetStored));
if (reservoirToSend != null && reservoirToSend.size() > 0) {
try {
ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName).sendAnalyticsEvents(maxSamplesStored, reservoirToSend.getNumberOfTries(), Collections.unmodifiableList(reservoirToSend.asList()));
final long durationInNanos = System.nanoTime() - startTimeInNanos;
ServiceFactory.getStatsService().doStatsWork(new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
recordSupportabilityMetrics(statsEngine, durationInNanos, reservoirToSend);
}
@Override
public String getAppName() {
return appName;
}
}, reservoirToSend.getServiceName());
} catch (HttpError e) {
if (!e.discardHarvestData()) {
Agent.LOG.log(Level.FINE, "Unable to send events for regular transactions. Data for this harvest will be resampled and the operation will be retried.", e);
// Save unsent data by merging it with current data using reservoir algorithm
currentReservoir = reservoirForApp.get(appName);
currentReservoir.retryAll(reservoirToSend);
} else {
// discard harvest data
reservoirToSend.clear();
Agent.LOG.log(Level.FINE, "Unable to send events for regular transactions. Data for this harvest will be dropped.", e);
}
} catch (Exception e) {
// discard harvest data
reservoirToSend.clear();
Agent.LOG.log(Level.FINE, "Unable to send events for regular transactions. Data for this harvest will be dropped.", e);
}
}
}
Aggregations