Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Gateway dependency logs #413

Merged
merged 8 commits into from Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,23 +14,32 @@
import ch.qos.logback.classic.turbo.TurboFilter;
import ch.qos.logback.core.spi.FilterReply;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Marker;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class ApimlDependencyLogHider extends TurboFilter {

private static final List<String> IGNORED_MESSAGE_KEYWORDS = Arrays.asList(
"Tomcat initialized",
"Tomcat initialized", "Tomcat started on port(s)",
"lease doesn't exist", "Not Found (Renew)",
"route 53",
"dirty timestamp", "Using the existing instanceInfo instead of the new instanceInfo as the registrant",
"eureka.server.peer-node-read-timeout-ms",
"Found more than one MBeanServer instance",
"dirty timestamp", "Using the existing instanceInfo instead of the new instanceInfo as the registrant",
"Network level connection to peer",
"Tomcat started on port(s)");
"DS: Registry: expired lease for",

"No routes found from RouteLocator",
"Exception Processing ErrorPage",
"Error while sending response to client",
"Request execution error",
"The Hystrix timeout",
".*Error during filtering.*Token is not valid.*");

private boolean isFilterActive;

Expand All @@ -41,22 +50,30 @@ public ApimlDependencyLogHider() {

@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
if (!isFilterActive || format == null || isLowThanInfoLevel(logger.getEffectiveLevel())) {
return FilterReply.NEUTRAL;
}

if (isFilterActive
&& !isLowThanInfoLevel(logger.getEffectiveLevel())
&& (format != null && isIgnoredMessage(format))) {
return FilterReply.DENY;
if (t != null) {
format += Arrays.asList(ExceptionUtils.getStackFrames(t)).stream().collect(Collectors.joining());
}

return FilterReply.NEUTRAL;
return getFilterReply(format);
}

private boolean isLowThanInfoLevel(Level level) {
return level.levelInt < Level.INFO.levelInt;
}

private boolean isIgnoredMessage(String format) {
return IGNORED_MESSAGE_KEYWORDS.stream()
.anyMatch(format::contains);
private FilterReply getFilterReply(String format) {
boolean ignored = IGNORED_MESSAGE_KEYWORDS.stream()
.anyMatch(keyword -> {
if (keyword.contains(".*")) {
return format.matches(keyword);
} else {
return format.contains(keyword);
}
});
return ignored ? FilterReply.DENY : FilterReply.NEUTRAL;
}
}
Expand Up @@ -55,7 +55,7 @@ public void testDecide_whenLoggerLevelIsLowThanInfo() {


@Test
public void testDecide_whenLoggerLevelWhenIgnoredMessagesArePresent() {
public void testDecide_whenIgnoredMessagesArePresent() {
logger.setLevel(Level.INFO);

Map<String, Boolean> logMessages = new HashMap<>();
Expand All @@ -71,4 +71,19 @@ public void testDecide_whenLoggerLevelWhenIgnoredMessagesArePresent() {
assertEquals("Log levels are not same", expectedFilterReply, actualFilterReply);
});
}

@Test
public void testDecide_whenIgnoredMessagesArePresentWithException() {
logger.setLevel(Level.ERROR);

String format = "Error during filtering";
RuntimeException filterException = new RuntimeException("Token is not valid");

FilterReply actualFilterReply = apimlDependencyLogHider.decide(null, logger, null,
format, null, filterException);

FilterReply expectedFilterReply = FilterReply.DENY;
assertEquals("Log levels are not same", expectedFilterReply, actualFilterReply);
}

}
9 changes: 4 additions & 5 deletions gateway-service/src/main/resources/application.yml
Expand Up @@ -3,22 +3,21 @@ logging:
ROOT: INFO
com.ca.mfaas: INFO
org.springframework: WARN
org.apache.catalina: WARN
com.netflix: WARN
com.netflix.discovery: ERROR
com.netflix.config: ERROR
com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient: OFF
com.netflix.discovery.DiscoveryClient: OFF
org.springframework.boot.web.embedded.tomcat.TomcatWebServer: INFO
org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand: ERROR
org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter: ERROR
org.apache.tomcat.websocket: WARN
org.springframework.web.socket: WARN
com.ca.mfaas.gateway.ws: INFO
com.ca.mfaas.gateway.error: INFO
org.eclipse.jetty: WARN
org.springframework.web.servlet.PageNotFound: ERROR

# New Config
org.apache: WARN #org.apache.catalina, org.apache.coyote, org.apache.tomcat

apiml:
# The `apiml` node contains API Mediation Layer specific configuration
service:
Expand Down Expand Up @@ -198,7 +197,7 @@ logging:
ROOT: INFO
com.ca.mfaas: DEBUG
org.springframework: INFO
org.apache.catalina: INFO
org.apache: INFO
com.netflix: INFO
org.hibernate: INFO
org.springframework.web.servlet.PageNotFound: WARN
Expand Down