rajarshisarkar commented on code in PR #7444:
URL: https://github.com/apache/iceberg/pull/7444#discussion_r1221475741


##########
aws/src/main/java/org/apache/iceberg/aws/metrics/SqsClientFactory.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.iceberg.aws.metrics;
+
+import java.io.Serializable;
+import java.util.Map;
+import org.apache.iceberg.aws.HttpClientProperties;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import software.amazon.awssdk.services.sqs.SqsAsyncClient;
+
+/** Factory class for SQS client */
+public class SqsClientFactory implements Serializable {

Review Comment:
   I have introduced `SqsMetricsReporterAwsClientFactory` interface.



##########
aws/src/main/java/org/apache/iceberg/aws/metrics/SqsMetricsReporter.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.iceberg.aws.metrics;
+
+import java.util.Map;
+import org.apache.iceberg.metrics.CommitReport;
+import org.apache.iceberg.metrics.CommitReportParser;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.iceberg.metrics.MetricsReporter;
+import org.apache.iceberg.metrics.ScanReport;
+import org.apache.iceberg.metrics.ScanReportParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.sqs.SqsAsyncClient;
+import software.amazon.awssdk.services.sqs.model.SendMessageRequest;
+
+/** An implementation of {@link MetricsReporter} which reports {@link 
MetricsReport} to SQS */
+public class SqsMetricsReporter implements MetricsReporter {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(SqsMetricsReporter.class);
+
+  private SqsAsyncClient sqsClient;
+
+  private String sqsQueueUrl;
+
+  public SqsMetricsReporter() {}
+
+  public SqsMetricsReporter(SqsAsyncClient sqsClient, String sqsQueueUrl) {
+    this.sqsClient = sqsClient;
+    this.sqsQueueUrl = sqsQueueUrl;
+  }
+
+  @Override
+  public void initialize(Map<String, String> properties) {
+    SqsMetricsReporterProperties sqsMetricsReporterProperties =
+        new SqsMetricsReporterProperties(properties);
+    SqsClientFactory sqsClientFactory = new SqsClientFactory(properties);
+    this.sqsClient = sqsClientFactory.sqs();
+    this.sqsQueueUrl = sqsMetricsReporterProperties.sqsQueueUrl();
+  }
+
+  @Override
+  public void report(MetricsReport report) {
+    if (null == report) {
+      LOG.warn("Received invalid metrics report: null");
+      return;
+    }
+
+    try {
+      String message = null;
+      if (report instanceof CommitReport) {
+        message = CommitReportParser.toJson((CommitReport) report);
+      } else if (report instanceof ScanReport) {
+        message = ScanReportParser.toJson((ScanReport) report);
+      }
+
+      if (null == message) {
+        LOG.warn("Received unknown MetricsReport type");
+        return;
+      }
+
+      LOG.info("Received metrics report: {}", message);
+      sqsClient.sendMessage(
+          
SendMessageRequest.builder().messageBody(message).queueUrl(sqsQueueUrl).build());

Review Comment:
   Added the callback.



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