Skip to content

Commit 86da232

Browse files
authored
Add a try/catch and some extra logging around firing requests (#173)
1 parent 8a263f1 commit 86da232

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/main/java/com/arpnetworking/tsdcore/sinks/HttpSinkActor.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public void preRestart(final Throwable reason, final Optional<Object> message) t
152152
super.preRestart(reason, message);
153153

154154
_periodicMetrics.recordCounter("actors/http_post_sink/restarted", 1);
155+
LOGGER.error()
156+
.setMessage("Actor restarted")
157+
.addData("sink", _sink)
158+
.setThrowable(reason)
159+
.log();
155160
}
156161

157162
/**
@@ -385,7 +390,21 @@ private void fireNextRequest() {
385390
_periodicMetrics.recordTimer(_inQueueLatencyName, latencyInMillis, Optional.of(TimeUnit.MILLISECONDS));
386391

387392
_inflightRequestsCount++;
388-
fireRequest(requestEntry, 1);
393+
try {
394+
fireRequest(requestEntry, 1);
395+
// CHECKSTYLE.OFF: IllegalCatch - We need to catch everything here
396+
} catch (final RuntimeException e) {
397+
// CHECKSTYLE.ON: IllegalCatch
398+
_inflightRequestsCount--;
399+
POST_ERROR_LOGGER.error()
400+
.setMessage("Error while sending request")
401+
.addData("sink", _sink)
402+
.addData("request", requestEntry)
403+
.addContext("actor", self())
404+
.setThrowable(e)
405+
.log();
406+
throw e;
407+
}
389408
}
390409
}
391410

@@ -402,9 +421,9 @@ private void fireRequest(final RequestEntry request, final int attempt) {
402421
Optional.of(TimeUnit.MILLISECONDS));
403422
if (err == null) {
404423
if (_acceptedStatusCodes.contains(result.getStatusCode())) {
405-
return new PostSuccess(attempt, request, result);
424+
return new PostSuccess(attempt, request, result);
406425
} else {
407-
return new PostRejected(attempt, request, result);
426+
return new PostRejected(attempt, request, result);
408427
}
409428
} else {
410429
return new PostFailure(attempt, request, err);

0 commit comments

Comments
 (0)