Skip to content

Commit

Permalink
Merge pull request #599 from swisspost/get-more-info-related-to-error
Browse files Browse the repository at this point in the history
write more detail log if forwarding to storage fails
  • Loading branch information
dominik-cnx authored Jun 20, 2024
2 parents 02e7950 + 5547874 commit 2610f64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.LoggerFactory;
import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager;
import org.swisspush.gateleen.core.configuration.ConfigurationResourceObserver;
import org.swisspush.gateleen.core.exception.GateleenExceptionFactory;
import org.swisspush.gateleen.core.http.HttpClientFactory;
import org.swisspush.gateleen.core.http.RequestLoggerFactory;
import org.swisspush.gateleen.core.logging.LoggableResource;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class Router implements Refreshable, LoggableResource, ConfigurationResou
private final String rulesUri;
private final String userProfileUri;
private final String serverUri;
private final GateleenExceptionFactory exceptionFactory;
private io.vertx.ext.web.Router router;
private final LoggingResourceManager loggingResourceManager;
private final LogAppenderRepository logAppenderRepository;
Expand Down Expand Up @@ -117,6 +119,7 @@ public static RouterBuilder builder() {
HttpClientFactory httpClientFactory,
int routeMultiplier,
@Nullable OAuthProvider oAuthProvider,
GateleenExceptionFactory exceptionFactory,
Handler<Void>... doneHandlers) {
this.storage = storage;
this.properties = properties;
Expand All @@ -135,6 +138,7 @@ public static RouterBuilder builder() {
this.doneHandlers = doneHandlers;
this.routeMultiplier = routeMultiplier;
this.oAuthProvider = oAuthProvider;
this.exceptionFactory = exceptionFactory;

if (oAuthProvider != null) {
this.oAuthStrategy = new OAuthStrategy(oAuthProvider);
Expand Down Expand Up @@ -324,7 +328,7 @@ private void createForwarders(List<Rule> rules, io.vertx.ext.web.Router newRoute
vertx.eventBus());
} else if (rule.getStorage() != null) {
forwarder = new StorageForwarder(vertx.eventBus(), rule, loggingResourceManager, logAppenderRepository,
monitoringHandler);
monitoringHandler, exceptionFactory);
} else if (rule.getScheme().equals("local")) {
forwarder = new Forwarder(vertx, selfClient, rule, this.storage, loggingResourceManager, logAppenderRepository,
monitoringHandler, userProfileUri, authStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager;
import org.swisspush.gateleen.core.exception.GateleenExceptionFactory;
import org.swisspush.gateleen.core.http.HttpClientFactory;
import org.swisspush.gateleen.core.storage.ResourceStorage;
import org.swisspush.gateleen.logging.LogAppenderRepository;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class RouterBuilder {
private int routeMultiplier = Router.DEFAULT_ROUTER_MULTIPLIER;

private OAuthProvider oAuthProvider;
private GateleenExceptionFactory exceptionFactory;

RouterBuilder() {
// PackagePrivate, as clients should use "Router.builder()" and not this class here directly.
Expand All @@ -67,6 +69,10 @@ public Router build() {
defaultRouteTypes = all();
}

if (this.exceptionFactory == null) {
this.exceptionFactory = GateleenExceptionFactory.newGateleenThriftyExceptionFactory();
}

Handler<Void>[] doneHandlersArray;
if (doneHandlers == null || doneHandlers.isEmpty()) {
logger.debug("No doneHandlers specified.");
Expand Down Expand Up @@ -102,6 +108,7 @@ public Router build() {
httpClientFactory,
routeMultiplier,
oAuthProvider,
exceptionFactory,
doneHandlersArray
);
if (resourceLoggingEnabled) {
Expand Down Expand Up @@ -273,4 +280,9 @@ public RouterBuilder withRouteMultiplier(int routeMultiplier) {
this.routeMultiplier = routeMultiplier;
return this;
}

public RouterBuilder withExceptionFactory(GateleenExceptionFactory exceptionFactory) {
this.exceptionFactory = exceptionFactory;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.vertx.ext.web.RoutingContext;
import org.slf4j.Logger;
import org.swisspush.gateleen.core.cors.CORSHandler;
import org.swisspush.gateleen.core.exception.GateleenExceptionFactory;
import org.swisspush.gateleen.core.http.HeaderFunctions;
import org.swisspush.gateleen.core.http.HttpRequest;
import org.swisspush.gateleen.core.http.RequestLoggerFactory;
Expand All @@ -40,13 +41,17 @@ public class StorageForwarder extends AbstractForwarder {
private Pattern urlPattern;
private String address;
private CORSHandler corsHandler;
private GateleenExceptionFactory gateleenExceptionFactory;

public StorageForwarder(EventBus eventBus, Rule rule, LoggingResourceManager loggingResourceManager, LogAppenderRepository logAppenderRepository, MonitoringHandler monitoringHandler) {
public StorageForwarder(EventBus eventBus, Rule rule, LoggingResourceManager loggingResourceManager,
LogAppenderRepository logAppenderRepository, MonitoringHandler monitoringHandler,
GateleenExceptionFactory gateleenExceptionFactory) {
super(rule, loggingResourceManager, logAppenderRepository, monitoringHandler);
this.eventBus = eventBus;
this.address = Address.storageAddress() + "-" + rule.getStorage();
urlPattern = Pattern.compile(rule.getUrlPattern());
corsHandler = new CORSHandler();
this.gateleenExceptionFactory = gateleenExceptionFactory;
}

@Override
Expand Down Expand Up @@ -97,7 +102,7 @@ public void handle(final RoutingContext ctx) {
response.setStatusCode(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setStatusMessage(statusMessage);
response.end();
log.error("Storage request failed", result.cause());
log.error(statusMessage, gateleenExceptionFactory.newException(result.cause()));
} else {
Buffer buffer = result.result().body();
int headerLength = buffer.getInt(0);
Expand Down

0 comments on commit 2610f64

Please sign in to comment.