mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
[bs-107] Finish off varz->metrics
[Fixes #49496887] [bs-107] Remove trailing "z" from management endpoint URLs
This commit is contained in:
parent
b7c0e3279e
commit
e649ef44cc
@ -85,13 +85,13 @@ You should be able to run it already:
|
||||
|
||||
Then in another terminal
|
||||
|
||||
$ curl localhost:8080/healthz
|
||||
$ curl localhost:8080/health
|
||||
ok
|
||||
$ curl localhost:8080/varz
|
||||
{"counter.status.200.healthz":1.0,"gauge.response.healthz":10.0,"mem":120768.0,"mem.free":105012.0,"processors":4.0}
|
||||
$ curl localhost:8080/metrics
|
||||
{"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
|
||||
you if the application is running and healthy. `/varz` is the default
|
||||
`/health` is the default location for the health endpoint - it tells
|
||||
you if the application is running and healthy. `/metrics` is the default
|
||||
location for the metrics endpoint - it gives you basic counts and
|
||||
response timing data by default but there are plenty of ways to
|
||||
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:
|
||||
|
||||
$ curl localhost:9001/healthz
|
||||
$ curl localhost:9001/health
|
||||
ok
|
||||
|
||||
To externalize business configuration you can simply add a default
|
||||
|
@ -43,7 +43,7 @@ public class HealthConfiguration {
|
||||
private HealthIndicator<? extends Object> healthIndicator = new VanillaHealthIndicator();
|
||||
|
||||
@Bean
|
||||
public HealthEndpoint<? extends Object> healthzEndpoint() {
|
||||
public HealthEndpoint<? extends Object> healthEndpoint() {
|
||||
return new HealthEndpoint<Object>(this.healthIndicator);
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ package org.springframework.bootstrap.actuate.autoconfigure;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
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.VanillaPublicMetrics;
|
||||
import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint;
|
||||
import org.springframework.bootstrap.actuate.metrics.MetricRepository;
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
||||
@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for /varz endpoint.
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for /metrics endpoint.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
|
@ -57,8 +57,8 @@ public class SecurityConfiguration {
|
||||
private static class BoostrapWebSecurityConfigurerAdapter extends
|
||||
WebSecurityConfigurerAdapter {
|
||||
|
||||
@Value("${endpoints.healthz.path:/healthz}")
|
||||
private String healthzPath = "/healthz";
|
||||
@Value("${endpoints.health.path:/health}")
|
||||
private String healthPath = "/health";
|
||||
|
||||
@Value("${endpoints.info.path:/info}")
|
||||
private String infoPath = "/info";
|
||||
@ -80,7 +80,7 @@ public class SecurityConfiguration {
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurityConfiguration builder) throws Exception {
|
||||
builder.ignoring().antMatchers(this.healthzPath, this.infoPath);
|
||||
builder.ignoring().antMatchers(this.healthPath, this.infoPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,9 +36,9 @@ public class HealthEndpoint<T> {
|
||||
this.indicator = indicator;
|
||||
}
|
||||
|
||||
@RequestMapping("${endpoints.healthz.path:/healthz}")
|
||||
@RequestMapping("${endpoints.health.path:/health}")
|
||||
@ResponseBody
|
||||
public T healthz() {
|
||||
public T health() {
|
||||
return this.indicator.health();
|
||||
}
|
||||
|
||||
|
@ -39,9 +39,9 @@ public class MetricsEndpoint {
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@RequestMapping("${endpoints.varz.path:/varz}")
|
||||
@RequestMapping("${endpoints.metrics.path:/metrics}")
|
||||
@ResponseBody
|
||||
public Map<String, Object> varz() {
|
||||
public Map<String, Object> metrics() {
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
for (Metric metric : this.metrics.metrics()) {
|
||||
result.put(metric.getName(), metric.getValue());
|
||||
|
@ -18,10 +18,16 @@ package org.springframework.bootstrap.actuate.autoconfigure;
|
||||
|
||||
import org.junit.Test;
|
||||
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.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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
@ -41,4 +47,35 @@ public class SecurityConfigurationTests {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ public class ManagementAddressServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarz() throws Exception {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:" + managementPort + "/varz", Map.class);
|
||||
"http://localhost:" + managementPort + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@ -89,9 +89,9 @@ public class ManagementAddressServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealthz() throws Exception {
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:" + managementPort + "/healthz", String.class);
|
||||
"http://localhost:" + managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ public class ManagementServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealthz() throws Exception {
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:" + managementPort + "/healthz", String.class);
|
||||
"http://localhost:" + managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ public class NoManagementServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test(expected = ResourceAccessException.class)
|
||||
public void testVarzNotAvailable() throws Exception {
|
||||
public void testMetricsNotAvailable() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,11 @@ public class ServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarz() throws Exception {
|
||||
public void testMetrics() throws Exception {
|
||||
testHome(); // makes sure some requests have been made
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = getRestTemplate("user", "password").getForEntity(
|
||||
"http://localhost:8080/varz", Map.class);
|
||||
"http://localhost:8080/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
@ -96,9 +96,9 @@ public class ServiceBootstrapApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealthz() throws Exception {
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
||||
"http://localhost:8080/healthz", String.class);
|
||||
"http://localhost:8080/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("ok", entity.getBody());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user