fix conflicts during merging

pull/619/head
pandaapo 3 years ago
commit c8654a275e

@ -6,3 +6,5 @@
- [Optimize: remove useless code for rest template router](https://github.com/Tencent/spring-cloud-tencent/pull/601) - [Optimize: remove useless code for rest template router](https://github.com/Tencent/spring-cloud-tencent/pull/601)
- [Optimize: optimize configuration conditional & optimize config data tips](https://github.com/Tencent/spring-cloud-tencent/pull/603) - [Optimize: optimize configuration conditional & optimize config data tips](https://github.com/Tencent/spring-cloud-tencent/pull/603)
- [Automatically transmit some headers specified by a environment varaible that directly defines header keys.](https://github.com/Tencent/spring-cloud-tencent/pull/606) - [Automatically transmit some headers specified by a environment varaible that directly defines header keys.](https://github.com/Tencent/spring-cloud-tencent/pull/606)
- [Optimize: Maybe remove Chinese characters](https://github.com/Tencent/spring-cloud-tencent/pull/607)
- [ fix pr #606 cause ci fail](https://github.com/Tencent/spring-cloud-tencent/pull/613)

@ -1,6 +1,6 @@
# Contributing # Contributing
--- ---
If you have good comments or suggestions, welcome to create [Issues](https://github.com/Tencent/spring-cloud-tencent/issues) or [Pull Requests](https://github.com/Tencent/spring-cloud-tencent/pulls)contribute to the Spring Cloud Tencent open source community. Spring Cloud Tencent continues to recruit contributors, even if it is answering questions in the issue, or doing some simple bugfixes, it will be of great help to Spring Cloud Tencent. If you have good comments or suggestions, welcome to create [Issues](https://github.com/Tencent/spring-cloud-tencent/issues) or [Pull Requests](https://github.com/Tencent/spring-cloud-tencent/pulls), contribute to the Spring Cloud Tencent open source community. Spring Cloud Tencent continues to recruit contributors, even if it is answering questions in the issue, or doing some simple bugfixes, it will be of great help to Spring Cloud Tencent.
[Tencent Open Source Incentive Program](https://opensource.tencent.com/contribution) Encourage developers to participate and contribute, and look forward to your joining. [Tencent Open Source Incentive Program](https://opensource.tencent.com/contribution) Encourage developers to participate and contribute, and look forward to your joining.

@ -113,7 +113,7 @@ You can build this project with command:
- [Actuator Endpoint Extension](https://github.com/Tencent/spring-cloud-tencent/wiki/Actuator-Endpoint-%E6%89%A9%E5%B1%95) - [Actuator Endpoint Extension](https://github.com/Tencent/spring-cloud-tencent/wiki/Actuator-Endpoint-%E6%89%A9%E5%B1%95)
- 最佳实践 - 最佳实践
- [Multi-feature environment](https://github.com/Tencent/spring-cloud-tencent/wiki/多特性环境) - [Multi-feature environment](https://github.com/Tencent/spring-cloud-tencent/wiki/%E5%A4%9A%E7%89%B9%E6%80%A7%E7%8E%AF%E5%A2%83)
- [Multi-registration and multi-discovery](https://github.com/Tencent/spring-cloud-tencent/wiki/Multi-registration-and-multi-discovery) - [Multi-registration and multi-discovery](https://github.com/Tencent/spring-cloud-tencent/wiki/Multi-registration-and-multi-discovery)
- 开发文档 - 开发文档

@ -115,7 +115,7 @@ You can build this project with command:
- [Actuator Endpoint Extension](https://github.com/Tencent/spring-cloud-tencent/wiki/Actuator-Endpoint-%E6%89%A9%E5%B1%95) - [Actuator Endpoint Extension](https://github.com/Tencent/spring-cloud-tencent/wiki/Actuator-Endpoint-%E6%89%A9%E5%B1%95)
- Best Practices - Best Practices
- [Multi-feature environment](https://github.com/Tencent/spring-cloud-tencent/wiki/多特性环境) - [Multi-feature environment](https://github.com/Tencent/spring-cloud-tencent/wiki/%E5%A4%9A%E7%89%B9%E6%80%A7%E7%8E%AF%E5%A2%83)
- [Multi-registration and multi-discovery](https://github.com/Tencent/spring-cloud-tencent/wiki/Multi-registration-and-multi-discovery) - [Multi-registration and multi-discovery](https://github.com/Tencent/spring-cloud-tencent/wiki/Multi-registration-and-multi-discovery)
- Development documentation - Development documentation

@ -22,7 +22,7 @@
- [Optimize router label resolver spi](https://github.com/Tencent/spring-cloud-tencent/pull/524) - [Optimize router label resolver spi](https://github.com/Tencent/spring-cloud-tencent/pull/524)
- [Code optimization for rpc-enhancement module](https://github.com/Tencent/spring-cloud-tencent/pull/526) - [Code optimization for rpc-enhancement module](https://github.com/Tencent/spring-cloud-tencent/pull/526)
- [Feature: Optimized configuration update](https://github.com/Tencent/spring-cloud-tencent/pull/528) - [Feature: Optimized configuration update](https://github.com/Tencent/spring-cloud-tencent/pull/528)
- [Featuresupport pushGateway push metrics](https://github.com/Tencent/spring-cloud-tencent/pull/529) - [Feature: support pushGateway push metrics](https://github.com/Tencent/spring-cloud-tencent/pull/529)
- [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/536) - [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/536)
- [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/542) - [Feature: remove location metadata](https://github.com/Tencent/spring-cloud-tencent/pull/542)
- [add feature-env plugin & add spring cloud gateway staining plugin](https://github.com/Tencent/spring-cloud-tencent/pull/533) - [add feature-env plugin & add spring cloud gateway staining plugin](https://github.com/Tencent/spring-cloud-tencent/pull/533)

@ -104,7 +104,7 @@ public class DecodeTransferMetadataReactiveFilter implements WebFilter, Ordered
.getFragmentContext(FRAGMENT_RAW_TRANSHEADERS); .getFragmentContext(FRAGMENT_RAW_TRANSHEADERS);
if (!CollectionUtils.isEmpty(transHeaderMetadata)) { if (!CollectionUtils.isEmpty(transHeaderMetadata)) {
Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst(); Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst();
String[] transHeaderArray = transHeaders.get().split(";"); String[] transHeaderArray = transHeaders.get().split(",");
HttpHeaders headers = serverHttpRequest.getHeaders(); HttpHeaders headers = serverHttpRequest.getHeaders();
Set<String> headerKeys = headers.keySet(); Set<String> headerKeys = headers.keySet();
Iterator<String> iterator = headerKeys.iterator(); Iterator<String> iterator = headerKeys.iterator();

@ -91,7 +91,7 @@ public class DecodeTransferMetadataServletFilter extends OncePerRequestFilter {
.getFragmentContext(FRAGMENT_RAW_TRANSHEADERS); .getFragmentContext(FRAGMENT_RAW_TRANSHEADERS);
if (!CollectionUtils.isEmpty(transHeaderMetadata)) { if (!CollectionUtils.isEmpty(transHeaderMetadata)) {
Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst(); Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst();
String[] transHeaderArray = transHeaders.get().split(";"); String[] transHeaderArray = transHeaders.get().split(",");
Enumeration<String> httpHeaders = httpServletRequest.getHeaderNames(); Enumeration<String> httpHeaders = httpServletRequest.getHeaderNames();
while (httpHeaders.hasMoreElements()) { while (httpHeaders.hasMoreElements()) {
String httpHeader = httpHeaders.nextElement(); String httpHeader = httpHeaders.nextElement();

@ -102,7 +102,7 @@ public class EncodeTransferMedataScgFilter implements GlobalFilter, Ordered {
.getFragmentContext(FRAGMENT_RAW_TRANSHEADERS); .getFragmentContext(FRAGMENT_RAW_TRANSHEADERS);
if (!CollectionUtils.isEmpty(transHeaderMetadata)) { if (!CollectionUtils.isEmpty(transHeaderMetadata)) {
Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst(); Optional<String> transHeaders = transHeaderMetadata.keySet().stream().findFirst();
String[] transHeaderArray = transHeaders.get().split(";"); String[] transHeaderArray = transHeaders.get().split(",");
HttpHeaders headers = serverHttpRequest.getHeaders(); HttpHeaders headers = serverHttpRequest.getHeaders();
Set<String> headerKeys = headers.keySet(); Set<String> headerKeys = headers.keySet();
Iterator<String> iterator = headerKeys.iterator(); Iterator<String> iterator = headerKeys.iterator();

@ -40,7 +40,7 @@ import static com.tencent.cloud.polaris.config.listener.PolarisConfigListenerCon
/** /**
* {@link PolarisConfigAnnotationProcessor} implementation for spring . * {@link PolarisConfigAnnotationProcessor} implementation for spring .
* <p>This source file was reference from * <p>This source file was reference from:
* <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java> * <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java>
* ApolloAnnotationProcessor</a></code> * ApolloAnnotationProcessor</a></code>
* @author <a href="mailto:iskp.me@gmail.com">Palmer Xu</a> 2022-06-07 * @author <a href="mailto:iskp.me@gmail.com">Palmer Xu</a> 2022-06-07

@ -26,7 +26,7 @@ import java.lang.annotation.Target;
/** /**
* Configuring the change listener annotation. * Configuring the change listener annotation.
* <p>This source file was reference from * <p>This source file was reference from:
* <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java> * <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java>
* ApolloAnnotationProcessor</a></code> * ApolloAnnotationProcessor</a></code>
* @author Palmer Xu 2022-05-31 * @author Palmer Xu 2022-05-31

@ -52,7 +52,7 @@ import static org.springframework.boot.context.config.ConfigData.Option.PROFILE_
* Load {@link ConfigData} via {@link PolarisConfigDataLoader} * Load {@link ConfigData} via {@link PolarisConfigDataLoader}
* *
* @author wlx * @author wlx
* @date 2022/7/5 11:14 * @date 2022/7/5 11:14 PM
*/ */
public class PolarisConfigDataLoader implements ConfigDataLoader<PolarisConfigDataResource> { public class PolarisConfigDataLoader implements ConfigDataLoader<PolarisConfigDataResource> {

@ -30,7 +30,7 @@ import org.springframework.boot.context.config.Profiles;
* A polaris configData resource from which {@link ConfigData} can be loaded. * A polaris configData resource from which {@link ConfigData} can be loaded.
* *
* @author wlx * @author wlx
* @date 2022/7/5 11:13 * @date 2022/7/5 11:13 PM
*/ */
public class PolarisConfigDataResource extends ConfigDataResource { public class PolarisConfigDataResource extends ConfigDataResource {

@ -7,7 +7,7 @@ import org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcess
/** /**
* Class for most {@code FailureAnalyzer} implementations, to analyze ImportException when * Class for most {@code FailureAnalyzer} implementations, to analyze ImportException when
* miss Polaris configData config. * miss Polaris configData config.
* <p>Refer to the Nacos project implementation * <p>Refer to the Nacos project implementation:
* <code><a href=https://github.com/alibaba/spring-cloud-alibaba/blob/2021.x/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataMissingEnvironmentPostProcessor.java> * <code><a href=https://github.com/alibaba/spring-cloud-alibaba/blob/2021.x/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/configdata/NacosConfigDataMissingEnvironmentPostProcessor.java>
* ImportExceptionFailureAnalyzer</a></code> * ImportExceptionFailureAnalyzer</a></code>
* *

@ -49,7 +49,7 @@ import static com.tencent.polaris.configuration.api.core.ChangeType.MODIFIED;
/** /**
* Polaris Config Listener Context Defined . * Polaris Config Listener Context Defined .
* <p>This source file was reference from * <p>This source file was reference from:
* <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java> * <code><a href=https://github.com/apolloconfig/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java>
* AbstractConfig</a></code> * AbstractConfig</a></code>
* @author Palmer Xu 2022-06-06 * @author Palmer Xu 2022-06-06

@ -22,22 +22,21 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Auto service registration of Polaris. * Auto service registration of Polaris.
* *
* @author Haotian Zhang, Andrew Shan, Jie Cheng * @author Haotian Zhang, Andrew Shan, Jie Cheng, changjin wei()
*/ */
public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistration<Registration> { public class PolarisAutoServiceRegistration extends AbstractAutoServiceRegistration<PolarisRegistration> {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAutoServiceRegistration.class); private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAutoServiceRegistration.class);
private final PolarisRegistration registration; private final PolarisRegistration registration;
public PolarisAutoServiceRegistration(ServiceRegistry<Registration> serviceRegistry, public PolarisAutoServiceRegistration(ServiceRegistry<PolarisRegistration> serviceRegistry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties, PolarisRegistration registration) { AutoServiceRegistrationProperties autoServiceRegistrationProperties, PolarisRegistration registration) {
super(serviceRegistry, autoServiceRegistrationProperties); super(serviceRegistry, autoServiceRegistrationProperties);
this.registration = registration; this.registration = registration;

@ -36,7 +36,7 @@ import org.springframework.util.CollectionUtils;
/** /**
* Registration object of Polaris. * Registration object of Polaris.
* *
* @author Haotian Zhang, Andrew Shan, Jie Cheng * @author Haotian Zhang, Andrew Shan, Jie Cheng, changjin wei()
*/ */
public class PolarisRegistration implements Registration { public class PolarisRegistration implements Registration {
@ -55,6 +55,8 @@ public class PolarisRegistration implements Registration {
private String host; private String host;
private String instanceId;
public PolarisRegistration( public PolarisRegistration(
PolarisDiscoveryProperties polarisDiscoveryProperties, PolarisDiscoveryProperties polarisDiscoveryProperties,
@Nullable ConsulContextProperties consulContextProperties, @Nullable ConsulContextProperties consulContextProperties,
@ -120,6 +122,15 @@ public class PolarisRegistration implements Registration {
return polarisDiscoveryProperties; return polarisDiscoveryProperties;
} }
@Override
public String getInstanceId() {
return instanceId;
}
protected void setInstanceId(String instanceId) {
this.instanceId = instanceId;
}
public boolean isRegisterEnabled() { public boolean isRegisterEnabled() {
boolean registerEnabled = false; boolean registerEnabled = false;
@ -141,6 +152,8 @@ public class PolarisRegistration implements Registration {
", polarisContext=" + polarisContext + ", polarisContext=" + polarisContext +
", staticMetadataManager=" + staticMetadataManager + ", staticMetadataManager=" + staticMetadataManager +
", metadata=" + metadata + ", metadata=" + metadata +
", host='" + host + '\'' +
", instanceId='" + instanceId + '\'' +
'}'; '}';
} }
} }

@ -31,6 +31,7 @@ import com.tencent.polaris.api.pojo.Instance;
import com.tencent.polaris.api.rpc.InstanceDeregisterRequest; import com.tencent.polaris.api.rpc.InstanceDeregisterRequest;
import com.tencent.polaris.api.rpc.InstanceHeartbeatRequest; import com.tencent.polaris.api.rpc.InstanceHeartbeatRequest;
import com.tencent.polaris.api.rpc.InstanceRegisterRequest; 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.api.rpc.InstancesResponse;
import com.tencent.polaris.client.util.NamedThreadFactory; import com.tencent.polaris.client.util.NamedThreadFactory;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -38,7 +39,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
@ -47,9 +47,9 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/** /**
* Service registry of Polaris. * Service registry of Polaris.
* *
* @author Haotian Zhang, Andrew Shan, Jie Cheng * @author Haotian Zhang, Andrew Shan, Jie Cheng, changjin wei()
*/ */
public class PolarisServiceRegistry implements ServiceRegistry<Registration> { public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistration> {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisServiceRegistry.class); private static final Logger LOGGER = LoggerFactory.getLogger(PolarisServiceRegistry.class);
@ -78,7 +78,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
@Override @Override
public void register(Registration registration) { public void register(PolarisRegistration registration) {
if (StringUtils.isBlank(registration.getServiceId())) { if (StringUtils.isBlank(registration.getServiceId())) {
LOGGER.warn("No service to register for polaris client..."); LOGGER.warn("No service to register for polaris client...");
@ -103,7 +103,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion()); instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
try { try {
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI(); ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
providerClient.register(instanceRegisterRequest); InstanceRegisterResponse instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
registration.setInstanceId(instanceRegisterResponse.getInstanceId());
LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(), LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(),
registration.getServiceId(), registration.getHost(), registration.getPort(), registration.getServiceId(), registration.getHost(), registration.getPort(),
staticMetadataManager.getMergedStaticMetadata()); staticMetadataManager.getMergedStaticMetadata());
@ -122,7 +123,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
@Override @Override
public void deregister(Registration registration) { public void deregister(PolarisRegistration registration) {
LOGGER.info("De-registering from Polaris Server now..."); LOGGER.info("De-registering from Polaris Server now...");
if (StringUtils.isEmpty(registration.getServiceId())) { if (StringUtils.isEmpty(registration.getServiceId())) {
@ -158,12 +159,12 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
} }
@Override @Override
public void setStatus(Registration registration, String status) { public void setStatus(PolarisRegistration registration, String status) {
} }
@Override @Override
public Object getStatus(Registration registration) { public Object getStatus(PolarisRegistration registration) {
String serviceName = registration.getServiceId(); String serviceName = registration.getServiceId();
InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName); InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName);
Instance[] instances = instancesResponse.getInstances(); Instance[] instances = instancesResponse.getInstances();

@ -62,12 +62,12 @@ public final class OkHttpUtil {
if (response.isSuccessful() && Objects.nonNull(response.body())) { if (response.isSuccessful() && Objects.nonNull(response.body())) {
String result = response.body().string(); String result = response.body().string();
LOGGER.debug("exec get request, url: {} successresponse data: {}", url, result); LOGGER.debug("exec get request, url: {} success, response data: {}", url, result);
return true; return true;
} }
} }
catch (Exception e) { catch (Exception e) {
LOGGER.error("exec get requesturl: {} failed!", url, e); LOGGER.error("exec get request, url: {} failed!", url, e);
} }
return false; return false;
} }

@ -25,7 +25,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -48,7 +47,7 @@ import static org.mockito.Mockito.doReturn;
public class PolarisAutoServiceRegistrationTest { public class PolarisAutoServiceRegistrationTest {
@Mock @Mock
private ServiceRegistry<Registration> serviceRegistry; private ServiceRegistry<PolarisRegistration> serviceRegistry;
@Mock @Mock
private AutoServiceRegistrationProperties autoServiceRegistrationProperties; private AutoServiceRegistrationProperties autoServiceRegistrationProperties;
@ -71,7 +70,7 @@ public class PolarisAutoServiceRegistrationTest {
public void setUp() { public void setUp() {
doReturn(polarisDiscoveryProperties).when(registration).getPolarisProperties(); doReturn(polarisDiscoveryProperties).when(registration).getPolarisProperties();
doNothing().when(serviceRegistry).register(nullable(Registration.class)); doNothing().when(serviceRegistry).register(nullable(PolarisRegistration.class));
polarisAutoServiceRegistration = polarisAutoServiceRegistration =
new PolarisAutoServiceRegistration(serviceRegistry, autoServiceRegistrationProperties, registration); new PolarisAutoServiceRegistration(serviceRegistry, autoServiceRegistrationProperties, registration);

@ -26,6 +26,7 @@ import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils; import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import static com.tencent.cloud.common.metadata.MetadataContext.FRAGMENT_DISPOSABLE; import static com.tencent.cloud.common.metadata.MetadataContext.FRAGMENT_DISPOSABLE;
import static com.tencent.cloud.common.metadata.MetadataContext.FRAGMENT_RAW_TRANSHEADERS; import static com.tencent.cloud.common.metadata.MetadataContext.FRAGMENT_RAW_TRANSHEADERS;
@ -70,6 +71,10 @@ public final class MetadataContextHolder {
metadataContext.putFragmentContext(FRAGMENT_DISPOSABLE, staticMetadataManager.getMergedStaticDisposableMetadata()); metadataContext.putFragmentContext(FRAGMENT_DISPOSABLE, staticMetadataManager.getMergedStaticDisposableMetadata());
metadataContext.putContext(FRAGMENT_RAW_TRANSHEADERS, staticMetadataManager.getEnvTransHeaderMetadata(), ""); metadataContext.putContext(FRAGMENT_RAW_TRANSHEADERS, staticMetadataManager.getEnvTransHeaderMetadata(), "");
if (StringUtils.hasText(staticMetadataManager.getTransHeaderFromEnv())) {
metadataContext.putContext(FRAGMENT_RAW_TRANSHEADERS, staticMetadataManager.getTransHeaderFromEnv(), "");
}
METADATA_CONTEXT.set(metadataContext); METADATA_CONTEXT.set(metadataContext);
return METADATA_CONTEXT.get(); return METADATA_CONTEXT.get();

@ -56,11 +56,11 @@ public class StaticMetadataManager {
private static final String ENV_METADATA_CONTENT_TRANSITIVE = "SCT_METADATA_CONTENT_TRANSITIVE"; private static final String ENV_METADATA_CONTENT_TRANSITIVE = "SCT_METADATA_CONTENT_TRANSITIVE";
private static final String ENV_METADATA_CONTENT_DISPOSABLE = "SCT_METADATA_CONTENT_DISPOSABLE"; private static final String ENV_METADATA_CONTENT_DISPOSABLE = "SCT_METADATA_CONTENT_DISPOSABLE";
/** /**
* This is the key of the header's key list needed to be transmitted. The list is a string split with ;. * This is the key of the header's key list needed to be transmitted. The list is a string split with ,.
* The value mapped by this key was specified by user. * The value mapped by this key was specified by user.
* This is configured in environment variables. * This is configured in environment variables.
*/ */
private static final String ENV_METADATA_CONTENT_RAW_TRANSHEADERS = "SCT_METADATA_CONTENT_RAW_TRANSHEADERS"; private static final String ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS = "SCT_TRAFFIC_CONTENT_RAW_TRANSHEADERS";
private static final String ENV_METADATA_ZONE = "SCT_METADATA_ZONE"; private static final String ENV_METADATA_ZONE = "SCT_METADATA_ZONE";
private static final String ENV_METADATA_REGION = "SCT_METADATA_REGION"; private static final String ENV_METADATA_REGION = "SCT_METADATA_REGION";
private static final String ENV_METADATA_CAMPUS = "SCT_METADATA_CAMPUS"; private static final String ENV_METADATA_CAMPUS = "SCT_METADATA_CAMPUS";
@ -107,7 +107,7 @@ public class StaticMetadataManager {
if (StringUtils.isNotBlank(key) && key.startsWith(ENV_METADATA_PREFIX) if (StringUtils.isNotBlank(key) && key.startsWith(ENV_METADATA_PREFIX)
&& !key.equals(ENV_METADATA_CONTENT_TRANSITIVE)) { && !key.equals(ENV_METADATA_CONTENT_TRANSITIVE)) {
String sourceKey = ""; String sourceKey = "";
if (key.equals(ENV_METADATA_CONTENT_RAW_TRANSHEADERS)) { if (key.equals(ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS)) {
sourceKey = key; sourceKey = key;
} }
else { else {
@ -282,8 +282,8 @@ public class StaticMetadataManager {
return envMetadata; return envMetadata;
} }
public String getEnvTransHeaderMetadata() { public String getTransHeaderFromEnv() {
return envMetadata.get(ENV_METADATA_CONTENT_RAW_TRANSHEADERS); return envMetadata.get(ENV_TRAFFIC_CONTENT_RAW_TRANSHEADERS);
} }
public Map<String, String> getEnvTransitiveMetadata() { public Map<String, String> getEnvTransitiveMetadata() {

@ -29,7 +29,7 @@ import org.springframework.cloud.client.ServiceInstance;
/** /**
* Polaris's implementation of {@link ServiceInstance}. * Polaris's implementation of {@link ServiceInstance}.
* *
* @author Haotian Zhang * @author Haotian Zhang, changjin wei()
*/ */
public class PolarisServiceInstance implements ServiceInstance { public class PolarisServiceInstance implements ServiceInstance {
@ -56,7 +56,7 @@ public class PolarisServiceInstance implements ServiceInstance {
@Override @Override
public String getInstanceId() { public String getInstanceId() {
return ServiceInstance.super.getInstanceId(); return instance.getId();
} }
@Override @Override

@ -5,7 +5,7 @@
This example shows how to use ```spring-cloud-starter-tencent-metadata-transfer``` in Spring Cloud project for its This example shows how to use ```spring-cloud-starter-tencent-metadata-transfer``` in Spring Cloud project for its
features. features.
This example contains ```metadata-frontend```、```metadata-middle```、```metadata-backend```. This example contains ```metadata-frontend```, ```metadata-middle```, ```metadata-backend```.
## Instruction ## Instruction
@ -55,7 +55,7 @@ Execute under ```spring-cloud-tencent-examples/metadata-transfer-example```
mvn clean package mvn clean package
``` ```
Then find the jars under ```metadata-frontend```、```metadata-middle```、```metadata-backend```, and run it: Then find the jars under ```metadata-frontend```, ```metadata-middle```, ```metadata-backend```, and run it:
``` ```
java -jar ${app.jar} java -jar ${app.jar}

@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* @author wlx * @author wlx
* @date 2022/7/6 9:15 * @date 2022/7/6 9:15 PM
*/ */
@SpringBootApplication @SpringBootApplication
public class PolarisConfigDataExampleApplication { public class PolarisConfigDataExampleApplication {

@ -32,7 +32,7 @@ By default, the applications point to the official Polaris experience environmen
registration data at the experience site after a successful launch. registration data at the experience site after a successful launch.
- Console address: http://14.116.241.63:8080/ - Console address: http://14.116.241.63:8080/
- Accountpolaris - Account: polaris
- Password: polaris - Password: polaris
## III. Testing ## III. Testing
@ -89,7 +89,7 @@ Simulate a real-world scenario, assuming that the client request has a uid reque
**Configure coloring rules** **Configure coloring rules**
Polaris Configuration Addresshttp://14.116.241.63:8080/#/filegroup-detail?group=featureenv-gateway&namespace=default Polaris Configuration Address: http://14.116.241.63:8080/#/filegroup-detail?group=featureenv-gateway&namespace=default
Modify the `rule/staining.json` configuration file and fill in the following rule: Modify the `rule/staining.json` configuration file and fill in the following rule:

@ -10,10 +10,10 @@ This project shows how to use Spring Cloud Tencent route and transitive feature
![](https://qcloudimg.tencent-cloud.cn/raw/488182fd3001b3e77d9450e2c8798ff3.png) ![](https://qcloudimg.tencent-cloud.cn/raw/488182fd3001b3e77d9450e2c8798ff3.png)
Incoming requests dispatched from Gateway service to 3 environments Incoming requests dispatched from Gateway service to 3 environments:
- gray1(match uid=1), env=green(green environment) - gray1(match uid=1), env=green(green environment)
- gray2(match uid=2), env=purple(purple environment) - gray2(match uid=2), env=purple(purple environment)
- baselinestable environment, match all other requests, env=blue(blue environment) - baseline(stable environment, match all other requests), env=blue(blue environment)
## How to access ## How to access
@ -26,8 +26,8 @@ Incoming requests dispatched from Gateway service to 3 environments
2. start router-grayrelease-gateway application 2. start router-grayrelease-gateway application
- Launch by IDEStart the main class `GrayReleaseGatewayApplication`. - Launch by IDE: Start the main class `GrayReleaseGatewayApplication`.
- Launch by JarExecute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-gateway-${verion}.jar` to launch application. - Launch by Jar: Execute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-gateway-${verion}.jar` to launch application.
3. add the route rule 3. add the route rule
@ -136,13 +136,13 @@ Incoming requests dispatched from Gateway service to 3 environments
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=blue - env tag: SCT_METADATA_CONTENT_env=blue
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-frontend application 2. start router-grayrelease-frontend application
- Launch by IDEStart the main class `GrayReleaseFrontApplication`. - Launch by IDE: Start the main class `GrayReleaseFrontApplication`.
- Launch by JarExecute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-frontend-${verion}.jar` to launch application. - Launch by Jar: Execute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-frontend-${verion}.jar` to launch application.
#### Start gray1 environment (green) #### Start gray1 environment (green)
@ -150,8 +150,8 @@ Incoming requests dispatched from Gateway service to 3 environments
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=green - env tag: SCT_METADATA_CONTENT_env=green
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-frontend application (same as previous instruction) 2. start router-grayrelease-frontend application (same as previous instruction)
@ -163,8 +163,8 @@ Incoming requests dispatched from Gateway service to 3 environments
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=purple - env tag: SCT_METADATA_CONTENT_env=purple
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-frontend application (same as previous instruction) 2. start router-grayrelease-frontend application (same as previous instruction)
@ -182,13 +182,13 @@ You can find the instances with different tags in polaris console.
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=blue - env tag: SCT_METADATA_CONTENT_env=blue
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-middle application 2. start router-grayrelease-middle application
- Launch by IDEStart the main class `GrayReleaseMiddleApplication`. - Launch by IDE: Start the main class `GrayReleaseMiddleApplication`.
- Launch by JarExecute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-middle-${verion}.jar` to launch application. - Launch by Jar: Execute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-middle-${verion}.jar` to launch application.
#### Start gray2 environment (purple) #### Start gray2 environment (purple)
@ -196,8 +196,8 @@ You can find the instances with different tags in polaris console.
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=purple - env tag: SCT_METADATA_CONTENT_env=purple
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-middle application (same as previous instruction) 2. start router-grayrelease-middle application (same as previous instruction)
@ -209,13 +209,13 @@ You can find the instances with different tags in polaris console.
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=blue - env tag: SCT_METADATA_CONTENT_env=blue
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-backend application 2. start router-grayrelease-backend application
- Launch by IDEStart the main class `GrayReleaseBackendApplication`. - Launch by IDE: Start the main class `GrayReleaseBackendApplication`.
- Launch by JarExecute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-backend-${verion}.jar` to launch application. - Launch by Jar: Execute `mvn clean package` to compile with jar package, then use `java -jar router-grayrelease-backend-${verion}.jar` to launch application.
#### Start gray1 environment (green) #### Start gray1 environment (green)
@ -223,8 +223,8 @@ You can find the instances with different tags in polaris console.
- polaris server address: polaris_address=grpc://127.0.0.1:8091 - polaris server address: polaris_address=grpc://127.0.0.1:8091
- pushgateway address: prometheus_address=127.0.0.1:9091 - pushgateway address: prometheus_address=127.0.0.1:9091
- env tagSCT_METADATA_CONTENT_env=green - env tag: SCT_METADATA_CONTENT_env=green
- transitive tagSCT_METADATA_CONTENT_TRANSITIVE=env - transitive tag: SCT_METADATA_CONTENT_TRANSITIVE=env
2. start router-grayrelease-backend application (same as previous instruction) 2. start router-grayrelease-backend application (same as previous instruction)

Loading…
Cancel
Save