obelix74 commented on code in PR #3385:
URL: https://github.com/apache/polaris/pull/3385#discussion_r2833859845


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PersistingMetricsReporter.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.inject.Inject;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.CommitReport;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.iceberg.metrics.ScanReport;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityCore;
+import org.apache.polaris.core.entity.PolarisEntitySubType;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.metrics.iceberg.MetricsRecordConverter;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.dao.entity.EntityResult;
+import org.apache.polaris.core.persistence.metrics.CommitMetricsRecord;
+import org.apache.polaris.core.persistence.metrics.MetricsPersistence;
+import org.apache.polaris.core.persistence.metrics.ScanMetricsRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of {@link PolarisMetricsReporter} that persists metrics to 
the configured {@link
+ * MetricsPersistence} backend.
+ *
+ * <p>This reporter is selected when {@code 
polaris.iceberg-metrics.reporting.type} is set to {@code
+ * "persisting"}.
+ *
+ * <p>The reporter looks up the catalog entity by name to obtain the catalog 
ID, then uses {@link
+ * MetricsRecordConverter} to convert Iceberg metrics reports to SPI records 
before persisting them.
+ *
+ * @see PolarisMetricsReporter
+ * @see MetricsPersistence
+ * @see MetricsRecordConverter
+ */
+@RequestScoped
+@Identifier("persisting")
+public class PersistingMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PersistingMetricsReporter.class);
+
+  private final CallContext callContext;
+  private final PolarisMetaStoreManager metaStoreManager;
+  private final MetricsPersistence metricsPersistence;
+
+  @Inject
+  public PersistingMetricsReporter(
+      CallContext callContext,
+      PolarisMetaStoreManager metaStoreManager,
+      MetricsPersistence metricsPersistence) {
+    this.callContext = callContext;
+    this.metaStoreManager = metaStoreManager;
+    this.metricsPersistence = metricsPersistence;
+  }
+
+  @Override
+  public void reportMetric(
+      String catalogName,
+      TableIdentifier table,
+      MetricsReport metricsReport,
+      Instant receivedTimestamp) {
+
+    // Look up the catalog entity to get the catalog ID
+    EntityResult catalogResult =

Review Comment:
   Addressed by passing catalogId and tableId directly from 
IcebergCatalogHandler.reportMetrics() where entities are already resolved 
during authorization. This eliminates the multiple lookupsthat were happening 
in PersistingMetricsReporter.



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

Reply via email to