Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x Fix nested config prefix for observer settings #8010

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: might be nice to append something like: "which is server.features.observe.observers.."

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