Maintain same structure in /health output
JSON output of /health now has the same structure for 1 or more HealthIndicators. This makes it easier to consume the response from scripts or apps fixes #1291
This commit is contained in:
parent
6b083d7e0b
commit
063f67da5f
|
|
@ -27,7 +27,7 @@ import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Endpoint} to expose application health.
|
* {@link Endpoint} to expose application health.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
|
|
@ -46,17 +46,12 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
|
||||||
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
|
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
|
||||||
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
||||||
|
|
||||||
if (healthIndicators.size() == 1) {
|
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
|
||||||
this.healthIndicator = healthIndicators.values().iterator().next();
|
healthAggregator);
|
||||||
}
|
for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) {
|
||||||
else {
|
healthIndicator.addHealthIndicator(getKey(h.getKey()), h.getValue());
|
||||||
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
|
|
||||||
healthAggregator);
|
|
||||||
for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) {
|
|
||||||
healthIndicator.addHealthIndicator(getKey(h.getKey()), h.getValue());
|
|
||||||
}
|
|
||||||
this.healthIndicator = healthIndicator;
|
|
||||||
}
|
}
|
||||||
|
this.healthIndicator = healthIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EndpointAutoConfiguration}.
|
* Tests for {@link EndpointAutoConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
|
|
@ -89,7 +89,7 @@ public class EndpointAutoConfigurationTests {
|
||||||
assertNotNull(bean);
|
assertNotNull(bean);
|
||||||
Health result = bean.invoke();
|
Health result = bean.invoke();
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertTrue("Wrong result: " + result, result.getDetails().containsKey("database"));
|
assertTrue("Wrong result: " + result, result.getDetails().containsKey("db"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue