Skip to content

Commit

Permalink
Add support for Spring HATEOAS hypermedia in Actuator endpoints
Browse files Browse the repository at this point in the history
If spring-hateoas is on the classpath and an MvcEndpoint returns a
@responsebody it will be extended and wrapped into a Resource with links.
All the existing endpoints that return sensible JSON data can be extended
this way (i.e. not /logfile). The HAL browser will also be added as an
endpoint if available on the classpath. Finally, asciidocs for the
Actuator endpoints are available as a separate jar file, which if
included in an app will also generate a new (HTTP) endpoint.

Fixes spring-projectsgh-1390
  • Loading branch information
dsyer committed Jul 2, 2015
1 parent 82fdb87 commit 74e9e07
Show file tree
Hide file tree
Showing 74 changed files with 3,106 additions and 154 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<module>spring-boot-devtools</module>
<module>spring-boot-docs</module>
<module>spring-boot-starters</module>
<module>spring-boot-actuator-docs</module>
<module>spring-boot-cli</module>
</modules>
</profile>
Expand Down
117 changes: 117 additions & 0 deletions spring-boot-actuator-docs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-boot-actuator-docs</artifactId>
<packaging>jar</packaging>

<name>spring-boot-actuator-docs</name>
<description>Docs project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-parent</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs</artifactId>
<version>1.0.0.M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-groovy-templates</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Documentation.java</include>
</includes>
<systemPropertyVariables>
<org.springframework.restdocs.outputDir>${project.build.directory}/generated-snippets</org.springframework.restdocs.outputDir>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<sourceDocumentName>index.adoc</sourceDocumentName>
<attributes>
<generated>${project.build.directory}/generated-snippets</generated>
<docs>${project.build.directory}/../src/main/asciidoc</docs>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/META-INF/resources/spring-boot-actuator/docs</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/generated-docs</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
26 changes: 26 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/autoconfig.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== /autoconfig

This endpoint is a report on the Spring Boot Autoconfiguration process
that happened when your application started up. It lists all the
`@Conditional` annotations that were evaluated as the context started
and in each case it gives an indication of if (and why) the condition
matched. A positive match results in a bean being included in the context,
and a negative result means the opposite (the beans's class may not even
be loaded).

The report is split into 2 parts, positive matches first, and then negative.
If the context is a hierarchy, there is also a separate report on the parent
context with the same format (and recursively up to the top of the hierarchy).

NOTE: the report is actually about `@Conditional` evaluation not autoconfiguration
per se, but most autoconfiguration features use `@Conditional` heavily, so there is
a lot of overlap.

Example curl request:
include::{generated}/autoconfig/curl-request.adoc[]

Example HTTP request:
include::{generated}/autoconfig/http-request.adoc[]

Example HTTP response:
include::{generated}/autoconfig/http-response.adoc[]
17 changes: 17 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/beans.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== /beans

This endpoint is a report on the Spring Boot `ApplicationContext`. It lists
the beans in the context and their dependencies, detailing the names and
concrete classes of each bean.

NOTE: some beans are pure configuration (any class that is annotated
`@Configuration`).

Example curl request:
include::{generated}/beans/curl-request.adoc[]

Example HTTP request:
include::{generated}/beans/http-request.adoc[]

Example HTTP response:
include::{generated}/beans/http-response.adoc[]
19 changes: 19 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/configprops.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== /configprops

This endpoint is a report on the Spring Boot `@ConfigurationProperties`
beans. Beans with this annotation are bound to the `Environment` on
startup, so they reflect the externalised configuration of the application.
Beans are listed by name.
A bean that is added using `@EnableConfigurationProperties` will have
a conventional name: `<prefix>.CONFIGURATION_PROPERTIES`, where
`<prefix>` is the environment key prefix specified in the
`@ConfigurationProperties` annotation.

Example curl request:
include::{generated}/configprops/curl-request.adoc[]

Example HTTP request:
include::{generated}/configprops/http-request.adoc[]

Example HTTP response:
include::{generated}/configprops/http-response.adoc[]
19 changes: 19 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/dump.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== /dump

This endpoint is a thread dump: the result is a list of threads each with
their name, monitor state and stack. It is the same information as you would
get from `kill -3` of a running Java process. Can be very useful for detecting
issues at runtime, especially sluggish behaviour caused by threads blocked
by slow or unavailable I/O (e.g. if a connection pool is exhausted).

NOTE: some `SecurityManager` implementations might prevent this endpoint
from working.

Example curl request:
include::{generated}/dump/curl-request.adoc[]

Example HTTP request:
include::{generated}/dump/http-request.adoc[]

Example HTTP response:
include::{generated}/dump/http-response.adoc[]
17 changes: 17 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/env.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== /env

This endpoint is a dump of the Spring `Environment`. It lists the active
profiles and all the `PropertySources` in the `Environment` (the ones that
are listed first take precedence when binding to `@ConfigurationProperties`
or `@Value`). Normally you will see the Java `System` properties and the
OS environment variables in their own `PropertySources` plus any `.properties`
or `.yml` files used to configure the application on start up.

Example curl request:
include::{generated}/env/curl-request.adoc[]

Example HTTP request:
include::{generated}/env/http-request.adoc[]

Example HTTP response:
include::{generated}/env/http-response.adoc[]
22 changes: 22 additions & 0 deletions spring-boot-actuator-docs/src/main/asciidoc/health.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== /health

This endpoint is an indication of the health of the application.
It has an overall status ("UP", "DOWN" etc.), which is the only thing
you see unless either you are authenticated or the endpoint is marked
as `sensitive=false` (`endpoints.health.sensitive=false`).

The HTTP code in the response reflects the status (e.g. "UP" = 200,
"OUT_OF_SERVICE"=503, "DOWN"=503). The mappings can be changed by
configuring `endpoints.health.mapping.<STATUS>=XXX`.

Example curl request:
include::{generated}/health/curl-request.adoc[]

Example HTTP request:
include::{generated}/health/http-request.adoc[]

Example HTTP response:
include::{generated}/health/http-response.adoc[]

Example HTTP response with `endpoints.health.sensitive=false`:
include::{generated}/health/unsensitive/http-response.adoc[]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 74e9e07

Please sign in to comment.