nastra commented on code in PR #7339:
URL: https://github.com/apache/iceberg/pull/7339#discussion_r1165483664


##########
core/src/main/java/org/apache/iceberg/rest/RESTMetricsReporter.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.rest;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.CommitReport;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.iceberg.metrics.MetricsReporter;
+import org.apache.iceberg.metrics.ScanReport;
+import org.apache.iceberg.relocated.com.google.common.base.Splitter;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RESTMetricsReporter implements MetricsReporter, Closeable {
+  private static final Logger LOG = 
LoggerFactory.getLogger(RESTMetricsReporter.class);
+  private static final Splitter DOT = Splitter.on('.');
+
+  private transient RESTClient client;
+  private transient ResourcePaths paths;
+
+  @Override
+  public void initialize(Map<String, String> properties) {
+    this.client = 
HTTPClient.builder(properties).uri(properties.get(CatalogProperties.URI)).build();
+    this.paths = ResourcePaths.forCatalogProperties(properties);
+  }
+
+  @Override
+  public void report(MetricsReport report) {
+    TableIdentifier tableIdentifier = null;
+    try {
+      // we need to derive the namespace + table name from the report itself
+      if (report instanceof ScanReport) {
+        ScanReport scanReport = (ScanReport) report;
+        tableIdentifier = identifierWithoutCatalog(scanReport.tableName());
+      } else if (report instanceof CommitReport) {
+        CommitReport commitReport = (CommitReport) report;
+        tableIdentifier = identifierWithoutCatalog(commitReport.tableName());
+      } else {
+        LOG.warn("Failed to derive namespace/table name from metrics report 
{}", report);
+      }
+
+      if (null != tableIdentifier) {
+        client.post(
+            paths.metrics(tableIdentifier),
+            ReportMetricsRequest.of(report),
+            null,
+            ImmutableMap.of(),

Review Comment:
   it's worth mentioning that this doesn't use any authorization headers to 
send a metrics report to the REST endpoint



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