adnanhemani commented on code in PR #1844:
URL: https://github.com/apache/polaris/pull/1844#discussion_r2224589790


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/models/ModelEvent.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.polaris.persistence.relational.jdbc.models;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.polaris.core.entity.PolarisEvent;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.apache.polaris.persistence.relational.jdbc.DatabaseType;
+
+@PolarisImmutable
+public interface ModelEvent extends Converter<PolarisEvent> {
+  String TABLE_NAME = "EVENTS";
+
+  List<String> ALL_COLUMNS =
+      List.of(
+          "catalog_id",
+          "event_id",
+          "request_id",
+          "event_type",
+          "timestamp_ms",
+          "principal_name",
+          "resource_type",
+          "resource_identifier",
+          "additional_parameters");

Review Comment:
   Renamed to `additional_properties`.



##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEvent.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.polaris.core.entity;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Map;
+
+public class PolarisEvent {

Review Comment:
   It's not trying to match Iceberg Events - but rather the naming scheme for 
all other persistence object types in that directory (which is 
"Polaris<ObjectName>"). I agree that it's a bit confusing, but I haven't been 
able to find a better name for this object given the current naming scheme. Do 
you have any suggestions?



##########
runtime/service/src/main/java/org/apache/polaris/service/quarkus/events/QuarkusPolarisEventListenerConfiguration.java:
##########
@@ -20,13 +20,23 @@
 
 import io.quarkus.runtime.annotations.StaticInitSafe;
 import io.smallrye.config.ConfigMapping;
+import java.time.Duration;
+import java.util.Optional;
+import org.apache.polaris.service.events.EventListenerConfiguration;
+import org.apache.polaris.service.events.listeners.PolarisEventListener;
 
 @StaticInitSafe
 @ConfigMapping(prefix = "polaris.event-listener")
-public interface QuarkusPolarisEventListenerConfiguration {
+public interface QuarkusPolarisEventListenerConfiguration extends 
EventListenerConfiguration {

Review Comment:
   Done.



##########
polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java:
##########
@@ -44,22 +46,34 @@ public class PolarisCallContext implements CallContext {
 
   private final Clock clock;
 
+  // A request ID to identify this REST request
+  private final String requestId;
+
   private final RealmContext realmContext;
 
   private final RealmConfig realmConfig;
 
+  private static final String REQUEST_ID_KEY = "requestId";
+
   public PolarisCallContext(
       @Nonnull RealmContext realmContext,
       @Nonnull BasePersistence metaStore,
       @Nonnull PolarisDiagnostics diagServices,
       @Nonnull PolarisConfigurationStore configurationStore,
-      @Nonnull Clock clock) {
+      @Nonnull Clock clock,
+      ContainerRequestContext containerRequestContext) {

Review Comment:
   Attempted this in the next revision.



##########
service/common/src/main/java/org/apache/polaris/service/ratelimiter/RateLimiterFilter.java:
##########
@@ -56,7 +58,11 @@ public void filter(ContainerRequestContext ctx) throws 
IOException {
     if (!rateLimiter.canProceed()) {
       polarisEventListener.onBeforeRequestRateLimited(
           new BeforeRequestRateLimitedEvent(
-              ctx.getMethod(), ctx.getUriInfo().getAbsolutePath().toString()));
+              PolarisEvent.createEventId(),
+              ctx.getMethod(),
+              ctx.getUriInfo().getAbsolutePath().toString()),
+          CallContext.getCurrentContext(),
+          ctx.getSecurityContext());
       
ctx.abortWith(Response.status(Response.Status.TOO_MANY_REQUESTS).build());

Review Comment:
   Mostly, yes. But I personally don't see a use for storing this event, as I 
don't consider it as directly driven from a singular user action. And there are 
some valid concerns regarding a potential DDoS attack against the server (and 
potentially, database) through this event.
   
   I still see value in having this event for other use cases (i.e. 
alerting/logging, etc.) - but just not as an event that we would serve back to 
users through having a record in the persistence.



##########
persistence/relational-jdbc/src/main/resources/h2/schema-v1.sql:
##########
@@ -118,3 +118,17 @@ CREATE TABLE IF NOT EXISTS policy_mapping_record (
 );
 
 CREATE INDEX IF NOT EXISTS idx_policy_mapping_record ON policy_mapping_record 
(realm_id, policy_type_code, policy_catalog_id, policy_id, target_catalog_id, 
target_id);
+
+CREATE TABLE IF NOT EXISTS events (

Review Comment:
   Sorry, was not careful in removing it from the previous revision. Thanks for 
the catch!



-- 
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: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to