You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2025/05/23 12:43:13 UTC

[PR] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

adutra opened a new pull request, #1662:
URL: https://github.com/apache/polaris/pull/1662

   As discussed in the ML, this PR introduces two flags to enable the inclusion of realm ID tags in API and HTTP metrics.
   
   They are both disabled by default.
   
   There is also a new safeguard: if the cardinality of realm IDs in HTTP metrics goes above a configurable threshold (100 by default), a warning is printed and no more HTTP metrics will be recorded. (Quarkus has a similar safeguard for URI tags in HTTP 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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java:
##########
@@ -22,17 +22,23 @@
 import io.micrometer.common.lang.Nullable;
 import jakarta.annotation.Nonnull;
 import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
 import org.apache.polaris.core.context.RealmContext;
 
 @ApplicationScoped
 public class QuarkusValueExpressionResolver implements ValueExpressionResolver {
 
+  @Inject QuarkusMetricsConfiguration metricsConfiguration;
+
   @Override
   public String resolve(@Nonnull String expression, @Nullable Object parameter) {
     // TODO maybe replace with CEL of some expression engine and make this more generic
-    if (parameter instanceof RealmContext realmContext && expression.equals("realmIdentifier")) {
+    if (metricsConfiguration.realmIdTag().apiMetricsEnabled()
+        && parameter instanceof RealmContext realmContext
+        && expression.equals("realmIdentifier")) {
       return realmContext.getRealmIdentifier();
     }
-    return null;
+    // FIXME cannot return null here, see https://github.com/quarkusio/quarkus/issues/47891
+    return "";

Review Comment:
   WFM



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java:
##########
@@ -22,17 +22,23 @@
 import io.micrometer.common.lang.Nullable;
 import jakarta.annotation.Nonnull;
 import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
 import org.apache.polaris.core.context.RealmContext;
 
 @ApplicationScoped
 public class QuarkusValueExpressionResolver implements ValueExpressionResolver {
 
+  @Inject QuarkusMetricsConfiguration metricsConfiguration;
+
   @Override
   public String resolve(@Nonnull String expression, @Nullable Object parameter) {
     // TODO maybe replace with CEL of some expression engine and make this more generic
-    if (parameter instanceof RealmContext realmContext && expression.equals("realmIdentifier")) {
+    if (metricsConfiguration.realmIdTag().apiMetricsEnabled()
+        && parameter instanceof RealmContext realmContext
+        && expression.equals("realmIdentifier")) {
       return realmContext.getRealmIdentifier();
     }
-    return null;
+    // FIXME cannot return null here, see https://github.com/quarkusio/quarkus/issues/47891
+    return "";

Review Comment:
   Not sure. I wasn't able to 100% verify this, but it seems that the empty string in a tag value is treated as no tag at all. Also the `???` is going to go away soon (fix coming in Quarkus 3.24).



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #1662:
URL: https://github.com/apache/polaris/pull/1662#discussion_r2109949347


##########
site/content/in-dev/unreleased/telemetry.md:
##########
@@ -47,6 +47,25 @@ polaris.metrics.tags.region=us-west-2
 Note that by default Polaris adds one tag: `application=Polaris`. You can override this tag by
 setting the `polaris.metrics.tags.application=<new-value>` property.
 
+### Realm ID Tag
+
+Polaris can add the realm ID as a tag to all API and HTTP request metrics. This is disabled by 
+default to prevent high cardinality issues, but can be enabled by setting the following properties:
+
+```properties
+polaris.metrics.realm-id-tag.enable-in-api-metrics=true
+polaris.metrics.realm-id-tag.enable-in-http-metrics=true
+```
+
+You should be particularly careful when enabling the realm ID tag in HTTP request metrics, as these
+metrics typically have a much higher cardinality than API request metrics.
+
+In order to prevent the number of tags from growing indefinitely and causing performance issues or
+crashing the server, the number of unique realm IDs in HTTP request metrics is limited to 100 by 
+default. If the number of unique realm IDs exceeds this value, a warning will be logged and no more
+HTTP request metrics will be recorded. This threshold can be changed by setting the 
+`polaris.metrics.realm-id-tag.http-metrics-max-cardinality` property.

Review Comment:
   To clarify this only applies when `polaris.metrics.realm-id-tag.enable-in-http-metrics` is set?



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java:
##########
@@ -22,17 +22,23 @@
 import io.micrometer.common.lang.Nullable;
 import jakarta.annotation.Nonnull;
 import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
 import org.apache.polaris.core.context.RealmContext;
 
 @ApplicationScoped
 public class QuarkusValueExpressionResolver implements ValueExpressionResolver {
 
+  @Inject QuarkusMetricsConfiguration metricsConfiguration;
+
   @Override
   public String resolve(@Nonnull String expression, @Nullable Object parameter) {
     // TODO maybe replace with CEL of some expression engine and make this more generic
-    if (parameter instanceof RealmContext realmContext && expression.equals("realmIdentifier")) {
+    if (metricsConfiguration.realmIdTag().apiMetricsEnabled()
+        && parameter instanceof RealmContext realmContext
+        && expression.equals("realmIdentifier")) {
       return realmContext.getRealmIdentifier();
     }
-    return null;
+    // FIXME cannot return null here, see https://github.com/quarkusio/quarkus/issues/47891
+    return "";

Review Comment:
   ```suggestion
       return "???";
   ```
   ... to indicate that it's "unknown"? (IIRC there was a similar usage of `???` elsewhere)



##########
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/metrics/RealmIdTagEnabledMetricsTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.quarkus.metrics;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import java.util.Map;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+@QuarkusTest
+@TestProfile(RealmIdTagEnabledMetricsTest.Profile.class)
+public class RealmIdTagEnabledMetricsTest extends MetricsTestBase {
+
+  public static class Profile implements QuarkusTestProfile {
+
+    @Override
+    public Map<String, String> getConfigOverrides() {
+      return Map.of(
+          "polaris.metrics.tags.environment",
+          "prod",
+          "polaris.realm-context.type",
+          "test",
+          "polaris.metrics.realm-id-tag.api-metrics-enabled",
+          "true",
+          "polaris.metrics.realm-id-tag.http-metrics-enabled",
+          "true");
+    }
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {"%s/metrics", "%s/q/metrics"})
+  public void testMetricsEmittedOnSuccessfulRequest(String endpoint) {
+    super.testMetricsEmittedOnSuccessfulRequest(endpoint, true);
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {"%s/metrics", "%s/q/metrics"})
+  public void testMetricsEmittedOnFailedRequest(String endpoint) {
+    super.testMetricsEmittedOnFailedRequest(endpoint, true);
+  }

Review Comment:
   I think you can eliminate the overrides with
   ```java
   @ConfigProperty("polaris.metrics.realm-id-tag.api-metrics-enabled")
   boolean apiMetricsEnabled;
   @ConfigProperty("polaris.metrics.realm-id-tag.http-metrics-enabled")
   boolean httpMetricsEnabled;
   ```
   and read those fields in the overridden functions.



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
site/content/in-dev/unreleased/telemetry.md:
##########
@@ -47,6 +47,25 @@ polaris.metrics.tags.region=us-west-2
 Note that by default Polaris adds one tag: `application=Polaris`. You can override this tag by
 setting the `polaris.metrics.tags.application=<new-value>` property.
 
+### Realm ID Tag
+
+Polaris can add the realm ID as a tag to all API and HTTP request metrics. This is disabled by 
+default to prevent high cardinality issues, but can be enabled by setting the following properties:
+
+```properties
+polaris.metrics.realm-id-tag.enable-in-api-metrics=true
+polaris.metrics.realm-id-tag.enable-in-http-metrics=true
+```
+
+You should be particularly careful when enabling the realm ID tag in HTTP request metrics, as these
+metrics typically have a much higher cardinality than API request metrics.
+
+In order to prevent the number of tags from growing indefinitely and causing performance issues or
+crashing the server, the number of unique realm IDs in HTTP request metrics is limited to 100 by 
+default. If the number of unique realm IDs exceeds this value, a warning will be logged and no more
+HTTP request metrics will be recorded. This threshold can be changed by setting the 
+`polaris.metrics.realm-id-tag.http-metrics-max-cardinality` property.

Review Comment:
   Yes.



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusMetricsConfiguration.java:
##########
@@ -19,11 +19,50 @@
 package org.apache.polaris.service.quarkus.metrics;
 
 import io.smallrye.config.ConfigMapping;
+import io.smallrye.config.WithDefault;
+import jakarta.validation.constraints.Min;
 import java.util.Map;
 
 @ConfigMapping(prefix = "polaris.metrics")
 public interface QuarkusMetricsConfiguration {
 
   /** Additional tags to include in the metrics. */
   Map<String, String> tags();
+
+  /** Configuration for the Realm ID metric tag. */
+  RealmIdTag realmIdTag();
+
+  interface RealmIdTag {
+
+    /**
+     * Whether to include the Realm ID tag in the API request metrics.
+     *
+     * <p>Beware that if the cardinality of this tag is too high, it can cause performance issues or
+     * even crash the server.
+     */
+    @WithDefault("false")
+    boolean apiMetricsEnabled();

Review Comment:
   nit: this reads a bit odd to me. It feels like all API metrics are disabled. How about `enabledInApiMetrics`?



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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

   > Re: the conventional commits message, I suppose this may need to be flagged as a breaking change. From my POV metrics constitute an API of the server too (API to observe metrics' values). Stopping to report ream ID tags is akin to removing a property from a JSON response. WDYT?
   
   Worth an explicit mention, yea


-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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


##########
quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java:
##########
@@ -22,17 +22,23 @@
 import io.micrometer.common.lang.Nullable;
 import jakarta.annotation.Nonnull;
 import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
 import org.apache.polaris.core.context.RealmContext;
 
 @ApplicationScoped
 public class QuarkusValueExpressionResolver implements ValueExpressionResolver {
 
+  @Inject QuarkusMetricsConfiguration metricsConfiguration;
+
   @Override
   public String resolve(@Nonnull String expression, @Nullable Object parameter) {
     // TODO maybe replace with CEL of some expression engine and make this more generic
-    if (parameter instanceof RealmContext realmContext && expression.equals("realmIdentifier")) {
+    if (metricsConfiguration.realmIdTag().apiMetricsEnabled()
+        && parameter instanceof RealmContext realmContext
+        && expression.equals("realmIdentifier")) {
       return realmContext.getRealmIdentifier();
     }
-    return null;
+    // FIXME cannot return null here, see https://github.com/quarkusio/quarkus/issues/47891
+    return "";

Review Comment:
   Not sure. I wasn't able to 100% verify this, but it seems that the empty string in a tag value is treated as not tag at all. Also the `???` is going to go away soon (fix coming in Quarkus 3.24).



-- 
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] feat(metrics): Mitigate potential performance issues with realm_id tag [polaris]

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

   > Re: the conventional commits message, I suppose this may need to be flagged as a breaking change. From my POV metrics constitute an API of the server too (API to observe metrics' values). Stopping to report ream ID tags is akin to removing a property from a JSON response. WDYT?
   
   Modified the initial commit to include a `BREAKING CHANGE` line. Is there another place to announce that kind of change?


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