Skip to content

Commit c99521f

Browse files
committed
Document the os info contribution
Closes gh-45565
1 parent 1d923cc commit c99521f

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/docs/antora/modules/api/pages/rest/actuator/info.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ include::partial$rest/actuator/info/response-fields-beneath-git.adoc[]
4747

4848
NOTE: This is the "simple" output.
4949
The contributor can also be configured to output all available data.
50+
51+
52+
[[info.retrieving.response-structure.os]]
53+
==== OS Response Structure
54+
55+
The following table describes the structure of the `os` section of the response:
56+
57+
[cols="2,1,3"]
58+
include::partial$rest/actuator/info/response-fields-beneath-os.adoc[]

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointDocumentationTests.java

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
import org.springframework.boot.actuate.info.GitInfoContributor;
2828
import org.springframework.boot.actuate.info.InfoContributor;
2929
import org.springframework.boot.actuate.info.InfoEndpoint;
30+
import org.springframework.boot.actuate.info.OsInfoContributor;
3031
import org.springframework.boot.info.BuildProperties;
3132
import org.springframework.boot.info.GitProperties;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
3435
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
36+
import org.springframework.restdocs.payload.FieldDescriptor;
3537
import org.springframework.restdocs.payload.JsonFieldType;
38+
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
3639

3740
import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath;
3841
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
@@ -51,23 +54,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
5154
void info() throws Exception {
5255
this.mockMvc.perform(get("/actuator/info"))
5356
.andExpect(status().isOk())
54-
.andDo(MockMvcRestDocumentation.document("info",
55-
responseFields(beneathPath("git"),
56-
fieldWithPath("branch").description("Name of the Git branch, if any."),
57-
fieldWithPath("commit").description("Details of the Git commit, if any."),
58-
fieldWithPath("commit.time").description("Timestamp of the commit, if any.")
59-
.type(JsonFieldType.VARIES),
60-
fieldWithPath("commit.id").description("ID of the commit, if any.")),
61-
responseFields(beneathPath("build"),
62-
fieldWithPath("artifact").description("Artifact ID of the application, if any.").optional(),
63-
fieldWithPath("group").description("Group ID of the application, if any.").optional(),
64-
fieldWithPath("name").description("Name of the application, if any.")
65-
.type(JsonFieldType.STRING)
66-
.optional(),
67-
fieldWithPath("version").description("Version of the application, if any.").optional(),
68-
fieldWithPath("time").description("Timestamp of when the application was built, if any.")
69-
.type(JsonFieldType.VARIES)
70-
.optional())));
57+
.andDo(MockMvcRestDocumentation.document("info", gitInfo(), buildInfo(), osInfo()));
58+
}
59+
60+
private ResponseFieldsSnippet gitInfo() {
61+
return responseFields(beneathPath("git"),
62+
fieldWithPath("branch").description("Name of the Git branch, if any."),
63+
fieldWithPath("commit").description("Details of the Git commit, if any."),
64+
fieldWithPath("commit.time").description("Timestamp of the commit, if any.").type(JsonFieldType.VARIES),
65+
fieldWithPath("commit.id").description("ID of the commit, if any."));
66+
}
67+
68+
private ResponseFieldsSnippet buildInfo() {
69+
return responseFields(beneathPath("build"),
70+
fieldWithPath("artifact").description("Artifact ID of the application, if any.").optional(),
71+
fieldWithPath("group").description("Group ID of the application, if any.").optional(),
72+
fieldWithPath("name").description("Name of the application, if any.")
73+
.type(JsonFieldType.STRING)
74+
.optional(),
75+
fieldWithPath("version").description("Version of the application, if any.").optional(),
76+
fieldWithPath("time").description("Timestamp of when the application was built, if any.")
77+
.type(JsonFieldType.VARIES)
78+
.optional());
79+
}
80+
81+
private ResponseFieldsSnippet osInfo() {
82+
return responseFields(beneathPath("os"), osInfoField("name", "Name"), osInfoField("version", "Version"),
83+
osInfoField("arch", "Architecture"));
84+
}
85+
86+
private FieldDescriptor osInfoField(String field, String desc) {
87+
return fieldWithPath(field)
88+
.description("Operating System " + desc + " (as obtained from the 'os." + field + "' system property).")
89+
.type(JsonFieldType.STRING)
90+
.optional();
7191
}
7292

7393
@Configuration(proxyBeanMethods = false)
@@ -99,6 +119,11 @@ BuildInfoContributor buildInfoContributor() {
99119
return new BuildInfoContributor(buildProperties);
100120
}
101121

122+
@Bean
123+
OsInfoContributor osInfoContributor() {
124+
return new OsInfoContributor();
125+
}
126+
102127
}
103128

104129
}

0 commit comments

Comments
 (0)