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


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PersistingMetricsReporter.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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 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.metrics.iceberg.MetricsRecordConverter;
+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 receives catalog and table IDs from the caller (already 
resolved during
+ * authorization), avoiding redundant entity lookups. It 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 {

Review Comment:
   Fixed in commit 192489d0d.  I am not sure if this is what you intended here.
   
   Updated PersistingMetricsReporter to use CallContext (which provides access 
to PolarisMetaStoreManager / BasePersistence) instead of directly injecting 
MetricsPersistence.
   
      Changes Made:
   
        1. `PersistingMetricsReporter.java`:
           • Now injects CallContext, Instance<PolarisPrincipal>, and 
Instance<RequestIdSupplier> instead of MetricsPersistence
           • Gets BasePersistence from 
callContext.getPolarisCallContext().getMetaStore()
           • Checks if BasePersistence is a JdbcBasePersistenceImpl with a 
metrics datasource
           • Sets up request context (setMetricsRequestContext()) before 
writing metrics
           • Falls back to MetricsPersistence.NOOP if metrics persistence is 
not available
   
        2. `ServiceProducers.java`:
           • Removed the metricsPersistence() producer method (no longer needed)
           • Removed unused imports (MetricsPersistence, 
JdbcBasePersistenceImpl, RequestIdSupplier)
   
        3. `ServiceProducersIT.java`:
           • Removed the JdbcMetricsPersistenceTest class that was testing the 
removed producer
           • Removed unused imports



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