Skip to content

Commit

Permalink
feat(proxy): update health check logic (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Oct 9, 2024
1 parent 5b32abf commit 03875bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private void initCustom() {
private UpstreamRedisClientTemplate initCustomInstance(long bid, String bgroup) {
CamelliaTranspondProperties.CustomProperties custom = properties.getCustom();
if (custom == null) return null;
logger.info("UpstreamRedisClientTemplate init, bid = {}, bgroup = {}", bid, bgroup);
logger.info("UpstreamRedisClientTemplate init custom instance, bid = {}, bgroup = {}", bid, bgroup);
UpstreamRedisClientTemplate template = new UpstreamRedisClientTemplate(env, bid, bgroup, updater, custom.getReloadIntervalMillis());
//更新的callback
ResourceTableUpdateCallback updateCallback = template::update;
Expand Down Expand Up @@ -496,7 +496,7 @@ private UpstreamRedisClientTemplate initRemoteInstance(long bid, String bgroup)
if (remote == null) return null;
boolean monitorEnable = remote.isMonitorEnable();
long checkIntervalMillis = remote.getCheckIntervalMillis();
logger.info("UpstreamRedisClientTemplate init, bid = {}, bgroup = {}", bid, bgroup);
logger.info("UpstreamRedisClientTemplate init remote instance, bid = {}, bgroup = {}", bid, bgroup);
return new UpstreamRedisClientTemplate(env, apiService, bid, bgroup, monitorEnable, checkIntervalMillis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ private void schedule() {
String url = entry.getKey();
boolean valid = entry.getValue().isValid();
if (!valid) {
logger.warn("IUpstreamClient with resource = {} not valid", url);
logger.warn("redis resource = {} not valid", url);
}
validCache.put(url, valid);
Long lastCheckTime = lastCheckValidTime.get(url);
if (lastCheckTime != null && TimeCache.currentMillis - lastCheckTime > notActiveThresholdMs) {
notActiveClients.add(url);
if (lastCheckTime == null) {
lastCheckValidTime.put(url, TimeCache.currentMillis);
} else {
if (TimeCache.currentMillis - lastCheckTime > notActiveThresholdMs) {
notActiveClients.add(url);
}
}
}
if (!notActiveClients.isEmpty()) {
for (String url : notActiveClients) {
clientCache.remove(url);
validCache.remove(url);
lastCheckValidTime.remove(url);
logger.info("redis resource = {} not active, remove from check list", url);
}
}
} catch (Exception e) {
Expand All @@ -70,7 +75,7 @@ public void addResource(Resource resource) {
IUpstreamClient client = factory.get(url);
clientCache.put(url, client);
boolean valid = client.isValid();
logger.info("addResource to ScheduledResourceChecker, resource = {}, valid = {}", url, valid);
logger.info("add redis resource = {} to check list, valid = {}", url, valid);
validCache.put(url, valid);
lastCheckValidTime.put(url, TimeCache.currentMillis);
}
Expand Down

0 comments on commit 03875bc

Please sign in to comment.