refactor:update registry status. (#1484)

2023
Haotian Zhang 7 days ago committed by GitHub
parent f59e820c73
commit a5dc460b9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -43,3 +43,4 @@
- [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1480) - [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1480)
- [feat:support smooth upgrade from tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1482) - [feat:support smooth upgrade from tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1482)
- [fix:fix caller disposable metadata handle when using tracing.](https://github.com/Tencent/spring-cloud-tencent/pull/1483) - [fix:fix caller disposable metadata handle when using tracing.](https://github.com/Tencent/spring-cloud-tencent/pull/1483)
- [refactor:update registry status.](https://github.com/Tencent/spring-cloud-tencent/pull/1484)

@ -235,7 +235,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName); InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName);
Instance[] instances = instancesResponse.getInstances(); Instance[] instances = instancesResponse.getInstances();
if (null == instances) { if (null == instances) {
return null; return "DOWN";
} }
for (Instance instance : instances) { for (Instance instance : instances) {
if (instance.getHost().equalsIgnoreCase(registration.getHost()) if (instance.getHost().equalsIgnoreCase(registration.getHost())
@ -243,7 +243,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
return instance.isHealthy() ? "UP" : "DOWN"; return instance.isHealthy() ? "UP" : "DOWN";
} }
} }
return null; return "DOWN";
} }
/** /**

@ -158,26 +158,25 @@ public final class MetadataContextHolder {
Map<String, String> dynamicApplicationMetadata, MetadataProvider callerMetadataProvider) { Map<String, String> dynamicApplicationMetadata, MetadataProvider callerMetadataProvider) {
com.tencent.polaris.metadata.core.manager.MetadataContextHolder.refresh(metadataManager -> { com.tencent.polaris.metadata.core.manager.MetadataContextHolder.refresh(metadataManager -> {
// caller transitive metadata to local custom transitive metadata // caller transitive metadata to local custom transitive metadata
MetadataContainer metadataContainerUpstream = metadataManager.getMetadataContainer(MetadataType.CUSTOM, false); MetadataContainer calleeCustomMetadataContainer = metadataManager.getMetadataContainer(MetadataType.CUSTOM, false);
if (!CollectionUtils.isEmpty(dynamicTransitiveMetadata)) { if (!CollectionUtils.isEmpty(dynamicTransitiveMetadata)) {
for (Map.Entry<String, String> entry : dynamicTransitiveMetadata.entrySet()) { for (Map.Entry<String, String> entry : dynamicTransitiveMetadata.entrySet()) {
metadataContainerUpstream.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.PASS_THROUGH); calleeCustomMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.PASS_THROUGH);
} }
} }
// caller disposable metadata to caller custom disposable metadata // caller disposable metadata to caller custom disposable metadata
MetadataContainer metadataContainerDownstream = metadataManager.getMetadataContainer(MetadataType.CUSTOM, false);
MetadataContainer callerCustomMetadataContainer = metadataManager.getMetadataContainer(MetadataType.CUSTOM, true); MetadataContainer callerCustomMetadataContainer = metadataManager.getMetadataContainer(MetadataType.CUSTOM, true);
if (!CollectionUtils.isEmpty(dynamicDisposableMetadata)) { if (!CollectionUtils.isEmpty(dynamicDisposableMetadata)) {
for (Map.Entry<String, String> entry : dynamicDisposableMetadata.entrySet()) { for (Map.Entry<String, String> entry : dynamicDisposableMetadata.entrySet()) {
metadataContainerDownstream.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.NONE); calleeCustomMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.NONE);
callerCustomMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE); callerCustomMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE);
} }
} }
// caller application metadata to caller application disposable metadata // caller application metadata to caller application disposable metadata
MetadataContainer applicationMetadataContainerDownstream = metadataManager.getMetadataContainer(MetadataType.APPLICATION, true); MetadataContainer callerApplicationMetadataContainer = metadataManager.getMetadataContainer(MetadataType.APPLICATION, true);
if (!CollectionUtils.isEmpty(dynamicApplicationMetadata)) { if (!CollectionUtils.isEmpty(dynamicApplicationMetadata)) {
for (Map.Entry<String, String> entry : dynamicApplicationMetadata.entrySet()) { for (Map.Entry<String, String> entry : dynamicApplicationMetadata.entrySet()) {
applicationMetadataContainerDownstream.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE); callerApplicationMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE);
} }
} }

@ -129,6 +129,10 @@ public final class TsfCoreEnvironmentPostProcessor implements EnvironmentPostPro
defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.enabled", "true"); defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.enabled", "true");
defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.is-need-test-connectivity", "true"); defaultProperties.put("spring.cloud.polaris.discovery.zero-protection.is-need-test-connectivity", "true");
defaultProperties.put("spring.cloud.discovery.client.health-indicator.enabled", "false"); defaultProperties.put("spring.cloud.discovery.client.health-indicator.enabled", "false");
String warmupEnabled = environment.getProperty("spring.cloud.polaris.warmup.enabled");
if (StringUtils.isBlank(warmupEnabled)) {
defaultProperties.put("spring.cloud.polaris.warmup.enabled", true);
}
// contract // contract
defaultProperties.put("spring.cloud.polaris.contract.enabled", environment.getProperty("tsf.swagger.enabled", "true")); defaultProperties.put("spring.cloud.polaris.contract.enabled", environment.getProperty("tsf.swagger.enabled", "true"));

Loading…
Cancel
Save