Skip to content

Commit bcab23e

Browse files
committed
Polish "Separate endpoint concerns"
* Fix the endpoint prefix for generated metadata. * Polish and improve configuration key descriptions. Closes gh-10176
1 parent 9411d17 commit bcab23e

File tree

7 files changed

+139
-71
lines changed

7 files changed

+139
-71
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointProperties.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,12 @@
3434
public class JmxEndpointProperties {
3535

3636
/**
37-
* Whether JMX endpoints are enabled.
38-
*/
39-
private boolean enabled;
40-
41-
/**
42-
* The IDs of endpoints that should be exposed or '*' for all.
37+
* Endpoint IDs that should be exposed or '*' for all.
4338
*/
4439
private Set<String> expose = new LinkedHashSet<>();
4540

4641
/**
47-
* The IDs of endpoints that should be excluded.
42+
* Endpoint IDs that should be excluded.
4843
*/
4944
private Set<String> exclude = new LinkedHashSet<>();
5045

@@ -71,14 +66,6 @@ public JmxEndpointProperties(Environment environment) {
7166
}
7267
}
7368

74-
public boolean isEnabled() {
75-
return this.enabled;
76-
}
77-
78-
public void setEnabled(boolean enabled) {
79-
this.enabled = enabled;
80-
}
81-
8269
public Set<String> getExpose() {
8370
return this.expose;
8471
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,25 @@
3434
public class WebEndpointProperties {
3535

3636
/**
37-
* Whether web endpoints are enabled.
38-
*/
39-
private boolean enabled;
40-
41-
/**
42-
* The base-path for the web endpoints. Relative to `server.context-path` or
43-
* `management.server.context-path`, if `management.server.port` is different.
37+
* Base path for Web endpoints. Relative to server.context-path or
38+
* management.server.context-path if management.server.port is configured.
4439
*/
4540
private String basePath = "/application";
4641

4742
/**
48-
* The IDs of endpoints that should be exposed or '*' for all.
43+
* Endpoint IDs that should be exposed or '*' for all.
4944
*/
5045
private Set<String> expose = new LinkedHashSet<>();
5146

5247
/**
53-
* The IDs of endpoints that should be excluded.
48+
* Endpoint IDs that should be excluded.
5449
*/
5550
private Set<String> exclude = new LinkedHashSet<>();
5651

5752
/**
5853
* Mapping between endpoint IDs and the path that should expose them.
5954
*/
60-
private Map<String, String> pathMapping = new LinkedHashMap<>();
61-
62-
public boolean isEnabled() {
63-
return this.enabled;
64-
}
65-
66-
public void setEnabled(boolean enabled) {
67-
this.enabled = enabled;
68-
}
55+
private final Map<String, String> pathMapping = new LinkedHashMap<>();
6956

7057
public String getBasePath() {
7158
return this.basePath;
@@ -95,8 +82,4 @@ public Map<String, String> getPathMapping() {
9582
return this.pathMapping;
9683
}
9784

98-
public void setPathMapping(Map<String, String> pathMapping) {
99-
this.pathMapping = pathMapping;
100-
}
101-
10285
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"vcap_services"
1111
]
1212
},
13-
{
14-
"name": "management.endpoints.enabled-by-default",
15-
"type": "java.lang.Boolean",
16-
"description": "Enable or disable all endpoints by default."
17-
},
1813
{
1914
"name": "management.endpoint.env.keys-to-sanitize",
2015
"defaultValue": [
@@ -36,6 +31,34 @@
3631
"level": "error"
3732
}
3833
},
34+
{
35+
"name": "management.endpoints.enabled-by-default",
36+
"type": "java.lang.Boolean",
37+
"description": "Enable or disable all endpoints by default."
38+
},
39+
{
40+
"name": "management.endpoints.jmx.enabled",
41+
"type": "java.lang.Boolean",
42+
"description": "Whether JMX endpoints are enabled.",
43+
"defaultValue": true
44+
},
45+
{
46+
"name": "management.endpoints.jmx.expose",
47+
"defaultValue": "*"
48+
},
49+
{
50+
"name": "management.endpoints.web.enabled",
51+
"type": "java.lang.Boolean",
52+
"description": "Whether web endpoints are enabled.",
53+
"defaultValue": true
54+
},
55+
{
56+
"name": "management.endpoints.web.expose",
57+
"defaultValue": [
58+
"info",
59+
"status"
60+
]
61+
},
3962
{
4063
"name": "info",
4164
"type": "java.util.Map<java.lang.String,java.lang.Object>",
@@ -1188,6 +1211,79 @@
11881211
}
11891212
}
11901213
],"hints": [
1214+
{
1215+
"name": "management.endpoints.web.path-mapping.keys",
1216+
"values": [
1217+
{
1218+
"value": "auditevents"
1219+
},
1220+
{
1221+
"value": "beans"
1222+
},
1223+
{
1224+
"value": "conditions"
1225+
},
1226+
{
1227+
"value": "configprops"
1228+
},
1229+
{
1230+
"value": "env"
1231+
},
1232+
{
1233+
"value": "flyway"
1234+
},
1235+
{
1236+
"value": "health"
1237+
},
1238+
{
1239+
"value": "heapdump"
1240+
},
1241+
{
1242+
"value": "info"
1243+
},
1244+
{
1245+
"value": "liquibase"
1246+
},
1247+
{
1248+
"value": "logfile"
1249+
},
1250+
{
1251+
"value": "loggers"
1252+
},
1253+
{
1254+
"value": "mappings"
1255+
},
1256+
{
1257+
"value": "metrics"
1258+
},
1259+
{
1260+
"value": "prometheus"
1261+
},
1262+
{
1263+
"value": "scheduledtasks"
1264+
},
1265+
{
1266+
"value": "sessions"
1267+
},
1268+
{
1269+
"value": "shutdown"
1270+
},
1271+
{
1272+
"value": "status"
1273+
},
1274+
{
1275+
"value": "threaddump"
1276+
},
1277+
{
1278+
"value": "trace"
1279+
}
1280+
],
1281+
"providers": [
1282+
{
1283+
"name": "any"
1284+
}
1285+
]
1286+
},
11911287
{
11921288
"name": "management.endpoints.web.cors.allowed-headers",
11931289
"values": [

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,20 +1096,23 @@ content into your application; rather pick only the properties that you need.
10961096
management.cloudfoundry.enabled=true # Enable extended Cloud Foundry actuator endpoints.
10971097
management.cloudfoundry.skip-ssl-validation=false # Skip SSL verification for Cloud Foundry actuator endpoint security calls.
10981098
1099-
# ENDPOINTS JMX CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/jmx/JmxEndpointExporterProperties.{sc-ext}[JmxEndpointExporterProperties])
1100-
management.endpoints.jmx.enabled= # Whether JMX endpoints are enabled
1101-
management.endpoints.jmx.expose= The IDs of endpoints to expose or '*' for all (default is 'info', 'status')
1102-
management.endpoints.jmx.exclude= The IDs of endpoints to exclude
1099+
# ENDPOINTS GENERAL CONFIGURATION
1100+
management.endpoints.enabled-by-default= # Enable or disable all endpoints by default.
1101+
1102+
# ENDPOINTS JMX CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/jmx/JmxEndpointProperties.{sc-ext}[JmxEndpointProperties])
1103+
management.endpoints.jmx.enabled=true # Whether JMX endpoints are enabled.
1104+
management.endpoints.jmx.expose=* # Endpoint IDs that should be exposed or '*' for all.
1105+
management.endpoints.jmx.exclude= # Endpoint IDs that should be excluded.
11031106
management.endpoints.jmx.domain=org.springframework.boot # Endpoints JMX domain name. Fallback to 'spring.jmx.default-domain' if set.
11041107
management.endpoints.jmx.static-names=false # Additional static properties to append to all ObjectNames of MBeans representing Endpoints.
11051108
management.endpoints.jmx.unique-names=false # Ensure that ObjectNames are modified in case of conflict.
11061109
11071110
# ENDPOINTS WEB CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/WebEndpointProperties.{sc-ext}[WebEndpointProperties])
1108-
management.endpoints.web.enabled= # Whether web endpoints are enabled
1109-
management.endpoints.web.expose= The IDs of endpoints to expose or '*' for all (default is '*')
1110-
management.endpoints.web.exclude= The IDs of endpoints to exclude
1111+
management.endpoints.web.enabled=true # Whether web endpoints are enabled
1112+
management.endpoints.web.expose=info,status # Endpoint IDs that should be exposed or '*' for all.
1113+
management.endpoints.web.exclude= # Endpoint IDs that should be excluded.
11111114
management.endpoints.web.base-path=/application # Base path for Web endpoints. Relative to server.context-path or management.server.context-path if management.server.port is configured.
1112-
management.endpoints.web.path=mapping= Map of endpoint IDs to the path that should expose them
1115+
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them.
11131116
11141117
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/servlet/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties])
11151118
management.endpoints.web.cors.allow-credentials= # Set whether credentials are supported. When not set, credentials are not supported.
@@ -1146,8 +1149,8 @@ content into your application; rather pick only the properties that you need.
11461149
management.endpoint.flyway.enabled= # Enable the flyway endpoint.
11471150
11481151
# HEALTH ENDPOINT ({sc-spring-boot-actuator}/health/HealthEndpoint.{sc-ext}[HealthEndpoint])
1149-
endpoints.health.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
1150-
endpoints.health.enabled= # Enable the health endpoint.
1152+
management.endpoint.health.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
1153+
management.endpoint.health.enabled= # Enable the health endpoint.
11511154
11521155
# HEAP DUMP ENDPOINT ({sc-spring-boot-actuator}/management/HeapDumpWebEndpoint.{sc-ext}[HeapDumpWebEndpoint])
11531156
management.endpoint.heapdump.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
@@ -1183,11 +1186,8 @@ content into your application; rather pick only the properties that you need.
11831186
management.endpoint.prometheus.enabled= # Enable the metrics endpoint.
11841187
11851188
# SCHEDULED TASKS ENDPOINT ({sc-spring-boot-actuator}/scheduling/ScheduledTasksEndpoint.{sc-ext}[ScheduledTasksEndpoint])
1186-
endpoints.scheduledtasks.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
1187-
endpoints.scheduledtasks.enabled= # Enable the scheduled tasks endpoint.
1188-
endpoints.scheduledtasks.jmx.enabled= # Expose the scheduled tasks endpoint as a JMX MBean.
1189-
endpoints.scheduledtasks.web.enabled= # Expose the scheduled tasks endpoint as a Web endpoint.
1190-
endpoints.scheduledtasks.web.path=sessions # Path of the scheduled tasks endpoint.
1189+
management.endpoint.scheduledtasks.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.
1190+
management.endpoint.scheduledtasks.enabled= # Enable the scheduled tasks endpoint.
11911191
11921192
# SESSIONS ENDPOINT ({sc-spring-boot-actuator}/session/SessionsEndpoint.{sc-ext}[SessionsEndpoint])
11931193
management.endpoint.sessions.cache.time-to-live=0 # Maximum time in milliseconds that a response can be cached.

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ private void processEndpoint(AnnotationMirror annotation, TypeElement element) {
429429
}
430430

431431
private String endpointKey(String suffix) {
432-
return "endpoints." + suffix;
432+
return "management.endpoint." + suffix;
433433
}
434434

435435
private boolean isNested(Element returnType, VariableElement field,

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public void lombokInnerClassWithGetterProperties() throws IOException {
533533
public void simpleEndpoint() throws IOException {
534534
ConfigurationMetadata metadata = compile(SimpleEndpoint.class);
535535
assertThat(metadata).has(
536-
Metadata.withGroup("endpoints.simple").fromSource(SimpleEndpoint.class));
536+
Metadata.withGroup("management.endpoint.simple").fromSource(SimpleEndpoint.class));
537537
assertThat(metadata).has(enabledFlag("simple", true));
538538
assertThat(metadata).has(cacheTtl("simple"));
539539
assertThat(metadata.getItems()).hasSize(3);
@@ -542,7 +542,7 @@ public void simpleEndpoint() throws IOException {
542542
@Test
543543
public void disableEndpoint() throws IOException {
544544
ConfigurationMetadata metadata = compile(DisabledEndpoint.class);
545-
assertThat(metadata).has(Metadata.withGroup("endpoints.disabled")
545+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.disabled")
546546
.fromSource(DisabledEndpoint.class));
547547
assertThat(metadata).has(enabledFlag("disabled", false));
548548
assertThat(metadata).has(cacheTtl("disabled"));
@@ -552,7 +552,7 @@ public void disableEndpoint() throws IOException {
552552
@Test
553553
public void enabledEndpoint() throws IOException {
554554
ConfigurationMetadata metadata = compile(EnabledEndpoint.class);
555-
assertThat(metadata).has(Metadata.withGroup("endpoints.enabled")
555+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.enabled")
556556
.fromSource(EnabledEndpoint.class));
557557
assertThat(metadata).has(enabledFlag("enabled", true));
558558
assertThat(metadata).has(cacheTtl("enabled"));
@@ -562,9 +562,10 @@ public void enabledEndpoint() throws IOException {
562562
@Test
563563
public void customPropertiesEndpoint() throws IOException {
564564
ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class);
565-
assertThat(metadata).has(Metadata.withGroup("endpoints.customprops")
565+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.customprops")
566566
.fromSource(CustomPropertiesEndpoint.class));
567-
assertThat(metadata).has(Metadata.withProperty("endpoints.customprops.name")
567+
assertThat(metadata).has(Metadata
568+
.withProperty("management.endpoint.customprops.name")
568569
.ofType(String.class).withDefaultValue("test"));
569570
assertThat(metadata).has(enabledFlag("customprops", true));
570571
assertThat(metadata).has(cacheTtl("customprops"));
@@ -574,7 +575,7 @@ public void customPropertiesEndpoint() throws IOException {
574575
@Test
575576
public void specificEndpoint() throws IOException {
576577
ConfigurationMetadata metadata = compile(SpecificEndpoint.class);
577-
assertThat(metadata).has(Metadata.withGroup("endpoints.specific")
578+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific")
578579
.fromSource(SpecificEndpoint.class));
579580
assertThat(metadata).has(enabledFlag("specific", true));
580581
assertThat(metadata).has(cacheTtl("specific"));
@@ -586,15 +587,15 @@ public void incrementalEndpointBuildChangeGeneralEnabledFlag() throws Exception
586587
TestProject project = new TestProject(this.temporaryFolder,
587588
IncrementalEndpoint.class);
588589
ConfigurationMetadata metadata = project.fullBuild();
589-
assertThat(metadata).has(Metadata.withGroup("endpoints.incremental")
590+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental")
590591
.fromSource(IncrementalEndpoint.class));
591592
assertThat(metadata).has(enabledFlag("incremental", true));
592593
assertThat(metadata).has(cacheTtl("incremental"));
593594
assertThat(metadata.getItems()).hasSize(3);
594595
project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"",
595596
"id = \"incremental\", enableByDefault = false");
596597
metadata = project.incrementalBuild(IncrementalEndpoint.class);
597-
assertThat(metadata).has(Metadata.withGroup("endpoints.incremental")
598+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental")
598599
.fromSource(IncrementalEndpoint.class));
599600
assertThat(metadata).has(enabledFlag("incremental", false));
600601
assertThat(metadata).has(cacheTtl("incremental"));
@@ -606,15 +607,15 @@ public void incrementalEndpointBuildEnableSpecificEndpoint() throws Exception {
606607
TestProject project = new TestProject(this.temporaryFolder,
607608
SpecificEndpoint.class);
608609
ConfigurationMetadata metadata = project.fullBuild();
609-
assertThat(metadata).has(Metadata.withGroup("endpoints.specific")
610+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific")
610611
.fromSource(SpecificEndpoint.class));
611612
assertThat(metadata).has(enabledFlag("specific", true));
612613
assertThat(metadata).has(cacheTtl("specific"));
613614
assertThat(metadata.getItems()).hasSize(3);
614615
project.replaceText(SpecificEndpoint.class, "enableByDefault = true",
615616
"enableByDefault = false");
616617
metadata = project.incrementalBuild(SpecificEndpoint.class);
617-
assertThat(metadata).has(Metadata.withGroup("endpoints.specific")
618+
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific")
618619
.fromSource(SpecificEndpoint.class));
619620
assertThat(metadata).has(enabledFlag("specific", false));
620621
assertThat(metadata).has(cacheTtl("specific"));
@@ -623,13 +624,14 @@ public void incrementalEndpointBuildEnableSpecificEndpoint() throws Exception {
623624

624625
private Metadata.MetadataItemCondition enabledFlag(String endpointId,
625626
Boolean defaultValue) {
626-
return Metadata.withEnabledFlag("endpoints." + endpointId + ".enabled")
627+
return Metadata.withEnabledFlag("management.endpoint." + endpointId + ".enabled")
627628
.withDefaultValue(defaultValue)
628629
.withDescription(String.format("Enable the %s endpoint.", endpointId));
629630
}
630631

631632
private Metadata.MetadataItemCondition cacheTtl(String endpointId) {
632-
return Metadata.withProperty("endpoints." + endpointId + ".cache.time-to-live")
633+
return Metadata
634+
.withProperty("management.endpoint." + endpointId + ".cache.time-to-live")
633635
.ofType(Long.class).withDefaultValue(0).withDescription(
634636
"Maximum time in milliseconds that a response can be cached.");
635637
}

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/CustomPropertiesEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @author Stephane Nicoll
2626
*/
2727
@Endpoint(id = "customprops")
28-
@ConfigurationProperties("endpoints.customprops")
28+
@ConfigurationProperties("management.endpoint.customprops")
2929
public class CustomPropertiesEndpoint {
3030

3131
private String name = "test";

0 commit comments

Comments
 (0)