summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-06-23 18:51:19 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-06-23 18:51:19 +0200
commitf8b5458406a0bc6f9d39afcfa61d266823ec46fd (patch)
tree3d3b38ed6062162b1d6d249ba54968d9cff75ddb /vespa-feed-client
parenteea6516493df1e341cfeb2477e4b5a69c932ee8f (diff)
Different log level for different errors
Diffstat (limited to 'vespa-feed-client')
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java28
1 files changed, 21 insertions, 7 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
index e9cd0baba5b..1987bae18f9 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java
@@ -16,6 +16,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.logging.Level;
import java.util.logging.Logger;
import static ai.vespa.feed.client.FeedClient.CircuitBreaker.State.CLOSED;
@@ -23,6 +24,8 @@ import static ai.vespa.feed.client.FeedClient.CircuitBreaker.State.HALF_OPEN;
import static ai.vespa.feed.client.FeedClient.CircuitBreaker.State.OPEN;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.logging.Level.FINE;
+import static java.util.logging.Level.FINEST;
+import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
// TODO: update doc
@@ -133,39 +136,50 @@ class HttpRequestStrategy implements RequestStrategy {
*/
private boolean retry(HttpRequest request, Throwable thrown, int attempt) {
breaker.failure();
- log.log(FINE, thrown, () -> "Failed attempt " + attempt + " at " + request);
-
if ( (thrown instanceof IOException) // General IO problems.
|| (thrown instanceof CancellationException) // TLS session disconnect.
- || (thrown instanceof CancelledKeyException)) // Selection cancelled.
+ || (thrown instanceof CancelledKeyException)) { // Selection cancelled.
+ log.log(INFO, thrown, () -> "Failed attempt " + attempt + " at " + request);
return retry(request, attempt);
+ }
+ log.log(WARNING, thrown, () -> "Failed attempt " + attempt + " at " + request);
return false;
}
/** Retries throttled requests (429, 503), adjusting the target inflight count, and server errors (500, 502). */
private boolean retry(HttpRequest request, HttpResponse response, int attempt) {
- if (response.code() / 100 == 2) {
+ if (response.code() / 100 == 2 || response.code() == 404 || response.code() == 412) {
+ logResponse(FINEST, response, request, attempt);
breaker.success();
throttler.success();
return false;
}
- log.log(FINE, () -> "Status code " + response.code() + " (" + new String(response.body(), UTF_8) +
- ") on attempt " + attempt + " at " + request);
if (response.code() == 429 || response.code() == 503) { // Throttling; reduce target inflight.
+ logResponse(FINE, response, request, attempt);
throttler.throttled((inflight.get() - delayedCount.get()));
return true;
}
breaker.failure();
- if (response.code() == 500 || response.code() == 502 || response.code() == 504) // Hopefully temporary errors.
+ if (response.code() == 500 || response.code() == 502 || response.code() == 504) { // Hopefully temporary errors.
+ logResponse(INFO, response, request, attempt);
return retry(request, attempt);
+ }
+ logResponse(WARNING, response, request, attempt);
return false;
}
+ static void logResponse(Level level, HttpResponse response, HttpRequest request, int attempt) {
+ if (log.isLoggable(level))
+ log.log(level, "Status code " + response.code() +
+ " (" + (response.body() == null ? "no body" : new String(response.body(), UTF_8)) +
+ ") on attempt " + attempt + " at " + request);
+ }
+
private void acquireSlot() {
try {
while (inflight.get() >= throttler.targetInflight())