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


##########
runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListener.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.service.events.jsonEventListener.aws.cloudwatch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.SecurityContext;
+import java.time.Clock;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.service.events.jsonEventListener.JsonEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.regions.Region;
+import 
software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsAsyncClient;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamResponse;
+import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.ResourceAlreadyExistsException;
+
+@ApplicationScoped
+@Identifier("aws-cloudwatch")
+public class AwsCloudWatchEventListener extends JsonEventListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AwsCloudWatchEventListener.class);
+  private final ObjectMapper objectMapper = new ObjectMapper();
+
+  private CloudWatchLogsAsyncClient client;
+
+  private final String logGroup;
+  private final String logStream;
+  private final Region region;
+  private final boolean synchronousMode;
+  private final Clock clock;
+
+  @Inject CallContext callContext;
+
+  @Context SecurityContext securityContext;
+
+  @Inject
+  public AwsCloudWatchEventListener(AwsCloudWatchConfiguration config, Clock 
clock) {
+    this.logStream = config.awsCloudwatchlogStream();
+    this.logGroup = config.awsCloudwatchlogGroup();
+    this.region = Region.of(config.awsCloudwatchRegion());
+    this.synchronousMode = config.synchronousMode();
+    this.clock = clock;
+  }
+
+  @PostConstruct
+  void start() {
+    this.client = createCloudWatchAsyncClient();
+    ensureLogGroupAndStream();
+  }
+
+  protected CloudWatchLogsAsyncClient createCloudWatchAsyncClient() {
+    return CloudWatchLogsAsyncClient.builder().region(region).build();
+  }
+
+  private void ensureLogGroupAndStream() {
+    try {
+      CompletableFuture<CreateLogGroupResponse> future =
+          
client.createLogGroup(CreateLogGroupRequest.builder().logGroupName(logGroup).build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log group {} already exists", logGroup);
+      } else {
+        throw e;
+      }
+    }
+
+    try {
+      CompletableFuture<CreateLogStreamResponse> future =
+          client.createLogStream(
+              CreateLogStreamRequest.builder()
+                  .logGroupName(logGroup)
+                  .logStreamName(logStream)
+                  .build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log stream {} already exists", logStream);
+      } else {
+        throw e;
+      }
+    }
+  }
+
+  @PreDestroy
+  void shutdown() {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Override
+  protected void transformAndSendEvent(HashMap<String, Object> properties) {
+    properties.put("realm", 
callContext.getRealmContext().getRealmIdentifier());
+    properties.put("principal", securityContext.getUserPrincipal().getName());

Review Comment:
   I'm not sure this is a base requirement for this PR. If users see the 
activated roles as a good-to-have for this feature in the future, I'm happy to 
add that as a separate field as well.



##########
runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/JsonEventListener.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.service.events.jsonEventListener;
+
+import java.util.HashMap;
+import org.apache.polaris.service.events.AfterTableRefreshedEvent;
+import org.apache.polaris.service.events.PolarisEventListener;
+
+/**
+ * Abstract base class from which all event sinks that output events in JSON 
format can extend.
+ *
+ * <p>This class provides a common framework for transforming Polaris events 
into JSON format and

Review Comment:
   It does not, you're correct. I've renamed the class and changed the JavaDoc.



##########
site/content/in-dev/unreleased/configuration.md:
##########
@@ -117,7 +117,12 @@ read-only mode, as Polaris only reads the configuration 
file once, at startup.
 | `polaris.metrics.realm-id-tag.http-metrics-max-cardinality`                  
          | `100`                 | The maximum cardinality for the `realm_id` 
tag in HTTP request metrics.                                                    
                                                                                
                                                                                
                                                                   |
 | `polaris.tasks.max-concurrent-tasks`                                         
          | `100`                 | Define the max number of concurrent tasks.  
                                                                                
                                                                                
                                                                                
                                                                  |
 | `polaris.tasks.max-queued-tasks`                                             
          | `1000`                | Define the max number of tasks in queue.    
                                                                                
                                                                                
                                                                                
                                                                  |
- | `polaris.config.rollback.compaction.on-conflicts.enabled`                   
           | `false`              | When set to true Polaris will apply the 
deconfliction by rollbacking those REPLACE operations snapshots which have the 
property of `polaris.internal.rollback.compaction.on-conflict` in their 
snapshot summary set to `rollback`, to resolve conflicts at the server end.     
                                                                               |
+ | `polaris.config.rollback.compaction.on-conflicts.enabled`                   
           | `false`               | When set to true Polaris will apply the 
deconfliction by rollbacking those REPLACE operations snapshots which have the 
property of `polaris.internal.rollback.compaction.on-conflict` in their 
snapshot summary set to `rollback`, to resolve conflicts at the server end.     
                                                                               |
+| `polaris.event-listener.type`                                                
          | `no-op`               | Define the Polaris event listener type. 
Supported values are `no-op`, `aws-cloudwatch`.                                 
                                                                                
                                                                                
                                                                     |
+| `polaris.event-listener.aws-cloudwatch.log-group`                            
          |                       | Define the AWS CloudWatch log group name 
for the event listener.                                                         
                                                                                
                                                                                
                                                                     |
+| `polaris.event-listener.aws-cloudwatch.log-stream`                           
          |                       | Define the AWS CloudWatch log stream name 
for the event listener.                                                         
                                                                                
                                                                                
                                                                    |
+| `polaris.event-listener.aws-cloudwatch.region`                               
          |                       | Define the AWS region for the CloudWatch 
event listener.                                                                 
                                                                                
                                                                                
                                                                     |

Review Comment:
   Good catch - added.



##########
site/content/in-dev/unreleased/configuration.md:
##########
@@ -117,7 +117,12 @@ read-only mode, as Polaris only reads the configuration 
file once, at startup.
 | `polaris.metrics.realm-id-tag.http-metrics-max-cardinality`                  
          | `100`                 | The maximum cardinality for the `realm_id` 
tag in HTTP request metrics.                                                    
                                                                                
                                                                                
                                                                   |
 | `polaris.tasks.max-concurrent-tasks`                                         
          | `100`                 | Define the max number of concurrent tasks.  
                                                                                
                                                                                
                                                                                
                                                                  |
 | `polaris.tasks.max-queued-tasks`                                             
          | `1000`                | Define the max number of tasks in queue.    
                                                                                
                                                                                
                                                                                
                                                                  |
- | `polaris.config.rollback.compaction.on-conflicts.enabled`                   
           | `false`              | When set to true Polaris will apply the 
deconfliction by rollbacking those REPLACE operations snapshots which have the 
property of `polaris.internal.rollback.compaction.on-conflict` in their 
snapshot summary set to `rollback`, to resolve conflicts at the server end.     
                                                                               |
+ | `polaris.config.rollback.compaction.on-conflicts.enabled`                   
           | `false`               | When set to true Polaris will apply the 
deconfliction by rollbacking those REPLACE operations snapshots which have the 
property of `polaris.internal.rollback.compaction.on-conflict` in their 
snapshot summary set to `rollback`, to resolve conflicts at the server end.     
                                                                               |
+| `polaris.event-listener.type`                                                
          | `no-op`               | Define the Polaris event listener type. 
Supported values are `no-op`, `aws-cloudwatch`.                                 
                                                                                
                                                                                
                                                                     |
+| `polaris.event-listener.aws-cloudwatch.log-group`                            
          |                       | Define the AWS CloudWatch log group name 
for the event listener.                                                         
                                                                                
                                                                                
                                                                     |

Review Comment:
   Added it to this page, let me know your thoughts!



##########
runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListener.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.service.events.jsonEventListener.aws.cloudwatch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.SecurityContext;
+import java.time.Clock;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.service.events.jsonEventListener.JsonEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.regions.Region;
+import 
software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsAsyncClient;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamResponse;
+import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.ResourceAlreadyExistsException;
+
+@ApplicationScoped
+@Identifier("aws-cloudwatch")
+public class AwsCloudWatchEventListener extends JsonEventListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AwsCloudWatchEventListener.class);
+  private final ObjectMapper objectMapper = new ObjectMapper();

Review Comment:
   I've added the injection of the Iceberg Object Mapper and a test showing 
that it should be working as well - please do let me know if that works.



##########
runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListener.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.service.events.jsonEventListener.aws.cloudwatch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.SecurityContext;
+import java.time.Clock;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.service.events.jsonEventListener.JsonEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.regions.Region;
+import 
software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsAsyncClient;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamResponse;
+import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.ResourceAlreadyExistsException;
+
+@ApplicationScoped
+@Identifier("aws-cloudwatch")
+public class AwsCloudWatchEventListener extends JsonEventListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AwsCloudWatchEventListener.class);
+  private final ObjectMapper objectMapper = new ObjectMapper();
+
+  private CloudWatchLogsAsyncClient client;
+
+  private final String logGroup;
+  private final String logStream;
+  private final Region region;
+  private final boolean synchronousMode;
+  private final Clock clock;
+
+  @Inject CallContext callContext;
+
+  @Context SecurityContext securityContext;
+
+  @Inject
+  public AwsCloudWatchEventListener(AwsCloudWatchConfiguration config, Clock 
clock) {
+    this.logStream = config.awsCloudwatchlogStream();
+    this.logGroup = config.awsCloudwatchlogGroup();
+    this.region = Region.of(config.awsCloudwatchRegion());
+    this.synchronousMode = config.synchronousMode();
+    this.clock = clock;
+  }
+
+  @PostConstruct
+  void start() {
+    this.client = createCloudWatchAsyncClient();
+    ensureLogGroupAndStream();
+  }
+
+  protected CloudWatchLogsAsyncClient createCloudWatchAsyncClient() {
+    return CloudWatchLogsAsyncClient.builder().region(region).build();
+  }
+
+  private void ensureLogGroupAndStream() {
+    try {
+      CompletableFuture<CreateLogGroupResponse> future =
+          
client.createLogGroup(CreateLogGroupRequest.builder().logGroupName(logGroup).build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log group {} already exists", logGroup);
+      } else {
+        throw e;
+      }
+    }
+
+    try {
+      CompletableFuture<CreateLogStreamResponse> future =
+          client.createLogStream(
+              CreateLogStreamRequest.builder()
+                  .logGroupName(logGroup)
+                  .logStreamName(logStream)
+                  .build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log stream {} already exists", logStream);
+      } else {
+        throw e;
+      }
+    }
+  }
+
+  @PreDestroy
+  void shutdown() {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Override
+  protected void transformAndSendEvent(HashMap<String, Object> properties) {
+    properties.put("realm", 
callContext.getRealmContext().getRealmIdentifier());

Review Comment:
   That's correct. Let me rename the property!



##########
runtime/service/src/main/java/org/apache/polaris/service/quarkus/events/jsonEventListener/aws/cloudwatch/QuarkusAwsCloudWatchConfiguration.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.service.quarkus.events.jsonEventListener.aws.cloudwatch;
+
+import io.quarkus.runtime.annotations.StaticInitSafe;
+import io.smallrye.config.ConfigMapping;
+import io.smallrye.config.WithDefault;
+import io.smallrye.config.WithName;
+import jakarta.enterprise.context.ApplicationScoped;
+import 
org.apache.polaris.service.events.jsonEventListener.aws.cloudwatch.AwsCloudWatchConfiguration;
+
+/**
+ * Quarkus-specific configuration interface for AWS CloudWatch event listener 
integration.
+ *
+ * <p>This interface extends the base {@link AwsCloudWatchConfiguration} and 
provides
+ * Quarkus-specific configuration mappings for AWS CloudWatch logging 
functionality.
+ */
+@StaticInitSafe
+@ConfigMapping(prefix = "polaris.event-listener.aws-cloudwatch")
+@ApplicationScoped
+public interface QuarkusAwsCloudWatchConfiguration extends 
AwsCloudWatchConfiguration {
+
+  /**
+   * Returns the AWS CloudWatch log group name for event logging.
+   *
+   * <p>The log group is a collection of log streams that share the same 
retention, monitoring, and
+   * access control settings. If not specified, defaults to 
"polaris-cloudwatch-default-group".
+   *
+   * <p>Configuration property: {@code 
polaris.event-listener.aws-cloudwatch.log-group}
+   *
+   * @return a String containing the log group name, or the default value if 
not configured
+   */
+  @WithName("log-group")
+  @WithDefault("polaris-cloudwatch-default-group")
+  @Override
+  String awsCloudwatchlogGroup();

Review Comment:
   Good point, changed.



##########
runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListener.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.service.events.jsonEventListener.aws.cloudwatch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.SecurityContext;
+import java.time.Clock;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.service.events.jsonEventListener.JsonEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.regions.Region;
+import 
software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsAsyncClient;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogGroupResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.CreateLogStreamResponse;
+import software.amazon.awssdk.services.cloudwatchlogs.model.InputLogEvent;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsRequest;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.PutLogEventsResponse;
+import 
software.amazon.awssdk.services.cloudwatchlogs.model.ResourceAlreadyExistsException;
+
+@ApplicationScoped
+@Identifier("aws-cloudwatch")
+public class AwsCloudWatchEventListener extends JsonEventListener {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(AwsCloudWatchEventListener.class);
+  private final ObjectMapper objectMapper = new ObjectMapper();
+
+  private CloudWatchLogsAsyncClient client;
+
+  private final String logGroup;
+  private final String logStream;
+  private final Region region;
+  private final boolean synchronousMode;
+  private final Clock clock;
+
+  @Inject CallContext callContext;
+
+  @Context SecurityContext securityContext;
+
+  @Inject
+  public AwsCloudWatchEventListener(AwsCloudWatchConfiguration config, Clock 
clock) {
+    this.logStream = config.awsCloudwatchlogStream();
+    this.logGroup = config.awsCloudwatchlogGroup();
+    this.region = Region.of(config.awsCloudwatchRegion());
+    this.synchronousMode = config.synchronousMode();
+    this.clock = clock;
+  }
+
+  @PostConstruct
+  void start() {
+    this.client = createCloudWatchAsyncClient();
+    ensureLogGroupAndStream();
+  }
+
+  protected CloudWatchLogsAsyncClient createCloudWatchAsyncClient() {
+    return CloudWatchLogsAsyncClient.builder().region(region).build();
+  }
+
+  private void ensureLogGroupAndStream() {
+    try {
+      CompletableFuture<CreateLogGroupResponse> future =
+          
client.createLogGroup(CreateLogGroupRequest.builder().logGroupName(logGroup).build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log group {} already exists", logGroup);
+      } else {
+        throw e;
+      }
+    }
+
+    try {
+      CompletableFuture<CreateLogStreamResponse> future =
+          client.createLogStream(
+              CreateLogStreamRequest.builder()
+                  .logGroupName(logGroup)
+                  .logStreamName(logStream)
+                  .build());
+      future.join();
+    } catch (CompletionException e) {
+      if (e.getCause() instanceof ResourceAlreadyExistsException) {
+        LOGGER.debug("Log stream {} already exists", logStream);
+      } else {
+        throw e;
+      }
+    }
+  }
+
+  @PreDestroy
+  void shutdown() {
+    if (client != null) {
+      client.close();
+    }
+  }
+
+  @Override
+  protected void transformAndSendEvent(HashMap<String, Object> properties) {
+    properties.put("realm", 
callContext.getRealmContext().getRealmIdentifier());
+    properties.put("principal", securityContext.getUserPrincipal().getName());

Review Comment:
   Putting them as class-wide constants isn't a great idea IMO. These variables 
are RequestScoped, while the class as a whole is ApplicationScoped. The best we 
can probably do is to keep them as variables within the `transformAndSendEvent` 
function (which will run per request) - but I'm not sure what that helps to 
clarify.



##########
runtime/service/src/main/java/org/apache/polaris/service/quarkus/events/jsonEventListener/aws/cloudwatch/QuarkusAwsCloudWatchConfiguration.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.service.quarkus.events.jsonEventListener.aws.cloudwatch;
+
+import io.quarkus.runtime.annotations.StaticInitSafe;
+import io.smallrye.config.ConfigMapping;
+import io.smallrye.config.WithDefault;
+import io.smallrye.config.WithName;
+import jakarta.enterprise.context.ApplicationScoped;
+import 
org.apache.polaris.service.events.jsonEventListener.aws.cloudwatch.AwsCloudWatchConfiguration;
+
+/**
+ * Quarkus-specific configuration interface for AWS CloudWatch event listener 
integration.
+ *
+ * <p>This interface extends the base {@link AwsCloudWatchConfiguration} and 
provides
+ * Quarkus-specific configuration mappings for AWS CloudWatch logging 
functionality.
+ */
+@StaticInitSafe
+@ConfigMapping(prefix = "polaris.event-listener.aws-cloudwatch")
+@ApplicationScoped
+public interface QuarkusAwsCloudWatchConfiguration extends 
AwsCloudWatchConfiguration {
+
+  /**
+   * Returns the AWS CloudWatch log group name for event logging.
+   *
+   * <p>The log group is a collection of log streams that share the same 
retention, monitoring, and
+   * access control settings. If not specified, defaults to 
"polaris-cloudwatch-default-group".
+   *
+   * <p>Configuration property: {@code 
polaris.event-listener.aws-cloudwatch.log-group}
+   *
+   * @return a String containing the log group name, or the default value if 
not configured
+   */
+  @WithName("log-group")
+  @WithDefault("polaris-cloudwatch-default-group")
+  @Override
+  String awsCloudwatchlogGroup();
+
+  /**
+   * Returns the AWS CloudWatch log stream name for event logging.
+   *
+   * <p>A log stream is a sequence of log events that share the same source. 
Each log stream belongs
+   * to one log group. If not specified, defaults to 
"polaris-cloudwatch-default-stream".
+   *
+   * <p>Configuration property: {@code 
polaris.event-listener.aws-cloudwatch.log-stream}
+   *
+   * @return a String containing the log stream name, or the default value if 
not configured
+   */
+  @WithName("log-stream")
+  @WithDefault("polaris-cloudwatch-default-stream")
+  @Override
+  String awsCloudwatchlogStream();
+
+  /**
+   * Returns the AWS region where CloudWatch logs should be sent.
+   *
+   * <p>This specifies the AWS region for the CloudWatch service endpoint. The 
region must be a
+   * valid AWS region identifier. If not specified, defaults to "us-east-1".
+   *
+   * <p>Configuration property: {@code 
polaris.event-listener.aws-cloudwatch.region}
+   *
+   * @return a String containing the AWS region, or the default value if not 
configured
+   */
+  @WithName("region")
+  @WithDefault("us-east-1")
+  @Override
+  String awsCloudwatchRegion();

Review Comment:
   I believe as long as the AWS Credentials which are available to Polaris have 
access to GovCloud - and the Polaris networking is able to connect to AWS 
CloudWatch in a GovCloud region, this should continue to work. 



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