Skip to content

Commit

Permalink
fix(#2068): polling health status does not include details (#2070)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Jul 19, 2022
1 parent c7c20f0 commit 10d5c14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,20 @@ public static Comparator<String> severity() {

@SuppressWarnings("unchecked")
public static StatusInfo from(Map<String, ?> body) {
return StatusInfo.valueOf((String) (body).get("status"), (Map<String, ?>) body.get("details"));
Map<String, ?> details = Collections.emptyMap();

/*
* Key "details" is present when accessing Spring Boot Actuator Health
* using Accept-Header {@link org.springframework.boot.actuate.endpoint.ApiVersion#V2}.
*/
if (body.containsKey("details")) {
details = (Map<String, ?>) body.get("details");
}
else if (body.containsKey("components")) {
details = (Map<String, ?>) body.get("components");
}

return StatusInfo.valueOf((String) body.get("status"), details);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public void from_map_should_return_same_result() {
assertThat(StatusInfo.from(map)).isEqualTo(StatusInfo.ofUp(singletonMap("foo", "bar")));
}

@Test
public void when_first_level_key_is_components() {
Map<String, Object> map = new HashMap<>();
map.put("status", "UP");
map.put("components", singletonMap("foo", "bar"));

assertThat(StatusInfo.from(map)).isEqualTo(StatusInfo.ofUp(singletonMap("foo", "bar")));
}

@Test
public void should_sort_by_status_order() {
List<String> unordered = asList(STATUS_OUT_OF_SERVICE, STATUS_UNKNOWN, STATUS_OFFLINE, STATUS_DOWN, STATUS_UP,
Expand Down

0 comments on commit 10d5c14

Please sign in to comment.