pzampino commented on code in PR #1518:
URL: https://github.com/apache/knox/pull/1518#discussion_r4603703067


##########
gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/AuditGatewayAppender.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.audit.log4j.appender;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+
+@Plugin(
+    name = "AuditGateway",
+    category = Core.CATEGORY_NAME,
+    elementType = Appender.ELEMENT_TYPE)
+public class AuditGatewayAppender extends AbstractAppender {
+  private static final Logger LOG = 
LogManager.getLogger(AuditGatewayAppender.class);
+  private static final long DROP_WARN_INTERVAL_MS = 60_000L;
+  private static final long POLL_MS = 250L;
+  private static final ContentType JSON = 
ContentType.create("application/json");
+  static final int MAX_WORKERS = 4;
+
+  private final URI uri;
+  private final String sourceSystem;
+  private final String podName;
+  private final BlockingQueue<String> queue;
+  private final int requestTimeoutMs;
+  private final long drainTimeoutMs;
+  private final int workerCount;
+  private final List<Thread> workers = new ArrayList<>();
+  private final AtomicBoolean running = new AtomicBoolean();
+  private final AtomicLong dropped = new AtomicLong();
+  private final AtomicLong lastDropWarn = new AtomicLong();
+  private CloseableHttpClient client;
+  private Thread shutdownHook;
+
+  AuditGatewayAppender(String name, Filter filter, URI uri, String 
sourceSystem, String podName,
+                       int queueSize, long requestTimeoutMs, long 
drainTimeoutMs, int workers) {
+    super(name, filter, null, true, Property.EMPTY_ARRAY);
+    this.uri = uri;
+    this.sourceSystem = sourceSystem;
+    this.podName = podName;
+    this.queue = new ArrayBlockingQueue<>(Math.max(1, queueSize));
+    this.requestTimeoutMs = (int) Math.min(Integer.MAX_VALUE, Math.max(0L, 
requestTimeoutMs));

Review Comment:
   Does this effectively default the timeout to zero?



##########
gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/AuditGatewayAppender.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.audit.log4j.appender;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+
+@Plugin(
+    name = "AuditGateway",
+    category = Core.CATEGORY_NAME,
+    elementType = Appender.ELEMENT_TYPE)
+public class AuditGatewayAppender extends AbstractAppender {
+  private static final Logger LOG = 
LogManager.getLogger(AuditGatewayAppender.class);
+  private static final long DROP_WARN_INTERVAL_MS = 60_000L;
+  private static final long POLL_MS = 250L;
+  private static final ContentType JSON = 
ContentType.create("application/json");
+  static final int MAX_WORKERS = 4;
+
+  private final URI uri;
+  private final String sourceSystem;
+  private final String podName;
+  private final BlockingQueue<String> queue;
+  private final int requestTimeoutMs;
+  private final long drainTimeoutMs;
+  private final int workerCount;
+  private final List<Thread> workers = new ArrayList<>();
+  private final AtomicBoolean running = new AtomicBoolean();
+  private final AtomicLong dropped = new AtomicLong();
+  private final AtomicLong lastDropWarn = new AtomicLong();
+  private CloseableHttpClient client;
+  private Thread shutdownHook;
+
+  AuditGatewayAppender(String name, Filter filter, URI uri, String 
sourceSystem, String podName,
+                       int queueSize, long requestTimeoutMs, long 
drainTimeoutMs, int workers) {
+    super(name, filter, null, true, Property.EMPTY_ARRAY);
+    this.uri = uri;
+    this.sourceSystem = sourceSystem;
+    this.podName = podName;
+    this.queue = new ArrayBlockingQueue<>(Math.max(1, queueSize));
+    this.requestTimeoutMs = (int) Math.min(Integer.MAX_VALUE, Math.max(0L, 
requestTimeoutMs));
+    this.drainTimeoutMs = Math.max(0L, drainTimeoutMs);
+    this.workerCount = Math.min(MAX_WORKERS, Math.max(1, workers));
+  }
+
+  @PluginFactory
+  public static AuditGatewayAppender createAppender(
+      @PluginAttribute("name") String name,
+      @PluginElement("Filter") Filter filter,
+      @PluginAttribute("endpoint") String endpoint,
+      @PluginAttribute("path") String path,
+      @PluginAttribute("sourceSystem") String sourceSystem,
+      @PluginAttribute("podName") String podName,
+      @PluginAttribute(value = "queueSize", defaultInt = 2000) int queueSize,
+      @PluginAttribute(value = "requestTimeoutMs", defaultLong = 2500L) long 
requestTimeoutMs,
+      @PluginAttribute(value = "drainTimeoutMs", defaultLong = 5000L) long 
drainTimeoutMs,
+      @PluginAttribute(value = "workers", defaultInt = 1) int workers) {
+    return new AuditGatewayAppender(name, filter, resolveUri(endpoint, path), 
sourceSystem, podName,
+        queueSize, requestTimeoutMs, drainTimeoutMs, workers);
+  }
+
+  static URI resolveUri(String endpoint, String path) {
+    if (StringUtils.isBlank(endpoint)) {
+      return null;
+    }
+    String value = endpoint.trim();
+    if (!value.contains("://")) {
+      value = "http://"; + value;

Review Comment:
   Should the default be https?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to