Search in sources :

Example 11 with HttpError

use of com.newrelic.agent.transport.HttpError 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);
        }
    }
}
Also used : StatsWork(com.newrelic.agent.stats.StatsWork) HttpError(com.newrelic.agent.transport.HttpError) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Aggregations

HttpError (com.newrelic.agent.transport.HttpError)11 StatsEngine (com.newrelic.agent.stats.StatsEngine)4 StatsWork (com.newrelic.agent.stats.StatsWork)4 Test (org.junit.Test)4 TransactionData (com.newrelic.agent.TransactionData)2 ConfigService (com.newrelic.agent.config.ConfigService)2 ReservoirManager (com.newrelic.agent.interfaces.ReservoirManager)2 DistributedSamplingPriorityQueue (com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue)2 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 Logger (com.newrelic.api.agent.Logger)2 IRPMService (com.newrelic.agent.IRPMService)1 SpanEventsConfig (com.newrelic.agent.config.SpanEventsConfig)1 CustomInsightsEvent (com.newrelic.agent.model.CustomInsightsEvent)1 ErrorEvent (com.newrelic.agent.model.ErrorEvent)1 LogEvent (com.newrelic.agent.model.LogEvent)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 Normalizer (com.newrelic.agent.normalization.Normalizer)1 HostConnectException (com.newrelic.agent.transport.HostConnectException)1 JSONException (com.newrelic.agent.util.JSONException)1