You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "cccs-cat001 (via GitHub)" <gi...@apache.org> on 2025/10/24 11:26:25 UTC

[PR] Added interface for reporting metrics [polaris]

cccs-cat001 opened a new pull request, #2887:
URL: https://github.com/apache/polaris/pull/2887

   <!--
       Possible security vulnerabilities: STOP here and contact security@apache.org instead!
   
       Please update the title of the PR with a meaningful message - do not leave it "empty" or "generated"
       Please update this summary field:
   
       The summary should cover these topics, if applicable:
       * the motivation for the change
       * a description of the status quo, for example the current behavior
       * the desired behavior
       * etc
   
       PR checklist:
       - Do a self-review of your code before opening a pull request
       - Make sure that there's good test coverage for the changes included in this PR
       - Run tests locally before pushing a PR (./gradlew check)
       - Code should have comments where applicable. Particularly hard-to-understand
         areas deserve good in-line documentation.
       - Include changes and enhancements to the documentation (in site/content/in-dev/unreleased)
       - For Work In Progress Pull Requests, please use the Draft PR feature.
   
       Make sure to add the information BELOW this comment.
       Everything in this comment will NOT be added to the PR description.
   -->
   
   ### What changes were proposed in this pull request?
   I'm adding an interface to be able to code for the `/metrics` endpoint in the Iceberg REST API Spec. 
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some IRC features, you can provide some references of other IRC implementations / IRC spec.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   The metrics endpoint in Polaris is currently a no-op endpoint. In our organization we use it for auditing who is reading/writing tables, as this endpoint is called after every read/write with Iceberg. I added a default no-op implementation so that the behaviour remains the same, and I added a logging implementation to show how it could be used. 
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   it adds an optional configuration for telling the metrics endpoint how it should behave. the default behaviour is no change, however if the user sets the `polaris.metrics.reporting.type` to `logging` it will log the MetricsReport to INFO. There is also the ability to implement the interface for your own needs if necessary. 
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Polaris versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   Tests were added. it was also tested in a staging environment. 
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   
   ### CHANGELOG.md
   <!--
   If the changes need to be included in CHANGELOG.md, please add a line here and in CHANGELOG.md.
   -->
   


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465229707


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   I guess we would need to purge that table frequently. Not sure if it's a good default to store in persistence without providing the purge functionality. Could that be an alternate CDI bean?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465254115


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(

Review Comment:
   No I would recommend logging at INFO, but set this logger by default to OFF. Here is how to do it:
   
   https://github.com/apache/polaris/blob/519e127c5f01352d3efa305535a594c734b941b0/runtime/defaults/src/main/resources/application.properties#L73
   
   



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485849419


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   They can both be injected. I'm not sure we need to modify the interface.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465118140


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(

Review Comment:
   As in use LOGGER.debug to print the logs? I'm not so sure, someone may want these logged without having debug logs enabled. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3487153471

   The current CI failure actually demonstrates that we _must_ annotate the CDI bean with something – otherwise, it's not a CDI bean and so it's not included in the alternatives passed to the producer method.
   
   TLDR: `DefaultMetricsReport` must be annotated with `@ApplicationScoped`.
   
   cc @cccs-cat001 @dimas-b 


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478578556


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   I was following the pattern of the other functions where they passed the call along to the IcebergCatalogHandler



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485461539


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   A factory is `ApplicationScoped`(or `Singleton`), but a bean can be `ApplicationScoped` or `RequestScoped`:
   
   * Should the bean exist only during the lifespan of a request? If so, use [@RequestScoped](http://docs.oracle.com/javaee/7/api/javax/enterprise/context/RequestScoped.html).
   * Should the bean exist during the lifespan of the application and should the state of the bean be shared between all the requests? If so, use [@ApplicationScoped](http://docs.oracle.com/javaee/7/api/javax/enterprise/context/ApplicationScoped.html).
   
   So, to use `ApplicationScoped` here, a factory is probably clearer.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490501610


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   @cccs-cat001 please change the scope of the `DefaultMetricsReporter` bean to also `@ApplicationScoped` – there is no reason for it to be request-scoped.
   
   Once this change is done we should be good 🀞 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465297845


##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   Another way to test logger is to modify your reporter implementation like below:
   
   ```java
   @RequestScoped
   @Identifier("logging")
   public class LoggingMetricsReporter implements PolarisMetricsReporter {
     private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
   
     // A consumer that can be mocked in tests; production code uses the default consumer
     // which logs to the slf4j logger.
     private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
   
     public LoggingMetricsReporter() {
       this(
           (warehouse, table, metricsReport) ->
               LOGGER.info("{}.{}: {}", warehouse, table, metricsReport));
     }
   
     @VisibleForTesting
     public LoggingMetricsReporter(
         TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer) {
       this.reportConsumer = reportConsumer;
     }
   
     @Override
     public void reportMetric(String warehouse, TableIdentifier table, MetricsReport metricsReport) {
       reportConsumer.accept(warehouse, table, metricsReport);
     }
   }
   ```



##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   If that's not too much to ask, you could provide two tests:
   
   1. A simple unit test that tests the reporter in isolation, testing that messages are generated in the logs, using any of the techniques above.
   2. A `@QuarkusTest` using a mock reporter (you can inject one in your test using `@InjectMock`), testing that metrics received via the endpoint are correctly passed to the reporter.



##########
runtime/defaults/src/main/resources/application.properties:
##########
@@ -209,6 +209,9 @@ polaris.oidc.principal-roles-mapper.type=default
 # Polaris Credential Manager Config
 polaris.credential-manager.type=default
 
+# Configuration for the behaviour of the metrics endpoint
+polaris.metrics.reporting.type=default

Review Comment:
   Can we rename this to `polaris.iceberg-metrics.reporting.type`? I'm afraid users will be confuse this feature with "standard" server metrics (which are configured using `polaris.metrics.*`, cf line 153).



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,44 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+
+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.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String warehouse, TableIdentifier table, MetricsReport metricsReport) {
+    StringBuilder reportString = new StringBuilder();

Review Comment:
   1. I don't think you need this. The `toString()` methods for `ScanReport` and `CommitReport` are generated by Java Immutables and contain all the information already. Same for `TableIdentifier` the `toString()` method is well defined. 
   2. The log pattern is malformed, there is one dangling placeholder.
   
   Just this should be enough:
   
   ```java
   LOGGER.info("{}.{}: {}", warehouse, table, metricsReport);
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3444047607

   > I'm not sure how this PR relates to the `/metrics` endpoint in the Iceberg REST API, though πŸ€” Could you clarify, please?
   
   If that can help: I was also puzzled initially, but we are actually talking about this IRC endpoint:
   
   https://github.com/apache/polaris/blob/f7b5646308b0477f737e9e0615c4649b0a497805/spec/iceberg-rest-catalog-open-api.yaml#L1288
   
   


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478888173


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   thx :+1: 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2469505744


##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/DefaultMetricsReporterTest.java:
##########
@@ -0,0 +1,42 @@
+package org.apache.polaris.service.reporting;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import io.smallrye.mutiny.tuples.Functions.TriConsumer;
+import java.util.Map;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.polaris.service.catalog.Profiles;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+@TestProfile(DefaultMetricsReporterTest.Profile.class)

Review Comment:
   This is just a unit test, you don't need to start the whole application.
   ```suggestion
   ```



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.polaris.service.reporting;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import io.smallrye.mutiny.tuples.Functions.TriConsumer;

Review Comment:
   ```suggestion
   import org.apache.commons.lang3.function.TriConsumer;
   ```
   
   There is nothing wrong per se with Mutiny's `TriConsumer`, but the one from Commons Lang is more general-purpose.



##########
runtime/defaults/src/main/resources/application.properties:
##########
@@ -209,6 +209,11 @@ polaris.oidc.principal-roles-mapper.type=default
 # Polaris Credential Manager Config
 polaris.credential-manager.type=default
 
+# Configuration for the behaviour of the metrics endpoint
+polaris.iceberg-metrics.reporting.type=default
+# Set to INFO if you want to see iceberg metric reports printed to console
+quarkus.log.category."polaris.service.reporting".level=WARN

Review Comment:
   ```suggestion
   quarkus.log.category."org.apache.polaris.service.reporting".level=OFF
   ```



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.polaris.service.reporting;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import io.smallrye.mutiny.tuples.Functions.TriConsumer;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (warehouse, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", warehouse, table, metricsReport));
+  }
+
+  @VisibleForTesting
+  public DefaultMetricsReporter(

Review Comment:
   ```suggestion
    DefaultMetricsReporter(
   ```



##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/DefaultMetricsReporterTest.java:
##########
@@ -0,0 +1,42 @@
+package org.apache.polaris.service.reporting;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import io.smallrye.mutiny.tuples.Functions.TriConsumer;
+import java.util.Map;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.apache.polaris.service.catalog.Profiles;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+@TestProfile(DefaultMetricsReporterTest.Profile.class)
+public class DefaultMetricsReporterTest {
+
+  @Test
+  void testLogging() {
+    TriConsumer<String, TableIdentifier, MetricsReport> mockConsumer = mock(TriConsumer.class);
+    DefaultMetricsReporter reporter = new DefaultMetricsReporter(mockConsumer);
+    String warehouse = "testWarehouse";
+    TableIdentifier table = TableIdentifier.of("testNamespace", "testTable");
+    MetricsReport metricsReport = mock(MetricsReport.class);
+
+    reporter.reportMetric(warehouse, table, metricsReport);
+
+    verify(mockConsumer).accept(warehouse, table, metricsReport);
+  }
+
+  public static class Profile extends Profiles.DefaultProfile {
+    @Override
+    public Map<String, String> getConfigOverrides() {
+      return ImmutableMap.<String, String>builder()
+          .putAll(super.getConfigOverrides())
+          .put("quarkus.log.category.\"polaris.service.reporting\".level", "INFO")
+          .build();
+    }
+  }

Review Comment:
   ```suggestion
   ```



##########
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationBase.java:
##########
@@ -882,6 +882,27 @@ public void testCreateAndLoadTableWithReturnedEtag() {
     }
   }
 
+  @Test
+  public void testSendMetricsReport() {
+    Map<String, String> payload =
+        ImmutableMap.<String, String>builder()
+            .put("reportType", "SCAN_REPORT")
+            .put(
+                "report",
+                "{\"scanId\":\""
+                    + UUID.randomUUID()
+                    + "\",\"timestamp\":"
+                    + System.currentTimeMillis()
+                    + ",\"filesScanned\":1,\"rowsScanned\":100,\"metrics\":{\"bytesRead\":1024}}")
+            .build();
+    Invocation.Builder metricEndpoint =
+        catalogApi.request(
+            "v1/{cat}/namespaces/ns1/tables/tbl1/metrics", Map.of("cat", currentCatalogName));
+    try (Response response = metricEndpoint.post(Entity.json(payload))) {
+      assertThat(response).returns(Response.Status.NO_CONTENT.getStatusCode(), Response::getStatus);
+    }

Review Comment:
   ```suggestion
       ScanReport scanReport =
           ImmutableScanReport.builder()
               .tableName("tbl1")
               .schemaId(4)
               .addProjectedFieldIds(1, 2, 3)
               .addProjectedFieldNames("c1", "c2", "c3")
               .snapshotId(23L)
               .filter(Expressions.alwaysTrue())
               .scanMetrics(ScanMetricsResult.fromScanMetrics(ScanMetrics.noop()))
               .build();
       Invocation.Builder metricEndpoint =
           catalogApi.request(
               "v1/{cat}/namespaces/ns1/tables/tbl1/metrics", Map.of("cat", currentCatalogName));
       try (Response response = metricEndpoint.post(Entity.json(ReportMetricsRequest.of(scanReport)))) {
         assertThat(response).returns(Response.Status.NO_CONTENT.getStatusCode(), Response::getStatus);
       }
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2482983680


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   nit: 
   ```suggestion
     void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490659554


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   Actually, given this producer method, I do not think `DefaultMetricsReporter` needs a scope annotation at all. It is always created via this method.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3469144259

   As @adutra noted, let's wait at least until tomorrow for other people to have a chance at reviewing.
   
   Side note: we may want to add Authorization checks for metric reporting (in a follow-up PR, of course).


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2487347077


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   `PolarisMetricsReporter` is not request-scoped. Its CDI scope is not defined by this interfaces. The scope is defined by the producer method. `@ApplicationScoped` is correct given the current codebase. If the code ever changes to require per-request state, the produce will have to be adjusted... but such adjustments are not required now, IMHO.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478497368


##########
runtime/defaults/src/main/resources/application.properties:
##########
@@ -209,6 +209,11 @@ polaris.oidc.principal-roles-mapper.type=default
 # Polaris Credential Manager Config
 polaris.credential-manager.type=default
 
+# Configuration for the behaviour of the metrics endpoint
+polaris.iceberg-metrics.reporting.type=default
+# Set to INFO if you want to see iceberg metric reports printed to console

Review Comment:
   nit: it's not necessary "console" - the level will affect all log targets, AFAIK.



##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   Why not call `metricsReporter.reportMetric()` from this class?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3481557470

   Are we ok to merge? I see a lot of recent comments resolved, but no fresh approvals :sweat_smile: 


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485792080


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   > The correct fix for me is just to replace `@RequestScoped` with `@ApplicationScoped` in the producer method:
   
   +1



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2461029009


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   `config.type()` is fixed in runtime... Can this bean be `@ApplicationScoped`?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465341084


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(

Review Comment:
   okay this is fine. I just made 2 implementations to ensure that I was going down the right path anyways :P 
   
   I've dropped down to one implementation with the configurable logging. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478903453


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,6 +759,10 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    metricsReporter.reportMetric(prefix, tableIdentifier, reportMetricsRequest.report());

Review Comment:
   Sorry for causing disruption on this PR πŸ˜… We probably need to go through `prefixParser.prefixToCatalogName(realmContext, prefix)` here (cf. `withCatalog(...)`)... the previous version used the catalog name as `warehouse` in `metricsReporter.reportMetric()`, but `prefix` might be different.
   
   nit: it might be worth clarifying the meaning of `warehouse` in `PolarisMetricsReporter` too. In Polaris the usual term is "catalog name".



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2460697122


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {

Review Comment:
   So that was my original plan! But the iceberg `MetricsReporter` is intended for client-side operations, so implementing it won't suffice for the `/metrics` endpoint reporting. 
   
   It would be ideal to change the name of it so that it doesn't get confused, but I wasn't sure of a better name πŸ˜…



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2491167547


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   Annotating both places SGTM πŸ‘ Using `@ApplicationScoped`, right?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490775312


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   > Actually, given this producer method, I do not think DefaultMetricsReporter needs a scope annotation at all. It is always created via this method.
   
   Yes and no :-) It doesn't need the annotation but 1) all other beans in the same situation are annotated and 2) annotating the bean allows for direct injection, e.g. in a test:
   
   ```java
   @Inject @Identifier("default") MetricsReporter defaultMetricsReporter;
   ```
   
   So, I'm rather in favor of anotating both places, even if I understand that this can cause some confusion.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485769051


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (catalogName, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", catalogName, table, metricsReport));

Review Comment:
   This adds a lot of logging output. I'd prefer to have a no-op default implementation.



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;

Review Comment:
   Generally `TriConsumer` makes it difficult to reason about the argument types in lambda expressions.
   However, as this is only used as an implementation detail, it's okay.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485774436


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   I'm -1 on the factory approach, The factory approach in Polaris is generally used for creating _and caching_ realm-scoped beans. The producer method approach OTOH is used for selecting beans at runtime according to their `@Identifier`.
   
   Here, it's clearly an application-scoped bean, selectable at runtime with its `@Identifier`.
   
   The correct fix for me is just to replace `@RequestScoped` with `@ApplicationScoped` in the producer method:
   
   ```java
   @ApplicationScoped
   public MetricsReporter metricsReporter(...)
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485911345


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (catalogName, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", catalogName, table, metricsReport));

Review Comment:
   `OFF` SGTM as well.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2460701445


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   I'm not sure what those are πŸ˜… my intentions were to have the default behaviour remain the same, and adding that may change the default behaviour



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2461238732


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   πŸ˜„ - no worries, we can look into that later.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2461654615


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {

Review Comment:
   the iceberg implementation is definitely not what we want to extend/implement here - https://iceberg.apache.org/docs/1.10.0/docs/metrics-reporting
   
   it's a client side thing. but I can change the name of this interface to PolarisMetricsReporter to have that separation. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3467767394

   @cccs-cat001 One last thing and we are good to go: do you mind adding this blurb to the CHANGELOG.md file?
   
   ```markdown
   ### Highlights
   
   - Support for [Iceberg Metrics Reporting] has been introduced in Polaris. Out of the box, metrics can
     be printed to the logs by setting the `org.apache.polaris.service.reporting` logger level to `INFO` (it's
     set to `OFF` by default). Custom reporters can be implemented and configured to send metrics to
     external systems for further analysis and monitoring.
   
   [Iceberg Metrics Reporting]: https://iceberg.apache.org/docs/latest/metrics-reporting/
   ```


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2494275068


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {

Review Comment:
   there was another TODO mentioned here https://github.com/apache/polaris/pull/2887#issuecomment-3469144259 
   
   If my time allows I'd be happy to help contribute that, and if we can get the requirements defined beforehand :) 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2492462348


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {

Review Comment:
   Not a blocker: would the name `IcebergMetricsReporter` be more descriptive as this is only for iceberg tables, other tables managed by Polaris won't be able to report the metrics?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2464392287


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   My recommendation was to store them in persistence, so that later we can serve them later, I recommend the same to @pingtimeout https://lists.apache.org/thread/koogjvb73hbl9ospmm7owsdx8oh67wk1



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    LOGGER.info(prefix);

Review Comment:
   Agree, Also i would recommend adding table uuid in the logs



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465229707


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   I guess we would need to purge that table frequently. Not sure if it's a good default to store in persistence without providing the purge functoinality. Could that be an alternate CDI bean?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485890270


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")

Review Comment:
   For context, the author had initially 2 beans, a no-op and a logging one. 
   
   I am the one that suggested that we could combine both together, since the logger level could be OFF by default. I still don't see why we would have 2, but fair enough.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490654495


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped

Review Comment:
   Makes sense! Good catch!



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3488046889

   Okay final answer (hopefully!!!) 


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485774436


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   I'm -1 on the factory approach, The factory approach in Polaris is generally used for creating _and caching_ realm-scoped beans. The producer method approach OTOH is used for selecting beans at runtime according to their `@Identifier`.
   
   Here, it's clearly an application-scoped bean, selectable at runtime with its `@IIdentifier`.
   
   The correct fix for me is just to replace `@RequestScoped` with `@ApplicationScoped` in the producer method:
   
   ```java
   @ApplicationScoped
   public MetricsReporter metricsReporter(...)
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2488106578


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped

Review Comment:
   Can we remove this scope annotation if this is meant to be application scoped? More details are here, https://github.com/apache/polaris/pull/2887/files#r2487347077



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3457759652

   I'm staring at the logs of the two failed checks and I'm not really sure what the cause of the errors are. Do you have any advice? πŸ˜…


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2483195184


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   [non-blocking] don't we need stuff like realm-id / authenitcated polaris prinicipals etc in this ? It would be really helpful to see which table is read most by which service prinicipal



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478914308


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,6 +759,10 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    metricsReporter.reportMetric(prefix, tableIdentifier, reportMetricsRequest.report());

Review Comment:
   That's right, I asked for it previously:
   
   https://github.com/apache/polaris/pull/2887#discussion_r2460410478
   
   And then I forgot about it πŸ˜† 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2460365883


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    LOGGER.info(prefix);

Review Comment:
   It would be better to consolidate all information into a single message. This is because the four lines are not guaranteed to appear consecutively in the logs.



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {

Review Comment:
   Iceberg already has a `MetricsReporter` and a `LoggingMetricsReporter`. I suppose you created new ones because you wanted to pass the warehouse and namespace names as well? In this case would it be possible to _extend_ Iceberg's `MetricsReporter`? 



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest);

Review Comment:
   1. I would rather rename `prefix` to `warehouse` or `catalogName` since `prefix` is a REST-specific notion. 
       1. But you should to call `prefixParser.prefixToCatalogName(realmContext, prefix)` to get the catalog name from the prefix.
   2. For a richer API, I would use `TableIdentifier` rather than 2 strings (namespace + table). It's very easy to get a `TableIdentifier`:
       ```java
       Namespace ns = decodeNamespace(namespace);
       TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
       ```



##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   These tests are rather useless as they are basically testing SmallRye Config.
   
   What would be more meaningful is a real test that invokes the IRC metrics endpoint and verifies that metrics were collected.



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/LoggingMetricsReporter.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("logging")
+public class LoggingMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(LoggingMetricsReporter.class);
+
+  @Override
+  public void reportMetric(

Review Comment:
   I'm not sure we need a distinct logging reporter. The default reporter could log the metrics, then users could simply adjust their log levels and decide whether they want the metrics to appear in the logs or not (by default, they wouldn't be logged). WDYT?



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   1. Would it make sense to define and maintain a set of Micrometer metrics and increment them here?
   2. Would it make sense to fire a `PolarisEvent` here?
   
   (I don't really know what an IRC server is supposed to do with these scan or commit metrics πŸ˜…)



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2486620376


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   that's the reason why I made this interface :P I'm injecting them with my private implementation just fine. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "pingtimeout (via GitHub)" <gi...@apache.org>.
pingtimeout commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485939226


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (catalogName, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", catalogName, table, metricsReport));

Review Comment:
   πŸ‘ 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490400656


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   So... am I meant to change something? `ServiceProducer::metricsReporter` is `@ApplicationScoped`, and the default implementation of `PolarisMetricsReporter`, `DefaultMetricsReporter` is `@RequestScoped`. Is that a problem?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2483194389


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,19 @@
+package org.apache.polaris.service.reporting;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements MetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  @Override
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest) {
+    // Do Nothing

Review Comment:
   Agree, though It can be any persistence, not necessarily an OLTP imho an OLAP is a valid consideration too, so is dumping in object storge so analytical engines can make a table on top of from Polaris POV, it seems to me that we are settling on catalog name and tble identifiers in addition to report from interface POV, why is realm-id not part of it is my doubt, why is authenticate prinicipals not part of these metric ?
   



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478920133


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,6 +759,10 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    metricsReporter.reportMetric(prefix, tableIdentifier, reportMetricsRequest.report());

Review Comment:
   oops got lost in the noise πŸ˜…



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2493923087


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {

Review Comment:
   Good point. But let's merge this PR (the author has been kind enough to address our collective feedback for two weeks now) and address this one in a follow-up task.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3490469102

   Thanks you so much @cccs-cat001 for your contribution – and your patience πŸ˜… 


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra merged PR #2887:
URL: https://github.com/apache/polaris/pull/2887


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2461249231


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {

Review Comment:
   I see. Would something like this suit your needs?
   
   ```java
   public interface PolarisMetricsReporter extends MetricsReporter {
     void report(String catalog, TableIdentifier table, MetricsReport report);
   }
   ```



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2461251107


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReporter.java:
##########
@@ -0,0 +1,8 @@
+package org.apache.polaris.service.reporting;
+
+import org.apache.iceberg.rest.requests.ReportMetricsRequest;
+
+public interface MetricsReporter {
+  public void reportMetric(
+      String prefix, String namespace, String table, ReportMetricsRequest reportMetricsRequest);

Review Comment:
   I forgot: it's probably better to pass `MetricsReport` here, not `ReportMetricsRequest`.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3461402668

   > I'm staring at the logs of the two failed checks and I'm not really sure what the cause of the errors are. Do you have any advice? πŸ˜…
   
   You have 4 files without license header:
   
   ```
   runtime/service/src/test/java/org/apache/polaris/service/reporting/DefaultMetricsReporterTest.java
   runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java
   runtime/service/src/main/java/org/apache/polaris/service/reporting/MetricsReportingConfiguration.java
   runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java
   ```
   
   The other error occurred while pulling a Docker image. It's a transient error.


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478701264


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   I agree it would be slightly better.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478903453


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,6 +759,10 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    metricsReporter.reportMetric(prefix, tableIdentifier, reportMetricsRequest.report());

Review Comment:
   Sorry for cause disruption on this PR πŸ˜… We probably need to go through `prefixParser.prefixToCatalogName(realmContext, prefix)` here (cf. `withCatalog(...)`)... the previous version used the catalog name as `warehouse` in `metricsReporter.reportMetric()`, but `prefix` might be different.
   
   nit: it might be worth clarifying the meaning of `warehouse` in `PolarisMetricsReporter` too. In Polaris the usual term is "catalog name".



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478684323


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   Yes, that pattern exists for "catalog" operations... however, in this case the "catalog" does not really handle anything in the metrics reports. I do not really see a need to for an extra indirection layer (i.e. `catalog.reportMetric(...)`). It seems quite possible to call the `metricsReporter` directly from `IcebergCatalogAdapter`. The benefit is avoiding non-functional changes in `catalog`. WDYT?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2487347077


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   `PolarisMetricsReporter` is not request-scoped. Its CDI scope is not defined by this interfaces. The scope is defined by the producer method. `@ApplicationScoped` is correct given the current codebase. If the code ever changes to require per-request state, the producer will have to be adjusted... but such adjustments are not required now, IMHO.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #2887:
URL: https://github.com/apache/polaris/pull/2887#issuecomment-3487170639

   TIL: re: bean annotations :sweat_smile: Like I commented on the specific thread (above) I'm ok with annotating both the bean and the produced with `@ApplicationScoped`


-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2490722505


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   Okay I see, I think you're right and we don't need the annotation. Other examples with @ApplicationScope in the ServiceProducer follow the same pattern. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485888424


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")

Review Comment:
   We already have a dozen CDI beans named `default`. Why is this one problematic?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "pingtimeout (via GitHub)" <gi...@apache.org>.
pingtimeout commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485949045


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")

Review Comment:
   > I am the one that suggested that we could combine both together, since the logger level could be OFF by default. I still don't see why we would have 2, but fair enough. 
   
   I am ok with a single bean, that was just a link to Robert's other comment.
   
   > We already have a dozen CDI beans named default. Why is this one problematic?
   
   I was not aware of that :-).  I don't this this one is _more_ problematic than any other.  This is just an attempt at having clearer names.  Feel free to consider this as a nit.  If this name is consistent with the rest of the codebase, I guess `default` is fine.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2487221322


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   I don't think my concern was addressed.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2484948175


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   Good point. I think prinicipals are super useful for audit use cases. 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2484947428


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -405,4 +407,11 @@ public PolarisCredentialManager polarisCredentialManager(
   public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
     executor.close();
   }
+
+  @Produces
+  @RequestScoped
+  public MetricsReporter metricsReporter(
+      MetricsReportingConfiguration config, @Any Instance<MetricsReporter> reporters) {
+    return reporters.select(Identifier.Literal.of(config.type())).get();

Review Comment:
   This producer is annotated `@ApplicationScoped` but it returns a `PolarisMetricsReporter`, which is `@RequestScoped`. That’s problematic in CDI because an `@ApplicationScoped` bean lives for the entire application lifecycle, while a `@RequestScoped` bean only lives for a single request.
   If the reporter (or a future implementation) ever injects request-scoped beans like `RealmContext` or `SecurityContext`, this setup would either fail at deployment or produce invalid references once the request ends.
   
   Instead of producing a reporter directly in an app-scoped producer, introduce a small factory:
   
   ```java
   @ApplicationScoped
   public class PolarisMetricsReporterFactory {
   
     public PolarisMetricsReporter getOrCreate(String type) {
   
     }
   }
   ```
   
   Similar to `MetaStoreManagerFactory`,  which ensure the scope correct, while avoid creating a new object for every request. It is also more flexible when we introduce more reporter types. 
   



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2484948175


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/PolarisMetricsReporter.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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 org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+
+public interface PolarisMetricsReporter {
+  public void reportMetric(String catalogName, TableIdentifier table, MetricsReport metricsReport);

Review Comment:
   Good point. I think it's super useful for audit use cases.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "pingtimeout (via GitHub)" <gi...@apache.org>.
pingtimeout commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485873415


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (catalogName, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", catalogName, table, metricsReport));

Review Comment:
   @snazy note that by default the log level for this package is set to `OFF`.  So what this code will do is perform a boolean check every time and return.
   
   That being said, I would also prefer to have a `no-op` implementation as well as this `logging` implementation and have the `polaris.iceberg-metrics.reporting.type` config parameter be very explicit on which one is picked, instead of relying on logging configuration to achieve the same goal.



##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")

Review Comment:
   Would it be possible to use another name than `default` here?  This currently results in the configuration file saying "The default value for polaris.iceberg-metrics.reporting.type is `default`", which does not give any meaningful information.
   
   This class could probably be named `LoggingMetricsReporter` and have a `logging` identifier.  Then as @snazy suggests, there could be a `no-op` reporter that does nothing.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2485851253


##########
runtime/service/src/main/java/org/apache/polaris/service/reporting/DefaultMetricsReporter.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import io.smallrye.common.annotation.Identifier;
+import jakarta.enterprise.context.RequestScoped;
+import org.apache.commons.lang3.function.TriConsumer;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.metrics.MetricsReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RequestScoped
+@Identifier("default")
+public class DefaultMetricsReporter implements PolarisMetricsReporter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMetricsReporter.class);
+
+  private final TriConsumer<String, TableIdentifier, MetricsReport> reportConsumer;
+
+  public DefaultMetricsReporter() {
+    this(
+        (catalogName, table, metricsReport) ->
+            LOGGER.info("{}.{}: {}", catalogName, table, metricsReport));

Review Comment:
   This logger is OFF by default.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478686487


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   @adutra : what 's your take on this?



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2478787026


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java:
##########
@@ -755,7 +760,16 @@ public Response reportMetrics(
       ReportMetricsRequest reportMetricsRequest,
       RealmContext realmContext,
       SecurityContext securityContext) {
-    return Response.status(Response.Status.NO_CONTENT).build();
+
+    Namespace ns = decodeNamespace(namespace);
+    TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table));
+    return withCatalog(
+        securityContext,
+        prefix,
+        catalog -> {
+          catalog.reportMetric(prefix, tableIdentifier, reportMetricsRequest);

Review Comment:
   oh yeah I see, you're totally right! I'll clean that up



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465970762


##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   hoping those tests I added are what you were looking for πŸ˜…



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465249180


##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   Yes, but it's a bit convoluted unfortunately. Have a look at `ExceptionMapperTest`: https://github.com/apache/polaris/blob/c2e932b7064e7ae5551e192c8dd273de2da9fd0d/runtime/service/src/test/java/org/apache/polaris/service/exception/ExceptionMapperTest.java#L52.



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added interface for reporting metrics [polaris]

Posted by "cccs-cat001 (via GitHub)" <gi...@apache.org>.
cccs-cat001 commented on code in PR #2887:
URL: https://github.com/apache/polaris/pull/2887#discussion_r2465176912


##########
runtime/service/src/test/java/org/apache/polaris/service/reporting/MetricsReportingConfigurationTest.java:
##########
@@ -0,0 +1,46 @@
+package org.apache.polaris.service.reporting;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+public class MetricsReportingConfigurationTest {
+  @Inject MetricsReportingConfiguration metricsConfig;
+
+  @Test
+  @TestProfile(MetricsReportingConfiguration.DefaultProfile.class)
+  void testDefault() {

Review Comment:
   hmm is there a way to verify that something was logged? 



-- 
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-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org