mirror of
https://github.com/spring-cloud/spring-cloud-netflix.git
synced 2026-09-17 15:49:00 +00:00
Merge remote-tracking branch 'origin/2.0.x'
This commit is contained in:
+1
-1
@@ -121,7 +121,7 @@ public class HystrixCircuitBreakerConfiguration {
|
||||
else if (value instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> sub = (Map<String, Object>) value;
|
||||
addMetrics(sub, prefix);
|
||||
addMetrics(sub, prefix + "." + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
-8
@@ -18,6 +18,7 @@
|
||||
package org.springframework.cloud.netflix.hystrix;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
|
||||
@@ -50,6 +51,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
import static org.springframework.cloud.netflix.test.TestAutoConfiguration.PASSWORD;
|
||||
import static org.springframework.cloud.netflix.test.TestAutoConfiguration.USER;
|
||||
@@ -59,7 +61,7 @@ import static org.springframework.cloud.netflix.test.TestAutoConfiguration.USER;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = HystrixOnlyApplication.class, webEnvironment = RANDOM_PORT,
|
||||
properties = "management.endpoint.health.show-details=ALWAYS")
|
||||
properties = {"management.endpoint.health.show-details=ALWAYS"})
|
||||
@DirtiesContext
|
||||
@ActiveProfiles("proxysecurity")
|
||||
public class HystrixOnlyTests {
|
||||
@@ -101,17 +103,45 @@ public class HystrixOnlyTests {
|
||||
map.containsKey("discovery"));
|
||||
}
|
||||
|
||||
private Map getHealth() {
|
||||
ResponseEntity<Map> response = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + BASE_PATH + "/health", HttpMethod.GET,
|
||||
@Test
|
||||
public void testHystrixInnerMapMetrics() {
|
||||
// We have to hit any Hystrix command before Hystrix metrics to be populated
|
||||
String url = "http://localhost:" + this.port;
|
||||
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url,
|
||||
String.class);
|
||||
assertEquals("bad response code", HttpStatus.OK, response.getStatusCode());
|
||||
|
||||
// Poller takes some time to realize for new metrics
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {}
|
||||
|
||||
Map<String, List<String>> map = (Map<String, List<String>>) getMetrics();
|
||||
|
||||
assertTrue("There is no latencyTotal group key specified",
|
||||
map.get("names").contains("hystrix.latency.total"));
|
||||
assertTrue("There is no latencyExecute group key specified",
|
||||
map.get("names").contains("hystrix.latency.execution"));
|
||||
}
|
||||
|
||||
|
||||
private Map<?, ?> getMetrics() {
|
||||
return getAuthenticatedEndpoint("/metrics");
|
||||
}
|
||||
|
||||
private Map<?, ?> getHealth() {
|
||||
return getAuthenticatedEndpoint("/health");
|
||||
}
|
||||
|
||||
private Map<?, ?> getAuthenticatedEndpoint(String endpoint) {
|
||||
return new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + BASE_PATH + endpoint, HttpMethod.GET,
|
||||
new HttpEntity<Void>(createBasicAuthHeader(USER, PASSWORD)),
|
||||
Map.class);
|
||||
Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
return response.getBody();
|
||||
Map.class).getBody();
|
||||
}
|
||||
|
||||
public static HttpHeaders createBasicAuthHeader(final String username,
|
||||
final String password) {
|
||||
final String password) {
|
||||
return new HttpHeaders() {
|
||||
private static final long serialVersionUID = 1766341693637204893L;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user