[bs-107] Finish off varz->metrics

[Fixes #49496887] [bs-107] Remove trailing "z" from management endpoint URLs
This commit is contained in:
Dave Syer 2013-05-23 19:26:25 +01:00
parent b7c0e3279e
commit e649ef44cc
11 changed files with 65 additions and 28 deletions

View File

@ -85,13 +85,13 @@ You should be able to run it already:
Then in another terminal Then in another terminal
$ curl localhost:8080/healthz $ curl localhost:8080/health
ok ok
$ curl localhost:8080/varz $ curl localhost:8080/metrics
{"counter.status.200.healthz":1.0,"gauge.response.healthz":10.0,"mem":120768.0,"mem.free":105012.0,"processors":4.0} {"counter.status.200.health":1.0,"gauge.response.health":10.0,"mem":120768.0,"mem.free":105012.0,"processors":4.0}
`/healthz` is the default location for the health endpoint - it tells `/health` is the default location for the health endpoint - it tells
you if the application is running and healthy. `/varz` is the default you if the application is running and healthy. `/metrics` is the default
location for the metrics endpoint - it gives you basic counts and location for the metrics endpoint - it gives you basic counts and
response timing data by default but there are plenty of ways to response timing data by default but there are plenty of ways to
customize it. You can also try `/trace` and `/dump` to get some customize it. You can also try `/trace` and `/dump` to get some
@ -196,7 +196,7 @@ will find the home page on port 9000 instead of 8080:
and the management endpoints on port 9001 instead of 8080: and the management endpoints on port 9001 instead of 8080:
$ curl localhost:9001/healthz $ curl localhost:9001/health
ok ok
To externalize business configuration you can simply add a default To externalize business configuration you can simply add a default

View File

@ -43,7 +43,7 @@ public class HealthConfiguration {
private HealthIndicator<? extends Object> healthIndicator = new VanillaHealthIndicator(); private HealthIndicator<? extends Object> healthIndicator = new VanillaHealthIndicator();
@Bean @Bean
public HealthEndpoint<? extends Object> healthzEndpoint() { public HealthEndpoint<? extends Object> healthEndpoint() {
return new HealthEndpoint<Object>(this.healthIndicator); return new HealthEndpoint<Object>(this.healthIndicator);
} }

View File

@ -19,9 +19,9 @@ package org.springframework.bootstrap.actuate.autoconfigure;
import javax.servlet.Servlet; import javax.servlet.Servlet;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint;
import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics; import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics;
import org.springframework.bootstrap.actuate.endpoint.metrics.VanillaPublicMetrics; import org.springframework.bootstrap.actuate.endpoint.metrics.VanillaPublicMetrics;
import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint;
import org.springframework.bootstrap.actuate.metrics.MetricRepository; import org.springframework.bootstrap.actuate.metrics.MetricRepository;
import org.springframework.bootstrap.context.annotation.ConditionalOnClass; import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean; import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for /varz endpoint. * {@link EnableAutoConfiguration Auto-configuration} for /metrics endpoint.
* *
* @author Dave Syer * @author Dave Syer
*/ */

View File

@ -57,8 +57,8 @@ public class SecurityConfiguration {
private static class BoostrapWebSecurityConfigurerAdapter extends private static class BoostrapWebSecurityConfigurerAdapter extends
WebSecurityConfigurerAdapter { WebSecurityConfigurerAdapter {
@Value("${endpoints.healthz.path:/healthz}") @Value("${endpoints.health.path:/health}")
private String healthzPath = "/healthz"; private String healthPath = "/health";
@Value("${endpoints.info.path:/info}") @Value("${endpoints.info.path:/info}")
private String infoPath = "/info"; private String infoPath = "/info";
@ -80,7 +80,7 @@ public class SecurityConfiguration {
@Override @Override
public void configure(WebSecurityConfiguration builder) throws Exception { public void configure(WebSecurityConfiguration builder) throws Exception {
builder.ignoring().antMatchers(this.healthzPath, this.infoPath); builder.ignoring().antMatchers(this.healthPath, this.infoPath);
} }
@Override @Override

View File

@ -36,9 +36,9 @@ public class HealthEndpoint<T> {
this.indicator = indicator; this.indicator = indicator;
} }
@RequestMapping("${endpoints.healthz.path:/healthz}") @RequestMapping("${endpoints.health.path:/health}")
@ResponseBody @ResponseBody
public T healthz() { public T health() {
return this.indicator.health(); return this.indicator.health();
} }

View File

@ -39,9 +39,9 @@ public class MetricsEndpoint {
this.metrics = metrics; this.metrics = metrics;
} }
@RequestMapping("${endpoints.varz.path:/varz}") @RequestMapping("${endpoints.metrics.path:/metrics}")
@ResponseBody @ResponseBody
public Map<String, Object> varz() { public Map<String, Object> metrics() {
Map<String, Object> result = new LinkedHashMap<String, Object>(); Map<String, Object> result = new LinkedHashMap<String, Object>();
for (Metric metric : this.metrics.metrics()) { for (Metric metric : this.metrics.metrics()) {
result.put(metric.getName(), metric.getValue()); result.put(metric.getName(), metric.getValue());

View File

@ -18,10 +18,16 @@ package org.springframework.bootstrap.actuate.autoconfigure;
import org.junit.Test; import org.junit.Test;
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
/** /**
@ -41,4 +47,35 @@ public class SecurityConfigurationTests {
assertNotNull(this.context.getBean(AuthenticationManager.class)); assertNotNull(this.context.getBean(AuthenticationManager.class));
} }
@Test
public void testOverrideAuthenticationManager() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class, SecurityConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertEquals(this.context.getBean(TestConfiguration.class).authenticationManager,
this.context.getBean(AuthenticationManager.class));
}
@Configuration
protected static class TestConfiguration {
private AuthenticationManager authenticationManager;
@Bean
public AuthenticationManager myAuthenticationManager() {
this.authenticationManager = new AuthenticationManager() {
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
return new TestingAuthenticationToken("foo", "bar");
}
};
return this.authenticationManager;
}
}
} }

View File

@ -77,11 +77,11 @@ public class ManagementAddressServiceBootstrapApplicationTests {
} }
@Test @Test
public void testVarz() throws Exception { public void testMetrics() throws Exception {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate().getForEntity( ResponseEntity<Map> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/varz", Map.class); "http://localhost:" + managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
@ -89,9 +89,9 @@ public class ManagementAddressServiceBootstrapApplicationTests {
} }
@Test @Test
public void testHealthz() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity( ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/healthz", String.class); "http://localhost:" + managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }

View File

@ -65,9 +65,9 @@ public class ManagementServiceBootstrapApplicationTests {
} }
@Test @Test
public void testHealthz() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity( ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:" + managementPort + "/healthz", String.class); "http://localhost:" + managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }

View File

@ -75,11 +75,11 @@ public class NoManagementServiceBootstrapApplicationTests {
} }
@Test(expected = ResourceAccessException.class) @Test(expected = ResourceAccessException.class)
public void testVarzNotAvailable() throws Exception { public void testMetricsNotAvailable() throws Exception {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity( ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity(
"http://localhost:" + managementPort + "/varz", Map.class); "http://localhost:" + managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
} }

View File

@ -84,11 +84,11 @@ public class ServiceBootstrapApplicationTests {
} }
@Test @Test
public void testVarz() throws Exception { public void testMetrics() throws Exception {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity( ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity(
"http://localhost:8080/varz", Map.class); "http://localhost:8080/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
@ -96,9 +96,9 @@ public class ServiceBootstrapApplicationTests {
} }
@Test @Test
public void testHealthz() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = getRestTemplate().getForEntity( ResponseEntity<String> entity = getRestTemplate().getForEntity(
"http://localhost:8080/healthz", String.class); "http://localhost:8080/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("ok", entity.getBody()); assertEquals("ok", entity.getBody());
} }