[ 
https://issues.apache.org/jira/browse/KNOX-3580?focusedWorklogId=1055403&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055403
 ]

ASF GitHub Bot logged work on KNOX-3580:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Nov/26 18:36
            Start Date: 17/Nov/26 18:36
    Worklog Time Spent: 10m 
      Work Description: hanicz commented on code in PR #1518:
URL: https://github.com/apache/knox/pull/1518#discussion_r4604062451


##########
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:
   No its 2.5s, its coming from 
   `@PluginAttribute(value = "requestTimeoutMs", defaultLong = 2500L) long 
requestTimeoutMs`





Issue Time Tracking
-------------------

    Worklog Id:     (was: 1055403)
    Time Spent: 40m  (was: 0.5h)

>  Add log4j2 appender to POST audit events as JSON to an HTTP endpoint
> ---------------------------------------------------------------------
>
>                 Key: KNOX-3580
>                 URL: https://issues.apache.org/jira/browse/KNOX-3580
>             Project: Apache Knox
>          Issue Type: Task
>          Components: Server
>    Affects Versions: 3.0.0
>            Reporter: Tamás Hanicz
>            Assignee: Tamás Hanicz
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Add an AuditGateway log4j2 appender that sends each Knox audit record as a 
> JSON event to an HTTP endpoint. It is enabled only when the AUDIT_GATEWAY env 
> var is set; otherwise it does nothing.
> - Maps Knox action and outcome to a category/verb/outcome event, including 
> actor (act), target resource and correlation id.
> - Sends asynchronously from a bounded queue, with retries and a circuit 
> breaker.
> - Drains queued events on shutdown.
> - gateway-audit.log is unchanged.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to