Compare commits

...

1 Commits

Author SHA1 Message Date
Olga Maciaszek-Sharma 7e9491f006 Use raw status codes in ResponseData. 3 years ago
  1. 13
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/ResponseData.java
  2. 2
      spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/stats/LoadBalancerTags.java
  3. 4
      spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/stats/MicrometerStatsLoadBalancerLifecycleTests.java

13
spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/ResponseData.java

@ -23,7 +23,6 @@ import java.util.Objects; @@ -23,7 +23,6 @@ import java.util.Objects;
import org.springframework.core.style.ToStringCreator;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponse;
@ -40,7 +39,7 @@ import org.springframework.web.reactive.function.client.ClientResponse; @@ -40,7 +39,7 @@ import org.springframework.web.reactive.function.client.ClientResponse;
*/
public class ResponseData {
private final HttpStatus httpStatus;
private final Integer httpStatus;
private final HttpHeaders headers;
@ -48,7 +47,7 @@ public class ResponseData { @@ -48,7 +47,7 @@ public class ResponseData {
private final RequestData requestData;
public ResponseData(HttpStatus httpStatus, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies,
public ResponseData(Integer httpStatus, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies,
RequestData requestData) {
this.httpStatus = httpStatus;
this.headers = headers;
@ -57,19 +56,19 @@ public class ResponseData { @@ -57,19 +56,19 @@ public class ResponseData {
}
public ResponseData(ClientResponse response, RequestData requestData) {
this(response.statusCode(), response.headers().asHttpHeaders(), response.cookies(), requestData);
this(response.rawStatusCode(), response.headers().asHttpHeaders(), response.cookies(), requestData);
}
public ResponseData(ServerHttpResponse response, RequestData requestData) {
this(response.getStatusCode(), response.getHeaders(), response.getCookies(), requestData);
this(response.getRawStatusCode(), response.getHeaders(), response.getCookies(), requestData);
}
public ResponseData(ClientHttpResponse clientHttpResponse, RequestData requestData) throws IOException {
this(clientHttpResponse.getStatusCode(), clientHttpResponse.getHeaders(),
this(clientHttpResponse.getRawStatusCode(), clientHttpResponse.getHeaders(),
buildCookiesFromHeaders(clientHttpResponse.getHeaders()), requestData);
}
public HttpStatus getHttpStatus() {
public Integer getHttpStatus() {
return httpStatus;
}

2
spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/stats/LoadBalancerTags.java

@ -67,7 +67,7 @@ final class LoadBalancerTags { @@ -67,7 +67,7 @@ final class LoadBalancerTags {
// In keeping with the way null HttpStatus is handled in Actuator
private static int statusValue(ResponseData responseData) {
return responseData.getHttpStatus() != null ? responseData.getHttpStatus().value() : 200;
return responseData.getHttpStatus() != null ? responseData.getHttpStatus() : 200;
}
private static String getPath(RequestData requestData) {

4
spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/stats/MicrometerStatsLoadBalancerLifecycleTests.java

@ -62,7 +62,7 @@ class MicrometerStatsLoadBalancerLifecycleTests { @@ -62,7 +62,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
ResponseData responseData = new ResponseData(HttpStatus.OK, new HttpHeaders(),
ResponseData responseData = new ResponseData(HttpStatus.OK.value(), new HttpHeaders(),
new MultiValueMapAdapter<>(new HashMap<>()), requestData);
statsLifecycle.onStartRequest(lbRequest, lbResponse);
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);
@ -121,7 +121,7 @@ class MicrometerStatsLoadBalancerLifecycleTests { @@ -121,7 +121,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
Request<Object> lbRequest = new DefaultRequest<>(new StatsTestContext());
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
ResponseData responseData = new ResponseData(HttpStatus.OK, new HttpHeaders(),
ResponseData responseData = new ResponseData(HttpStatus.OK.value(), new HttpHeaders(),
new MultiValueMapAdapter<>(new HashMap<>()), null);
statsLifecycle.onStartRequest(lbRequest, lbResponse);
assertThat(meterRegistry.get("loadbalancer.requests.active").gauge().value()).isEqualTo(1);

Loading…
Cancel
Save