fix:fix instance circuit breaker not working bug. (#892)

pull/895/head
Haotian Zhang 2 years ago committed by GitHub
parent ec82c1b4c4
commit 257e4a3512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,3 +15,4 @@
- [feature:add polaris circuit breaker support.](https://github.com/Tencent/spring-cloud-tencent/pull/881)
- [fix:fix NPE.](https://github.com/Tencent/spring-cloud-tencent/pull/885)
- [refactor:optimize sct-all.](https://github.com/Tencent/spring-cloud-tencent/pull/889)
- [fix:fix instance circuit breaker not working bug.](https://github.com/Tencent/spring-cloud-tencent/pull/892)

@ -20,15 +20,22 @@ package com.tencent.cloud.polaris.loadbalancer;
import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled;
import com.tencent.polaris.router.api.core.RouterAPI;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
/**
@ -41,6 +48,11 @@ import org.springframework.core.env.Environment;
@ConditionalOnDiscoveryEnabled
public class PolarisLoadBalancerClientConfiguration {
/**
* Order of reactive discovery service instance supplier.
*/
private static final int REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER = 193827465;
private final static String STRATEGY_WEIGHT = "polarisWeighted";
@Bean
@ -52,4 +64,35 @@ public class PolarisLoadBalancerClientConfiguration {
return new PolarisLoadBalancer(name,
loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), routerAPI);
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnReactiveDiscoveryEnabled
@Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER)
protected static class PolarisReactiveSupportConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(ReactiveDiscoveryClient.class)
public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return new PolarisServiceInstanceListSupplier(
ServiceInstanceListSupplier.builder().withDiscoveryClient().build(context));
}
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnBlockingDiscoveryEnabled
@Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER + 1)
protected static class PolarisBlockingSupportConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(DiscoveryClient.class)
public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return new PolarisServiceInstanceListSupplier(
ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().build(context));
}
}
}

@ -0,0 +1,49 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.tencent.cloud.polaris.loadbalancer;
import java.util.List;
import reactor.core.publisher.Flux;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.loadbalancer.core.DelegatingServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
/**
* Service instance list supplier of Polaris.
*
* @author Haotian Zhang
*/
public class PolarisServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier {
public PolarisServiceInstanceListSupplier(ServiceInstanceListSupplier delegate) {
super(delegate);
}
@Override
public Flux<List<ServiceInstance>> get() {
return getDelegate().get();
}
@Override
public Flux<List<ServiceInstance>> get(Request request) {
return super.get(request);
}
}

@ -41,6 +41,7 @@ import com.tencent.polaris.api.rpc.InstanceRegisterRequest;
import com.tencent.polaris.api.rpc.InstanceRegisterResponse;
import com.tencent.polaris.api.rpc.InstancesResponse;
import com.tencent.polaris.client.util.NamedThreadFactory;
import com.tencent.polaris.factory.config.provider.ServiceConfigImpl;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -145,6 +146,11 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
LOGGER.warn("Stat server started error, ", e);
}
}
ServiceConfigImpl serviceConfig = (ServiceConfigImpl) polarisDiscoveryHandler.getSdkContext().getConfig()
.getProvider().getService();
serviceConfig.setNamespace(polarisDiscoveryProperties.getNamespace());
serviceConfig.setName(serviceId);
}
catch (Exception e) {
LOGGER.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);

@ -73,7 +73,7 @@
<revision>1.10.0-2020.0.5-SNAPSHOT</revision>
<!-- Dependencies -->
<polaris.version>1.11.0</polaris.version>
<polaris.version>1.11.1-SNAPSHOT</polaris.version>
<guava.version>31.0.1-jre</guava.version>
<logback.version>1.2.11</logback.version>
<mocktio.version>4.5.1</mocktio.version>

Loading…
Cancel
Save