From dfff3145701a851a1b6b102f127032beea13c758 Mon Sep 17 00:00:00 2001 From: Zhu Zhan Yan Date: Tue, 8 Sep 2020 12:43:59 +0800 Subject: [PATCH] Allow Logging Interceptor to be toggled by Message Logging Enabled Flag (#940) * Update audit.logging.messageLoggingEnabled to be able to enable/disable logging interceptor Previously the flag only toggled AuditLogger codebase * Remove disable at AuditLogger for messageLoggingEnabled as it already disabled at the GrpcMessageInterceptor * Remove legacy logging config file. --- .../feast/common/logging/AuditLogger.java | 5 ----- .../interceptors/GrpcMessageInterceptor.java | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/feast/common/logging/AuditLogger.java b/common/src/main/java/feast/common/logging/AuditLogger.java index 4e779a75aa..5f9f92c0be 100644 --- a/common/src/main/java/feast/common/logging/AuditLogger.java +++ b/common/src/main/java/feast/common/logging/AuditLogger.java @@ -20,7 +20,6 @@ import feast.common.logging.config.LoggingProperties.AuditLogProperties; import feast.common.logging.entry.ActionAuditLogEntry; import feast.common.logging.entry.AuditLogEntry; -import feast.common.logging.entry.AuditLogEntryKind; import feast.common.logging.entry.LogResource; import feast.common.logging.entry.LogResource.ResourceType; import feast.common.logging.entry.MessageAuditLogEntry; @@ -112,10 +111,6 @@ private static void log(Level level, AuditLogEntry entry) { if (!properties.isEnabled()) { return; } - if (entry.getKind().equals(AuditLogEntryKind.MESSAGE) - && !properties.isMessageLoggingEnabled()) { - return; - } // Log event to audit log through enabled formats String entryJSON = entry.toJSON(); diff --git a/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java b/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java index da293817ec..e568ccdd86 100644 --- a/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java +++ b/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java @@ -22,6 +22,7 @@ import feast.common.auth.config.SecurityProperties.AuthenticationProperties; import feast.common.auth.utils.AuthUtils; import feast.common.logging.AuditLogger; +import feast.common.logging.config.LoggingProperties; import feast.common.logging.entry.MessageAuditLogEntry; import io.grpc.ForwardingServerCall.SimpleForwardingServerCall; import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener; @@ -48,18 +49,30 @@ @Component public class GrpcMessageInterceptor implements ServerInterceptor { private SecurityProperties securityProperties; + private LoggingProperties loggingProperties; + /** - * Construct GrpcMessageIntercetor. If provided securityProperties, will output the subject claim - * specified in securityProperties as identity in {@link MessageAuditLogEntry} instead. + * Construct GrpcMessageIntercetor. + * + * @param loggingProperties properties used to configure logging interceptor. + * @param securityProperties If provided, will output the subject claim specified in + * securityProperties as identity in {@link MessageAuditLogEntry} instead. */ @Autowired - public GrpcMessageInterceptor(@Nullable SecurityProperties securityProperties) { + public GrpcMessageInterceptor( + LoggingProperties loggingProperties, @Nullable SecurityProperties securityProperties) { this.securityProperties = securityProperties; + this.loggingProperties = loggingProperties; } @Override public Listener interceptCall( ServerCall call, Metadata headers, ServerCallHandler next) { + // Disable the message logging interceptor entirely if message logging is disabled. + if (!loggingProperties.getAudit().isMessageLoggingEnabled()) { + return next.startCall(call, headers); + } + MessageAuditLogEntry.Builder entryBuilder = MessageAuditLogEntry.newBuilder(); // default response/request message to empty proto in log entry. // request could be empty when the client closes the connection before sending a request