Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:RefreshAdminServerAddressTask supports dynamic configuration of time interval #5248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Organization>>() {
}.getType();
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to let the user configure the interval in seconds instead of milliseconds.

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();

Expand Down Expand Up @@ -304,4 +317,11 @@ public List<String> getUserPasswordNotAllowList() {
}
return Arrays.asList(value);
}

int checkInt(int value, int min, int max, int defaultValue) {
if (value >= min && value <= max) {
return value;
}
return defaultValue;
}
}
Loading