Skip to content

Commit 4b8d6ef

Browse files
onobcsnicoll
authored andcommitted
Add support for GET requests for /actuator/startup
See gh-24717
1 parent 8a6e79d commit 4b8d6ef

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/asciidoc/endpoints/startup.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ The resulting response is similar to the following:
1616

1717
include::{snippets}/startup/http-response.adoc[]
1818

19-
19+
NOTE: The above call resets the application startup steps buffer - subsequent calls to the endpoint will
20+
not include the returned steps. To retrieve a snapshot of the steps recorded so far without removing them
21+
from the startup buffer, make a `GET` request to `/actuator/startup`.
2022

2123
[[startup-retrieving-response-structure]]
2224
=== Response Structure

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/startup/StartupEndpoint.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.boot.SpringBootVersion;
2020
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
21+
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
2122
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
2223
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
2324
import org.springframework.boot.context.metrics.buffering.StartupTimeline;
@@ -28,6 +29,7 @@
2829
* application startup}.
2930
*
3031
* @author Brian Clozel
32+
* @author Chris Bono
3133
* @since 2.4.0
3234
*/
3335
@Endpoint(id = "startup")
@@ -50,6 +52,12 @@ public StartupResponse startup() {
5052
return new StartupResponse(startupTimeline);
5153
}
5254

55+
@ReadOperation
56+
public StartupResponse startupSnapshot() {
57+
StartupTimeline startupTimeline = this.applicationStartup.getBufferedTimeline();
58+
return new StartupResponse(startupTimeline);
59+
}
60+
5361
/**
5462
* A description of an application startup, primarily intended for serialization to
5563
* JSON.

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/startup/StartupEndpointTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Tests for {@link StartupEndpoint}.
3131
*
3232
* @author Brian Clozel
33+
* @author Chris Bono
3334
*/
3435
class StartupEndpointTests {
3536

@@ -60,6 +61,19 @@ void bufferIsDrained() {
6061
});
6162
}
6263

64+
@Test
65+
void bufferIsNotDrained() {
66+
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
67+
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
68+
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
69+
.withUserConfiguration(EndpointConfiguration.class);
70+
contextRunner.run((context) -> {
71+
StartupEndpoint.StartupResponse startup = context.getBean(StartupEndpoint.class).startupSnapshot();
72+
assertThat(startup.getTimeline().getEvents()).isNotEmpty();
73+
assertThat(applicationStartup.getBufferedTimeline().getEvents()).isNotEmpty();
74+
});
75+
}
76+
6377
@Configuration(proxyBeanMethods = false)
6478
static class EndpointConfiguration {
6579

0 commit comments

Comments
 (0)