Polish "Filter properties with a particular prefix"

See gh-24718
pull/25178/head
Stephane Nicoll 4 years ago
parent ad7c69a9cd
commit b92bb9332b

@ -25,13 +25,14 @@ The response contains details of the application's `@ConfigurationProperties` be
The following table describes the structure of the response:
[cols="2,1,3"]
include::{snippets}/configprops/response-fields.adoc[]
include::{snippets}/configprops/all/response-fields.adoc[]
[[configprops-retrieving-by-prefix]]
== Retrieving @ConfigurationProperties Beans By Prefix
To retrieve the `@ConfigurationProperties` beans mapped under a certain prefix, make a `GET` request to `/actuator/configprops/{prefix}`, as shown in the following curl-based example:
To retrieve the `@ConfigurationProperties` beans mapped under a certain prefix, make a `GET` request to `/actuator/configprops/\{prefix}`, as shown in the following curl-based example:
include::{snippets}/configprops/prefixed/curl-request.adoc[]
@ -39,7 +40,9 @@ The resulting response is similar to the following:
include::{snippets}/configprops/prefixed/http-response.adoc[]
NOTE: The `{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem.
NOTE: The `\{prefix}` does not need to be exact, a more general prefix will return all beans mapped under that prefix stem.
[[configprops-retrieving-by-prefix-response-structure]]
=== Response Structure
@ -48,4 +51,4 @@ The response contains details of the application's `@ConfigurationProperties` be
The following table describes the structure of the response:
[cols="2,1,3"]
include::{snippets}/configprops/prefixed/response-fields.adoc[]
include::{snippets}/configprops/prefixed/response-fields.adoc[]

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -121,7 +121,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
}
@ReadOperation
public ApplicationConfigurationProperties configurationProperties(@Selector String prefix) {
public ApplicationConfigurationProperties configurationPropertiesWithPrefix(@Selector String prefix) {
return extract(this.context, (bean) -> bean.getAnnotation().prefix().startsWith(prefix));
}
@ -181,11 +181,9 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
private ContextConfigurationProperties describeBeans(ObjectMapper mapper, ApplicationContext context,
Predicate<ConfigurationPropertiesBean> beanFilterPredicate) {
Map<String, ConfigurationPropertiesBean> beans = ConfigurationPropertiesBean.getAll(context);
Map<String, ConfigurationPropertiesBeanDescriptor> descriptors = beans.values().stream()
.filter(beanFilterPredicate::test)
.collect(Collectors.toMap((bean) -> bean.getName(), (bean) -> describeBean(mapper, bean)));
.filter(beanFilterPredicate)
.collect(Collectors.toMap(ConfigurationPropertiesBean::getName, (bean) -> describeBean(mapper, bean)));
return new ContextConfigurationProperties(descriptors,
(context.getParent() != null) ? context.getParent().getId() : null);
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.boot.actuate.context.properties;
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties;
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
@ -40,10 +39,12 @@ public class ConfigurationPropertiesReportEndpointWebExtension {
}
@ReadOperation
public WebEndpointResponse<ApplicationConfigurationProperties> configurationProperties(@Selector String prefix) {
ApplicationConfigurationProperties configurationProperties = this.delegate.configurationProperties(prefix);
public WebEndpointResponse<ApplicationConfigurationProperties> configurationPropertiesWithPrefix(
@Selector String prefix) {
ApplicationConfigurationProperties configurationProperties = this.delegate
.configurationPropertiesWithPrefix(prefix);
boolean foundMatchingBeans = configurationProperties.getContexts().values().stream()
.map(ContextConfigurationProperties::getBeans).anyMatch((beans) -> !beans.isEmpty());
.anyMatch((context) -> !context.getBeans().isEmpty());
return (foundMatchingBeans) ? new WebEndpointResponse<>(configurationProperties, WebEndpointResponse.STATUS_OK)
: new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -42,10 +42,11 @@ class ConfigurationPropertiesReportEndpointFilteringTests {
contextRunner.run((context) -> {
ConfigurationPropertiesReportEndpoint endpoint = context
.getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("only.bar");
ApplicationConfigurationProperties applicationProperties = endpoint
.configurationPropertiesWithPrefix("only.bar");
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
assertThat(contextProperties.getBeans().values()).hasSize(1).first().hasFieldOrPropertyWithValue("prefix",
assertThat(contextProperties.getBeans().values()).singleElement().hasFieldOrPropertyWithValue("prefix",
"only.bar");
});
}
@ -57,7 +58,8 @@ class ConfigurationPropertiesReportEndpointFilteringTests {
contextRunner.run((context) -> {
ConfigurationPropertiesReportEndpoint endpoint = context
.getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo.");
ApplicationConfigurationProperties applicationProperties = endpoint
.configurationPropertiesWithPrefix("foo.");
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
assertThat(contextProperties.getBeans()).containsOnlyKeys("primaryFoo", "secondaryFoo");
@ -71,7 +73,8 @@ class ConfigurationPropertiesReportEndpointFilteringTests {
contextRunner.run((context) -> {
ConfigurationPropertiesReportEndpoint endpoint = context
.getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties("foo.third");
ApplicationConfigurationProperties applicationProperties = endpoint
.configurationPropertiesWithPrefix("foo.third");
assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
assertThat(contextProperties.getBeans()).isEmpty();

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

Loading…
Cancel
Save