use of com.newrelic.agent.transport.HostConnectException in project newrelic-java-agent by newrelic.
the class RPMService method harvest.
@Override
public void harvest(StatsEngine statsEngine) {
if (!isConnected()) {
// Assumption: failed re-connect should be a result of a temporary condition, and we need to retry
try {
Agent.LOG.fine("Trying to re-establish connection to New Relic.");
this.launch();
} catch (Exception e) {
Agent.LOG.fine("Problem trying to re-establish connection to New Relic: " + e.getMessage());
}
}
if (isConnected()) {
boolean retry = false;
Normalizer metricNormalizer = ServiceFactory.getNormalizationService().getMetricNormalizer(appName);
List<MetricData> data = statsEngine.getMetricData(metricNormalizer);
long startTime = System.nanoTime();
long reportInterval = 0;
try {
long now = System.currentTimeMillis();
sendMetricDataSyncRestart(lastReportTime, now, data);
reportInterval = now - lastReportTime;
lastReportTime = now;
last503Error.set(0);
// log at info level whenever we successfully send metric data following a failure
if (retryCount.get() > 0) {
Agent.LOG.log(Level.INFO, "Successfully reconnected to the New Relic data service.");
}
Agent.LOG.log(Level.FINE, "Reported {0} timeslices for {1}", data.size(), getApplicationName());
} catch (InternalLimitExceeded e) {
Agent.LOG.log(Level.SEVERE, "The metric data post was too large. {0} timeslices will not be resent", data.size());
} catch (MetricDataException e) {
Agent.LOG.log(Level.SEVERE, "An invalid response was received while sending metric data. This data will not be resent.");
Agent.LOG.log(Level.FINEST, e, e.toString());
} catch (HttpError e) {
// HttpError handled here
retry = e.isRetryableError();
if (HttpResponseCode.SERVICE_UNAVAILABLE == e.getStatusCode()) {
// 503s are unfortunately common for the collector, so we log these at a lower level until we see
// many consecutive failures
handle503Error(e);
} else if (retry) {
// otherwise if we're going to retry later things aren't so bad
Agent.LOG.log(Level.INFO, "An error occurred posting metric data - {0}. This data will be resent later.", e.getMessage());
} else {
// but let's call out when we're dropping data. Check out HttpError.isRetryableError()
Agent.LOG.log(Level.SEVERE, "An error occurred posting metric data - {0}. {1} timeslices will not be resent.", e.getMessage(), data.size());
}
} catch (ForceRestartException e) {
logForceRestartException(e);
reconnectAsync();
retry = true;
} catch (ForceDisconnectException e) {
logForceDisconnectException(e);
shutdownAsync();
} catch (HostConnectException e) {
retry = true;
Agent.LOG.log(Level.INFO, "A connection error occurred contacting {0}. Please check your network / proxy settings.", e.getHostName());
Agent.LOG.log(Level.FINEST, e, e.toString());
} catch (Exception e) {
// LicenseException handled here
logMetricDataError(e);
retry = true;
if (e.getMessage() != null) {
String message = e.getMessage().toLowerCase();
// (web transaction maybe?). clear out the metrics
if (message.contains("json") && message.contains("parse")) {
retry = false;
}
}
}
long duration = System.nanoTime() - startTime;
if (retry) {
retryCount.getAndIncrement();
} else {
retryCount.set(0);
statsEngine.clear();
recordSupportabilityMetrics(statsEngine, reportInterval, duration, data.size());
}
}
}
use of com.newrelic.agent.transport.HostConnectException in project newrelic-java-agent by newrelic.
the class ApacheHttpClientWrapper method execute.
@Override
public ReadResult execute(HttpClientWrapper.Request request, ExecuteEventHandler handler) throws Exception {
HttpUriRequest apacheRequest = mapRequestToApacheRequest(request);
if (handler != null) {
handler.requestStarted();
}
logConnectionPoolStatus(apacheRequest);
try (CloseableHttpResponse response = httpClient.execute(apacheRequest, createContext())) {
if (handler != null) {
handler.requestEnded();
}
logConnectionPoolStatus(apacheRequest);
return mapResponseToResult(response);
} catch (HttpHostConnectException hostConnectException) {
throw new HostConnectException(hostConnectException.getHost().toString(), hostConnectException);
}
}
use of com.newrelic.agent.transport.HostConnectException in project newrelic-java-agent by newrelic.
the class HostConnectExceptionTest method ensureCauseIsSet.
@Test
public void ensureCauseIsSet() {
HttpHostConnectException innerException = new HttpHostConnectException(new IOException("really inner cause"), HttpHost.create("https://nothing.example.com"));
HostConnectException target = new HostConnectException(innerException.toString(), innerException);
assertSame(innerException, target.getCause());
}
Aggregations