fix:fix SCG report wrong service bug when using IP routing. (#1064)

pull/1067/head
Haotian Zhang 1 year ago committed by GitHub
parent 0ff2b595a1
commit b63d50dc6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,3 +19,4 @@
- [fix:fix circuit breaker bean load order bug when using Nacos discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1049)
- [refactor:refactor Polaris registration.](https://github.com/Tencent/spring-cloud-tencent/pull/1056)
- [feat:added automatic optimization for dynamic config refresh type.](https://github.com/Tencent/spring-cloud-tencent/pull/1059)
- [fix:fix SCG report wrong service bug when using IP routing.](https://github.com/Tencent/spring-cloud-tencent/pull/1064)

@ -73,7 +73,7 @@
<revision>1.12.0-2020.0.6-SNAPSHOT</revision>
<!-- Dependencies -->
<polaris.version>1.13.0-SNAPSHOT</polaris.version>
<polaris.version>1.13.0</polaris.version>
<guava.version>32.0.1-jre</guava.version>
<logback.version>1.2.11</logback.version>
<mocktio.version>4.5.1</mocktio.version>

@ -17,6 +17,8 @@
package com.tencent.cloud.rpc.enhancement.scg;
import java.net.URI;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginContext;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginRunner;
import com.tencent.cloud.rpc.enhancement.plugin.EnhancedPluginType;
@ -33,6 +35,7 @@ import org.springframework.web.server.ServerWebExchange;
import static org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter.LOAD_BALANCER_CLIENT_FILTER_ORDER;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_LOADBALANCER_RESPONSE_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR;
/**
* EnhancedGatewayGlobalFilter.
@ -50,11 +53,11 @@ public class EnhancedGatewayGlobalFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
EnhancedPluginContext enhancedPluginContext = new EnhancedPluginContext();
URI uri = exchange.getAttribute(GATEWAY_REQUEST_URL_ATTR);
EnhancedRequestContext enhancedRequestContext = EnhancedRequestContext.builder()
.httpHeaders(exchange.getRequest().getHeaders())
.httpMethod(exchange.getRequest().getMethod())
.url(exchange.getRequest().getURI())
.url(uri)
.build();
enhancedPluginContext.setRequest(enhancedRequestContext);
@ -65,7 +68,7 @@ public class EnhancedGatewayGlobalFilter implements GlobalFilter, Ordered {
enhancedPluginContext.setTargetServiceInstance(instance, exchange.getRequest().getURI());
}
else {
enhancedPluginContext.setTargetServiceInstance(null, exchange.getRequest().getURI());
enhancedPluginContext.setTargetServiceInstance(null, uri);
}
// Run pre enhanced plugins.

@ -57,16 +57,13 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_LOADBALANCER_RESPONSE_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR;
@ExtendWith(MockitoExtension.class)
public class EnhancedGatewayGlobalFilterTest {
private static MockedStatic<ApplicationContextAwareUtils> mockedApplicationContextAwareUtils;
@Mock
private RpcEnhancementReporterProperties reporterProperties;
@Mock
private SDKContext sdkContext;
@Mock
Registration registration;
@Mock
ServerWebExchange exchange;
@ -76,6 +73,10 @@ public class EnhancedGatewayGlobalFilterTest {
ServerHttpResponse response;
@Mock
ServerHttpRequest request;
@Mock
private RpcEnhancementReporterProperties reporterProperties;
@Mock
private SDKContext sdkContext;
@BeforeAll
static void beforeAll() {
@ -87,7 +88,8 @@ public class EnhancedGatewayGlobalFilterTest {
StaticMetadataManager staticMetadataManager = mock(StaticMetadataManager.class);
doReturn(metadataLocalProperties).when(applicationContext).getBean(MetadataLocalProperties.class);
doReturn(staticMetadataManager).when(applicationContext).getBean(StaticMetadataManager.class);
mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext).thenReturn(applicationContext);
mockedApplicationContextAwareUtils.when(ApplicationContextAwareUtils::getApplicationContext)
.thenReturn(applicationContext);
}
@AfterAll
@ -123,6 +125,7 @@ public class EnhancedGatewayGlobalFilterTest {
}
};
doReturn(serviceInstanceResponse).when(exchange).getAttribute(GATEWAY_LOADBALANCER_RESPONSE_ATTR);
doReturn(new URI("http://0.0.0.0/")).when(exchange).getAttribute(GATEWAY_REQUEST_URL_ATTR);
doReturn(request).when(exchange).getRequest();
doReturn(response).when(exchange).getResponse();

Loading…
Cancel
Save