From d7706de428e4d65272d5d9e1591c1f7c514d4d8d Mon Sep 17 00:00:00 2001 From: Haotian Zhang Date: Thu, 12 Dec 2024 20:15:55 +0800 Subject: [PATCH] refactor:update registry status. (#1487) --- CHANGELOG.md | 1 + .../polaris/registry/PolarisServiceRegistry.java | 4 ++-- .../cloud/common/metadata/MetadataContextHolder.java | 11 +++++------ .../extend/tsf/TsfCoreEnvironmentPostProcessor.java | 4 ++++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0407bc58b..5ef0ea11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,3 +38,4 @@ - [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1469) - [feat:support smooth upgrade from tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1473) - [fix:fix caller disposable metadata handle when using tracing.](https://github.com/Tencent/spring-cloud-tencent/pull/1477) +- [refactor:update registry status.](https://github.com/Tencent/spring-cloud-tencent/pull/1487) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java index bb07733a0..f98591bcd 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java @@ -235,7 +235,7 @@ public Object getStatus(PolarisRegistration registration) { InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName); Instance[] instances = instancesResponse.getInstances(); if (null == instances) { - return null; + return "DOWN"; } for (Instance instance : instances) { if (instance.getHost().equalsIgnoreCase(registration.getHost()) @@ -243,7 +243,7 @@ public Object getStatus(PolarisRegistration registration) { return instance.isHealthy() ? "UP" : "DOWN"; } } - return null; + return "DOWN"; } /** diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java index f09a12685..55473bfd8 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java @@ -158,26 +158,25 @@ public static void init(Map dynamicTransitiveMetadata, Map dynamicApplicationMetadata, MetadataProvider callerMetadataProvider) { com.tencent.polaris.metadata.core.manager.MetadataContextHolder.refresh(metadataManager -> { // 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)) { for (Map.Entry 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 - MetadataContainer metadataContainerDownstream = metadataManager.getMetadataContainer(MetadataType.CUSTOM, false); MetadataContainer callerCustomMetadataContainer = metadataManager.getMetadataContainer(MetadataType.CUSTOM, true); if (!CollectionUtils.isEmpty(dynamicDisposableMetadata)) { for (Map.Entry 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); } } // 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)) { for (Map.Entry entry : dynamicApplicationMetadata.entrySet()) { - applicationMetadataContainerDownstream.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE); + callerApplicationMetadataContainer.putMetadataStringValue(entry.getKey(), entry.getValue(), TransitiveType.DISPOSABLE); } } diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfCoreEnvironmentPostProcessor.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfCoreEnvironmentPostProcessor.java index 54b70c54c..484be810f 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfCoreEnvironmentPostProcessor.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfCoreEnvironmentPostProcessor.java @@ -129,6 +129,10 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp 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.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 defaultProperties.put("spring.cloud.polaris.contract.enabled", environment.getProperty("tsf.swagger.enabled", "true"));