Skip to content
Closed
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 @@ -16,7 +16,9 @@ The resulting response is similar to the following:

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


NOTE: The above call resets the application startup steps buffer - subsequent calls to the endpoint will
Copy link
Contributor Author

@onobc onobc Jan 9, 2021

Choose a reason for hiding this comment

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

This may need some wordsmith polishing - it feels like I'm bleeding impl details to the doc w/ talk of "buffer" etc..

not include the returned steps. To retrieve a snapshot of the steps recorded so far without removing them
from the startup buffer, make a `GET` request to `/actuator/startup`.

[[startup-retrieving-response-structure]]
=== Response Structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.context.metrics.buffering.StartupTimeline;
Expand All @@ -28,6 +29,7 @@
* application startup}.
*
* @author Brian Clozel
* @author Chris Bono
* @since 2.4.0
*/
@Endpoint(id = "startup")
Expand All @@ -50,6 +52,12 @@ public StartupResponse startup() {
return new StartupResponse(startupTimeline);
}

@ReadOperation
public StartupResponse startupSnapshot() {
StartupTimeline startupTimeline = this.applicationStartup.getBufferedTimeline();
return new StartupResponse(startupTimeline);
}

/**
* A description of an application startup, primarily intended for serialization to
* JSON.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Tests for {@link StartupEndpoint}.
*
* @author Brian Clozel
* @author Chris Bono
*/
class StartupEndpointTests {

Expand Down Expand Up @@ -60,6 +61,19 @@ void bufferIsDrained() {
});
}

@Test
void bufferIsNotDrained() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(256);
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
.withUserConfiguration(EndpointConfiguration.class);
contextRunner.run((context) -> {
StartupEndpoint.StartupResponse startup = context.getBean(StartupEndpoint.class).startupSnapshot();
assertThat(startup.getTimeline().getEvents()).isNotEmpty();
assertThat(applicationStartup.getBufferedTimeline().getEvents()).isNotEmpty();
});
}

@Configuration(proxyBeanMethods = false)
static class EndpointConfiguration {

Expand Down