Skip to content

Commit

Permalink
Always log QosException at info (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Nov 30, 2022
1 parent e4ece66 commit 808fd0c
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.palantir.conjure.java.undertow.runtime;

import com.google.common.util.concurrent.RateLimiter;
import com.palantir.conjure.java.api.errors.ErrorType;
import com.palantir.conjure.java.api.errors.QosException;
import com.palantir.conjure.java.api.errors.RemoteException;
Expand Down Expand Up @@ -50,6 +51,9 @@ public enum ConjureExceptions implements ExceptionHandler {
private static final Serializer<SerializableError> serializer =
new ConjureBodySerDe(Collections.singletonList(Encodings.json())).serializer(new TypeMarker<>() {});

// Log at most once every second
private static final RateLimiter qosLoggingRateLimiter = RateLimiter.create(1);

@Override
public void handle(HttpServerExchange exchange, Throwable throwable) {
setFailure(exchange, throwable);
Expand Down Expand Up @@ -89,15 +93,17 @@ private static void serviceException(HttpServerExchange exchange, ServiceExcepti

private static void qosException(HttpServerExchange exchange, QosException qosException) {
qosException.accept(QOS_EXCEPTION_HEADERS).accept(exchange);
if (qosExceptionHasAdditionalMetadata(qosException)) {
log.info("quality-of-service intervention", qosException);
} else {
log.debug("quality-of-service intervention", qosException);

if (log.isDebugEnabled()) {
log.debug("Quality-of-Service error handling request", qosException);
} else if (qosExceptionHasAdditionalMetadata(qosException) || qosLoggingRateLimiter.tryAcquire()) {
log.info("Quality-of-Service error handling request", qosException);
}

writeResponse(exchange, Optional.empty(), qosException.accept(QOS_EXCEPTION_STATUS_CODE));
}

/** Returns true if {@link QosException} provides additional metadata and should be logged at {@code info}. */
/** Returns true if {@link QosException} provides additional metadata and should be logged at {@code info}. */
private static boolean qosExceptionHasAdditionalMetadata(QosException qosException) {
try {
if (qosException.getCause() != null) {
Expand Down

0 comments on commit 808fd0c

Please sign in to comment.