Skip to content

Commit

Permalink
Fix nested config prefix for observer settings (helidon-io#8010)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjquinno authored Nov 17, 2023
1 parent fa71b68 commit ef55462
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Class<? extends Annotation> annotationType() {
* Creates a new instance of the health CDI extension.
*/
public HealthCdiExtension() {
super(LOGGER, "observe.providers.health", "health");
super(LOGGER, nestedConfigKey("health"), "health");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit ef55462

Please sign in to comment.