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-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org