abhishekagarwal87 commented on code in PR #15480:
URL: https://github.com/apache/druid/pull/15480#discussion_r1415228285


##########
server/src/main/java/org/apache/druid/server/audit/AuditSerdeHelper.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.druid.server.audit;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.audit.AuditEvent;
+import org.apache.druid.audit.AuditManagerConfig;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.JsonNonNull;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+public class AuditSerdeHelper

Review Comment:
   javadocs please



##########
server/src/main/java/org/apache/druid/guice/SQLMetadataStorageDruidModule.java:
##########
@@ -130,21 +133,48 @@ public void configure(Binder binder)
             .to(SQLMetadataStorageUpdaterJobHandler.class)
             .in(LazySingleton.class);
 
-    JsonConfigProvider.bind(binder, "druid.audit.manager", 
SQLAuditManagerConfig.class);
-
-    PolyBind.optionBinder(binder, Key.get(AuditManager.class))
-            .addBinding(type)
-            .to(SQLAuditManager.class)
-            .in(LazySingleton.class);
-
-    PolyBind.optionBinder(binder, Key.get(AuditManagerProvider.class))
-            .addBinding(type)
-            .to(SQLAuditManagerProvider.class)
-            .in(LazySingleton.class);
-
     PolyBind.optionBinder(binder, Key.get(MetadataSupervisorManager.class))
             .addBinding(type)
             .to(SQLMetadataSupervisorManager.class)
             .in(LazySingleton.class);
   }
+
+  private void configureAuditDestination(Binder binder)
+  {
+    PolyBind.createChoice(
+        binder,
+        "druid.audit.destination",

Review Comment:
   druid.audit.storage seems better than druid.audit.destination. what do you 
think? 



##########
indexing-service/src/test/java/org/apache/druid/indexing/overlord/http/OverlordResourceTest.java:
##########
@@ -900,7 +900,7 @@ public void testTaskPostDeniesDatasourceReadUser()
     Task task = NoopTask.forDatasource(Datasources.WIKIPEDIA);
     expectedException.expect(ForbiddenException.class);
     expectedException.expect(ForbiddenException.class);
-    overlordResource.taskPost(task, req);
+    overlordResource.taskPost(task, "", "", req);

Review Comment:
   maybe add a test with non-empty author to see that audit event does go 
through? 



##########
server/src/main/java/org/apache/druid/server/http/DataSourcesResource.java:
##########
@@ -236,12 +250,24 @@ public Response markSegmentsAsUnused(
                    .collect(Collectors.toSet());
 
         // Note: segments for the "wrong" datasource are ignored.
-        return segmentsMetadataManager.markSegmentsAsUnused(
+        numUpdatedSegments = segmentsMetadataManager.markSegmentsAsUnused(
             segmentIds.stream()
                       .filter(segmentId -> 
segmentId.getDataSource().equals(dataSourceName))
                       .collect(Collectors.toSet())
         );
+        auditPayload = Collections.singletonMap("segmentIds", segmentIds);
+      }
+      if (auditManager != null && author != null && !author.isEmpty()) {
+        auditManager.doAudit(
+            AuditEvent.builder()
+                      .key(dataSourceName)
+                      .type("segments.markUnused")

Review Comment:
   can the type name be standardized? E.g. serviceName.api-path



##########
server/src/main/java/org/apache/druid/server/audit/SQLAuditManager.java:
##########
@@ -268,10 +263,27 @@ private List<AuditEntry> 
fetchAuditHistoryLastEntries(final String key, final St
           return query
               .bind("type", type)
               .setMaxRows(theLimit)
-              .map((index, r, ctx) -> JacksonUtils.readValue(jsonMapper, 
r.getBytes("payload"), AuditEntry.class))
+              .map(resultMapper)
               .list();
         }
     );
   }
 
+  private class AuditEventMapper implements ResultSetMapper<AuditEvent>
+  {
+    @Override
+    public AuditEvent map(int index, ResultSet r, StatementContext ctx) throws 
SQLException
+    {
+      // Read the record and convert to an AuditEvent that can deserialize the 
payload on-demand
+      AuditRecord record = JacksonUtils.readValue(jsonMapper, 
r.getBytes("payload"), AuditRecord.class);

Review Comment:
   does this not fail when payload is truncated? 



##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java:
##########
@@ -225,18 +226,31 @@ public Response taskPost(final Task task, @Context final 
HttpServletRequest req)
         taskQueue -> {
           try {
             taskQueue.add(task);
+
+            // Do an audit only if this API was called by a user and not by 
internal services
+            if (author != null && !author.isEmpty()) {
+              auditManager.doAudit(
+                  AuditEvent.builder()
+                            .key(task.getDataSource())
+                            .type("ingestion.batch")

Review Comment:
   can the type be just `task` or just `ingestion`? 



##########
processing/src/test/java/org/apache/druid/audit/NoopAuditManager.java:
##########


Review Comment:
   this is not needed? 



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to