From ef55462c10c336da4fccb5077b6528b9ea0e50a5 Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Fri, 17 Nov 2023 11:22:45 -0600 Subject: [PATCH] Fix nested config prefix for observer settings (#8010) --- .../health/HealthCdiExtension.java | 2 +- .../microprofile/health/NestedConfigTest.java | 46 +++++++++++++++++++ .../metrics/MetricsCdiExtension.java | 2 +- .../HelidonRestCdiExtension.java | 10 ++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 microprofile/health/src/test/java/io/helidon/microprofile/health/NestedConfigTest.java diff --git a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java index 0217daab277..8d806a6654b 100644 --- a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java +++ b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java @@ -58,7 +58,7 @@ public Class annotationType() { * Creates a new instance of the health CDI extension. */ public HealthCdiExtension() { - super(LOGGER, "observe.providers.health", "health"); + super(LOGGER, nestedConfigKey("health"), "health"); } /** diff --git a/microprofile/health/src/test/java/io/helidon/microprofile/health/NestedConfigTest.java b/microprofile/health/src/test/java/io/helidon/microprofile/health/NestedConfigTest.java new file mode 100644 index 00000000000..474a806f9dd --- /dev/null +++ b/microprofile/health/src/test/java/io/helidon/microprofile/health/NestedConfigTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed 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 io.helidon.microprofile.health; + +import io.helidon.microprofile.testing.junit5.AddConfig; +import io.helidon.microprofile.testing.junit5.HelidonTest; + +import jakarta.inject.Inject; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +@HelidonTest() +@AddConfig(key = "server.features.observe.observers.health.details", value = "false") +class NestedConfigTest { + + @Inject + private WebTarget webTarget; + + @Test + void checkForNoDetailsWithConfigNested() { + Response response = webTarget.path("/health") + .request() + .accept(MediaType.APPLICATION_JSON) + .get(); + + assertThat("Response status", response.getStatus(), is(204)); + } +} diff --git a/microprofile/metrics/src/main/java/io/helidon/microprofile/metrics/MetricsCdiExtension.java b/microprofile/metrics/src/main/java/io/helidon/microprofile/metrics/MetricsCdiExtension.java index 9bc4f175372..b1a8a362b10 100644 --- a/microprofile/metrics/src/main/java/io/helidon/microprofile/metrics/MetricsCdiExtension.java +++ b/microprofile/metrics/src/main/java/io/helidon/microprofile/metrics/MetricsCdiExtension.java @@ -175,7 +175,7 @@ public class MetricsCdiExtension extends HelidonRestCdiExtension { * Creates a new extension instance. */ public MetricsCdiExtension() { - super(LOGGER, "observe.providers.metrics", "metrics"); + super(LOGGER, nestedConfigKey("metrics"), "metrics"); } /** diff --git a/microprofile/service-common/src/main/java/io/helidon/microprofile/servicecommon/HelidonRestCdiExtension.java b/microprofile/service-common/src/main/java/io/helidon/microprofile/servicecommon/HelidonRestCdiExtension.java index 09617b30d53..4b4ac2bed5d 100644 --- a/microprofile/service-common/src/main/java/io/helidon/microprofile/servicecommon/HelidonRestCdiExtension.java +++ b/microprofile/service-common/src/main/java/io/helidon/microprofile/servicecommon/HelidonRestCdiExtension.java @@ -254,6 +254,16 @@ protected HttpRouting.Builder routingBuilder(ServerCdiExtension server) { : server.serverNamedRoutingBuilder(routingName); } + /** + * Returns the config key for settings for the specified suffix nested within the server config tree. + * + * @param suffix the config key suffix (typically the name of the component: e.g., health) + * @return full nested config key for the specified suffix + */ + protected static String nestedConfigKey(String suffix) { + return "server.features.observe.observers." + suffix; + } + /** * Configure with runtime config. *