From fa1b0de998925ede92f6bdc70eae3feffb6573a0 Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 7 Oct 2024 20:30:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix=EF=BC=9ARefreshAdminServerAddressTask?= =?UTF-8?q?=20supports=20dynamic=20configuration=20of=20time=20interval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/AdminServiceAddressLocator.java | 12 ++++++----- .../portal/component/config/PortalConfig.java | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java index c8d4e72b22b..42ced007a08 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java @@ -16,6 +16,7 @@ */ package com.ctrip.framework.apollo.portal.component; +import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService; import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.portal.environment.Env; @@ -42,8 +43,6 @@ @Component public class AdminServiceAddressLocator { - private static final long NORMAL_REFRESH_INTERVAL = 5 * 60 * 1000; - private static final long OFFLINE_REFRESH_INTERVAL = 10 * 1000; private static final int RETRY_TIMES = 3; private static final String ADMIN_SERVICE_URL_PATH = "/services/admin"; private static final Logger logger = LoggerFactory.getLogger(AdminServiceAddressLocator.class); @@ -56,16 +55,19 @@ public class AdminServiceAddressLocator { private final PortalSettings portalSettings; private final RestTemplateFactory restTemplateFactory; private final PortalMetaDomainService portalMetaDomainService; + private final PortalConfig portalConfig; public AdminServiceAddressLocator( final HttpMessageConverters httpMessageConverters, final PortalSettings portalSettings, final RestTemplateFactory restTemplateFactory, - final PortalMetaDomainService portalMetaDomainService + final PortalMetaDomainService portalMetaDomainService, + final PortalConfig portalConfig ) { this.portalSettings = portalSettings; this.restTemplateFactory = restTemplateFactory; this.portalMetaDomainService = portalMetaDomainService; + this.portalConfig = portalConfig; } @PostConstruct @@ -105,10 +107,10 @@ public void run() { if (refreshSuccess) { refreshServiceAddressService - .schedule(new RefreshAdminServerAddressTask(), NORMAL_REFRESH_INTERVAL, TimeUnit.MILLISECONDS); + .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskNormalIntervalInMilli(), TimeUnit.MILLISECONDS); } else { refreshServiceAddressService - .schedule(new RefreshAdminServerAddressTask(), OFFLINE_REFRESH_INTERVAL, TimeUnit.MILLISECONDS); + .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskOfflineIntervalInMilli(), TimeUnit.MILLISECONDS); } } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index a5a4a9d81ea..e1b86a8c05f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -43,6 +43,9 @@ public class PortalConfig extends RefreshableConfig { private static final Logger logger = LoggerFactory.getLogger(PortalConfig.class); + private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI = 5 * 60 * 1000; //5min + private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI = 10 * 1000; //10s + private static final Gson GSON = new Gson(); private static final Type ORGANIZATION = new TypeToken>() { }.getType(); @@ -193,6 +196,16 @@ public String portalAddress() { return getValue("apollo.portal.address"); } + public int refreshAdminServerAddressTaskNormalIntervalInMilli() { + int interval = getIntProperty("refresh.admin.server.address.task.normal.interval.ms", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI); + return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI); + } + + public int refreshAdminServerAddressTaskOfflineIntervalInMilli() { + int interval = getIntProperty("refresh.admin.server.address.task.offline.interval.ms", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI); + return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI); + } + public boolean isEmergencyPublishAllowed(Env env) { String targetEnv = env.getName(); @@ -304,4 +317,11 @@ public List getUserPasswordNotAllowList() { } return Arrays.asList(value); } + + int checkInt(int value, int min, int max, int defaultValue) { + if (value >= min && value <= max) { + return value; + } + return defaultValue; + } } From 103a0402f060d096ce6096ee266c7fd13804f105 Mon Sep 17 00:00:00 2001 From: yangzl Date: Tue, 8 Oct 2024 22:13:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix=EF=BC=9Aadd=20CHANGES.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index f151343137f..77604074d99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Apollo 2.4.0 * [Fix link namespace published items show missing some items](https://github.com/apolloconfig/apollo/pull/5240) * [Feature: Add limit and whitelist for namespace count per appid+cluster](https://github.com/apolloconfig/apollo/pull/5228) * [Feature support the observe status access-key for pre-check and logging only](https://github.com/apolloconfig/apollo/pull/5236) +* [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248) ------------------ All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1) From 06339a6838babf98aa0c1cd70d878622668c1670 Mon Sep 17 00:00:00 2001 From: yangzl Date: Mon, 14 Oct 2024 21:54:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix=EF=BC=9AChange=20the=20time=20interval?= =?UTF-8?q?=20to=20seconds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/AdminServiceAddressLocator.java | 4 ++-- .../portal/component/config/PortalConfig.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java index 42ced007a08..eaec49d941f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java @@ -107,10 +107,10 @@ public void run() { if (refreshSuccess) { refreshServiceAddressService - .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskNormalIntervalInMilli(), TimeUnit.MILLISECONDS); + .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskNormalIntervalSecond(), TimeUnit.SECONDS); } else { refreshServiceAddressService - .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskOfflineIntervalInMilli(), TimeUnit.MILLISECONDS); + .schedule(new RefreshAdminServerAddressTask(), portalConfig.refreshAdminServerAddressTaskOfflineIntervalSecond(), TimeUnit.SECONDS); } } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index e1b86a8c05f..e5e5e201d5c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -43,8 +43,8 @@ public class PortalConfig extends RefreshableConfig { private static final Logger logger = LoggerFactory.getLogger(PortalConfig.class); - private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI = 5 * 60 * 1000; //5min - private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI = 10 * 1000; //10s + private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_SECOND = 5 * 60; //5min + private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND = 10; //10s private static final Gson GSON = new Gson(); private static final Type ORGANIZATION = new TypeToken>() { @@ -196,14 +196,14 @@ public String portalAddress() { return getValue("apollo.portal.address"); } - public int refreshAdminServerAddressTaskNormalIntervalInMilli() { - int interval = getIntProperty("refresh.admin.server.address.task.normal.interval.ms", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI); - return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI); + public int refreshAdminServerAddressTaskNormalIntervalSecond() { + int interval = getIntProperty("refresh.admin.server.address.task.normal.interval.second", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_SECOND); + return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_SECOND); } - public int refreshAdminServerAddressTaskOfflineIntervalInMilli() { - int interval = getIntProperty("refresh.admin.server.address.task.offline.interval.ms", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI); - return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI); + public int refreshAdminServerAddressTaskOfflineIntervalSecond() { + int interval = getIntProperty("refresh.admin.server.address.task.offline.interval.second", DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND); + return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND); } public boolean isEmergencyPublishAllowed(Env env) { From d52028c48e44fae59b088c641b524490da92d2fe Mon Sep 17 00:00:00 2001 From: yangzl Date: Tue, 15 Oct 2024 07:46:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=EF=BC=9Aadd=20warn=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/apollo/portal/component/config/PortalConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java index e5e5e201d5c..982515be490 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java @@ -318,10 +318,11 @@ public List getUserPasswordNotAllowList() { return Arrays.asList(value); } - int checkInt(int value, int min, int max, int defaultValue) { + private int checkInt(int value, int min, int max, int defaultValue) { if (value >= min && value <= max) { return value; } + logger.warn("Configuration value '{}' is out of bounds [{} - {}]. Using default value '{}'.", value, min, max, defaultValue); return defaultValue; } }